2018年5月25日金曜日

開発環境

入門 自然言語処理 (Steven Bird (著)、Ewan Klein (著)、Edward Loper (著)、萩原 正人 (翻訳)、中山 敬広 (翻訳)、水野 貴明 (翻訳)、オライリージャパン)の1章(言語処理とPython)、1.8(演習問題)22.を取り組んでみる。

コード(Emacs)

Python 3

#!/usr/bin/env python3
from nltk.book import *

print('22.')

fdist = FreqDist(word for word in text5 if len(word) == 4)

d = {k: [] for k in set(fdist.values())}
for k, v in fdist.items():
    d[v].append(k)

for k in sorted(d.keys(), reverse=True):
    print(f'{k}: {d[k]}')

入出力結果(Terminal, Jupyter(IPython))

$ ./sample15.py
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
22.
1021: ['JOIN']
1016: ['PART']
274: ['that']
183: ['what']
181: ['here']
170: ['....']
164: ['have']
156: ['like']
152: ['with']
142: ['chat']
137: ['your']
130: ['good']
125: ['just']
107: ['lmao']
103: ['know']
98: ['room']
92: ['from']
86: ['this']
81: ['well']
78: ['back', 'hiya']
77: ['they']
75: ['dont', 'yeah']
71: ['want']
60: ['love']
58: ['guys', 'some']
57: ['been']
56: ['talk']
52: ['nice']
50: ['time']
48: ['when']
44: ['haha', 'make']
43: ['girl', 'need']
42: ['U122']
41: ['MODE']
40: ['will', 'much', 'then']
39: ['over']
38: ['work', 'were']
37: ['take']
36: ['U121', 'U115', 'song']
35: ['even', 'does', 'seen', 'U156', 'U105']
34: ['more', 'damn']
33: ['only', 'come']
29: ['hell']
28: ['long', 'them']
27: ['name', 'tell']
26: ['away', 'sure', 'look', 'baby', 'call']
25: ['play', 'U110', 'U114']
24: ['NICK', 'down', 'cool']
23: ['sexy', 'many', 'hate', 'said']
22: ['last', 'ever']
21: ['hear', 'life']
20: ['live']
19: ['feel', 'very', 'mean', 'give', 'same', 'must', 'stop', 'LMAO']
18: ['!!!!', 'hugs', 'What', 'find', 'cant']
17: ['left', '????', 'shit', 'nite', 'busy', 'hair', 'lost', 'U104']
16: ['fine', 'real', 'game']
15: ['fuck', 'sits', 'eyes', 'lets', 'heya', 'kill']
14: ['read', 'shut', 'wait', 'goes', 'keep', 'true']
13: ['pick', 'free', 'else', 'near', 'nope', 'U168']
12: ['hope', 'head', 'male', 'than', 'gets', 'cold', 'hehe', 'bout', 'stay', 'used', 'awww', 'told', 'This', 'U102']
11: ['doin', 'kids', 'perv', 'wont', 'face', 'home', 'year', 'babe', 'into', 'yall', '.. .', 'U119', 'U107']
10: ['hard', 'show', 'U101', 'once', 'Well', 'help', 'mind', 'Yeah', 'week', 'Liam', 'U132']
9: ['pics', 'such', 'type', 'best', 'neck', 'dang', 'dead', 'runs', 'aint', 'rock', 'days', 'mine', 'book', 'crap', 'soon', 'care', 'full', 'kiss', 'hour', 'nick', 'sick', '; ..', 'hmmm']
8: ['U139', 'word', 'heyy', 'case', 'wana', 'hows', 'went', 'lady', 'blue', 'says', 'suck', 'made', 'wife', 'sang', 'U144']
7: ['fast', 'rule', 'dude', 'okay', 'alot', 'hand', 'took', 'wear', 'Hiya', 'kick', 'ahhh', 'dear', 'That', 'U108', 'U169']
6: ['U129', 'U116', 'most', 'thru', 'U165', 'list', 'seem', 'sing', 'next', 'done', 'ride', 'comp', 'main', '))))', 'goin', 'U520', 'pink', 'poor', 'gone', 'oops', 'knew', '<---', 'ball', 'send', 'Song', 'blah', 'They', 'part', 'U103', 'U120', 'Last', 'whos', 'food', 'U142', 'sock', 'U197']
5: ['legs', 'fire', 'warm', 'late', 'hang', 'miss', 'boys', 'land', 'nose', 'lick', 'caps', 'wish', 'U128', 'came', 'cali', 'roll', 'easy', 'lose', 'When', 'soul', 'luck', 'also', 'kool', 'fall', 'boss', 'beer', 'ohhh', '####', 'wall', 'Have', 'meet', 'till', 'feet', 'xbox', 'idea', 'heck', 'joke', 'fool', 'felt', 'yoko', 'meds', 'both', 'Lime']
4: ['glad', 'U133', 'U126', 'jerk', 'ugly', 'date', 'ummm', 'quit', 'rest', 'door', 'none', 'self', 'pass', 'line', 'cute', 'holy', 'hook', 'Like', 'each', 'open', 'high', 'ouch', 'evil', 'fart', 'grrr', 'pain', 'pfft', 'sigh', 'shes', 'ROOM', ',,,,', 'lord', 'mmmm', 'ones', 'huge', 'woot', 'shot', 'team', 'ways', 'beat', 'kent', 'U130', 'U196', 'U219', 'turn', 'lame', 'U123', 'U154', 'U988', 'puff', 'U146', 'U989', 'U117', 'U819', 'U820']
3: ['clap', 'itch', 'guyz', 'U136', 'gold', 'ring', 'isnt', 'U141', 'Only', 'U148', 'Your', 'deal', 'wash', 'U109', 'piff', 'jump', 'band', 'orgy', 'slap', 'soft', 'bend', 'toss', 'amen', 'rain', 'deop', 'roof', '((((', 'CHAT', 'ahem', 'hola', 'butt', 'imma', 'town', 'hawt', '2006', 'Elev', 'Wind', 'AKDT', 'lead', 'DING', 'note', 'gawd', 'half', 'mary', 'ello', 'hick', 'wine', 'hiii', 'bare', 'vote', 'Same', 'wack', 'snow', 'hurt', 'move', 'road', 'walk', 'yawn', 'hail', 'nana', 'U106', 'hump', 'elle', 'yada', 'tune', 'hank', 'slow', 'rubs', 'skin', 'died', 'U145', 'swim', 'U163', 'army', 'THAT', 'wazz', 'toes', 'U153']
2: ['golf', 'drew', 'cast', 'Days', 'opps', 'U138', 'plan', 'Just', 'deaf', 'deep', 'phil', 'hmph', 'U155', 'Poor', 'Lies', 'bite', 'mins', 'eats', '>:->', 'cell', 'cmon', 'wats', 'kind', 'mike', 'whoa', 'dumb', 'park', 'Sure', 'Come', 'O.k.', 'mama', 'Nice', 'hold', 'ohio', 'whip', 'twin', 'burp', 'blew', 'temp', 'corn', 'pool', 'cash', 'ears', 'From', 'porn', 'heal', 'Dang', 'ciao', 'DOES', 'typo', 'Stop', 'eric', 'Drew', 'sore', 'Live', 'High', 'hits', 'KoOL', 'past', 'Love', 'meat', '!!!.', 'argh', 'limp', 'rent', 'cars', 'Tell', 'shop', 'U172', 'five', 'sell', '<<<<', 'city', 'yard', 'grrl', 'chip', 'bear', 'foot', 'uses', 'DONT', 'sort', 'lies', 'whud', 'hott', 'Down', 'Lets', 'club', 'adds', 'Here', 'born', 'wOOt', 'area', '?!?!', 'Ohio', 'U112', 'humm', 'newp', 'gays', 'zone', 'hint', 'spin', 'ewww', 'pies', 'doll', 'drop', 'gimp', 'spot', 'ages', 'clue', 'mass', 'Ummm', 'Gosh', 'flow', 'kewl', 'hall', 'haze', '1996', 'John', 'john', 'sooo', 'cost', 'trip', 'babi', 'rich', 'U100', 'n9ne', 'Ahhh', '??!!', 'U111', 'moon', 'STOP', 'any1', 'yeas', 'wooo', '<333', 'tick', 'tock', 'WITH', 'FROM', 'side', 'Heyy', 'howz', "ex's", 'Cool', 'U170', 'U175', 'root', 'tyvm', 'luvs', 'fits', 'rofl', 'sand', 'ltns', 'flaw', 'aunt', 'lawl', 'Okay', 'HAVE', 'NONE', 'YOUR', 'Lmao', 'Tisk', 'U190', 'tisk']
1: ['draw', 'docs', 'Slip', 'Fade', 'bowl', 'bong', 'ogan', 'cams', 'gooo', 'yeee', 'ahah', 'jeep', 'Deep', 'Show', 'Turn', 'Hand', 'VBox', 'ELSE', 'serg', 'bein', 'whys', 'tape', 'sexs', 'form', 'HUGE', 'nads', 'owww', 'gags', 'Meep', 'LAst', "pm's", '1.99', 'lool', 'kina', 'sext', 'lazy', 'calm', 'arms', 'smax', 'VVil', 'este', 'chik', 'Boyz', 'coat', 'Eyes', 'Dawn', 'LIVE', 'mauh', 'ques', '4.20', 'gosh', 'ruff', 'mame', 'nada', 'push', 'prob', 'wild', 'whew', 'dark', 'waht', 'test', 'boot', 'hiom', 'HAHA', 'dman', 'jail', 'cops', 'hogs', 'peek', 'MORE', 'TIME', 'loud', 'o.k.', 'Sexy', 'Ctrl', 'hots', 'Need', 'frst', '1200', 'crop', 'bomb', 'Pour', 'pour', 'Swim', 'Hard', 'eeek', 'tjhe', '10th', 'heee', 'peel', 'fock', 'Kold', 'exit', 'kold', '3:45', 'MRIs', 'buff', 'plus', 'tory', 'knee', 'OOPS', 'oooh', 'lala', 'fake', 'ssid', 'poot', 'poop', 'bird', 'plow', 'thnx', 'card', 'Hugs', 'Lord', 'uyes', 'benz', '<~~~', 'disc', 'LONG', 'Been', 'Will', 'bloe', 'blow', 'hooo', 'thje', 'Jess', 'term', 'Tina', 'ooer', 'HALO', 'Awww', 'anal', 'Drop', 'dojn', 'wubs', 'mkay', 'spat', 'gees', 'hawT', 'yes.', 'puts', 'fish', 'size', '39.3', '1980', '64.8', 'syck', 'tere', 'U542', 'sent', '45.5', '98.5', '1299', '1900', '1930', 'Werd', 'Rofl', 'mode', 'nawt', 'sign', 'woof', 'sum1', 'ghet', 'brad', 'offa', 'Dood', 'out.', 'LOUD', 'sink', 'FINE', 'cums', 'loss', 'Life', 'Damn', 'wrap', 'hide', "PM's", 'Talk', 'okey', 'worl', 'Hold', 'cepn', 'lots', 'Mary', 'nawp', 'addy', 'lake', 'slip', 'mite', 'wood', 'orta', 'wins', 'ebay', 'coem', 'giva', '1.98', 'ally', 'Judy', 'cyas', 'shup', 'tooo', "pm'n", 'choc', 'wher', 'whoo', 'dint', 'tend', 'menu', 'lust', 'nods', 'NAME', 'kept', 'scuk', 'raed', 'Then', 'bugs', 'nerd', 'Hill', 'Evil', 'saME', '2Pac', 'Time', 'pimp', 'haaa', '98.6', "it's", 'Mono', 'mono', 'Bone', 'Hero', 'Came', '.op.', 'Hott', 'Joey', 'Jane', 'span', 'wore', 'QUIT', 'pasa', 'barn', 'Kick', 'feat', 'Back', 'dork', 'laid', 'Home', 'herd', 'Born', 'Away', 'Tide', 'jush', 'Cute', 'GrlZ', 'lung', 'SOME', 'Lion', 'brat', ':o *', 'MUAH', 'fawk', 'dust', 'Help', 'seth', 'Heya', 'bone', 'abou', 'tthe', 'Even', 'herE', 'Hail', 'halo', 'pork', '1cos', "yw's", 'mark', 'dotn', 'PMSL', 'pmsl', 'gift', 'outs', 'Paul', 'outa', 'York', 'Care', 'Chat', 'fear', 'dies', 'givs', 'bust', 'xmas', 'enuf', 'LoVe', 'eeww', 'dick', 'fair', 'lyin', 'lois', 'cuss', 'LATE', 'THEY', 'GOOD', 'rape', 'geez', 'tart', 'hgey', 'caan', 'lol.', 'Elle', 'nude', 'allo', 'yesh', 'wind', 'Reub', '!???', 'heat', 'kmph', 'pope', 'yess', '!...', 'duet', 'wuts', 'west', 'quiz', 'scar', 'Girl', 'pair', 'Rang', 'rang', 'bell', 'dawg', 'febe', 'Prof', 'Kewl', 'jude', 'Yoko', 'seee', 'whou', 'idnt', 'perk', 'http', '2DAY', 'yell', 'mang', 'SSRI', 'cure', 'wean', 'post', 'anti', 'noth', 'tall', 'pray', 'weed', 'icky', 'Rick', 'spit', 'lube', 'mami', 'east', '18ST', 'seat', 'cock', 'SExy', 'otay', 'firs', 'site', 'U113', 'dump', 'toop', 'four', 'U118', 'sets', 'asss', 'paid', 'Iowa', 'Teck', '"...', 'jeff', 'crib', 'drug', 'cook', '9:10', 'ladz', 'aime', 'hong', 'kong', 'Oops', 'tits', 'gret', 'guns', 'inch', 'sean', 'howl', 'Take', 'z-ro', 'U137', 'Haha', '1985', 'slam', 'pine', 'puke', 'waaa', 'urls', 'star', 'Save', 'teck', 'Room', 'sori', 'Long', 'poem', 'jack', 'Rule', 'CAPS', 'junk', 'tips', 'rush', 'Nooo', 'Troy', 'tail', 'Seee', '6:38', 'dyed', 't he', 'beam', 'daft', 'twit', 'scum', 'U134', 'Type', 'WHOA', 'toke', 'ribs', 'Eggs', 'Wyte', 'moms', 'Over', 'West', 'Rock', 'goof', 'U143', 'able', 'vamp', 'Nope', 'Kent', 'ther', 'U147', 'TEXT', 'SIZE', 'gear', 'CALI', 'Matt', 'Rush', 'AWAY', 'NTMN', 'Kiss', 'U158', 'grea', 'Look', 'guts', 'wrek', 'Fort', '2:55', 'AKST', '4:03', 'wire', 'soda', 'gray', 'tlak', 'ltnc', "ok'd", 'sayn', 'evah', 'bike', 'hill', 'ohwa', 'caca', 'prep', 'pull', 'dirt', 'vent', '100%', 'safe', 'dogs', 'bull', 'asks', 'Road', 'chit', 'grin', 'bred', 'rats', 'Sat.', 'samn', 'Phil', 'nuff', 'rose', 'Ruth', 'grew', 'mena', 'ROFL', 'lapd', 'surf', 'City', 'hazy', 'thot', 'acid', 'wide', 'keys', 'salt', 'mess', 'base', 'byes', "RN's", 'yout', 'numb', 'thah', 'mahn', 'King', 'TALK', 'GIRL', 'WHEN', 'HOTT', 'HERE', 'soup', '6:51', '9.53', 'Mine', 'vega', 'pigs', 'king', 'poof', 'Nova', 'mofo', 'Ohhh', 'Holy', 'sips', 'clay', 'None', 'Male', 'bacl', 'body', 'akon', 'yoll', 'boom', 'News', 'Maps', 'page', 'Tiff', 'Chop', 'DAMN', 'TYPR', 'poll', 'boed', 'Dude', 'Does', 'pwns', 'Very', 'Good', 'Food', 'sexi', 'bois', 'KNOW', 'GUYS', 'YALL', 'EVEN', 'SEEN', 'WILL', 'COME', 'FACE', 'JUST', 'Kids', '6:41', 'bied', '6:53', 'U149', '7:45', 'Uhhh', 'tenn', 'pure', 'U164', 'U150', 'U181', 'gals', 'woah', 'ussy', 'tiff', 'Heys', "<3's", 'lisa', 'brwn', 'hurr', 'Were']
$

0 コメント:

コメントを投稿