public:t-malv-15-3:1
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| public:t-malv-15-3:1 [2015/08/20 08:31] – [1. Getting to know some helpful functions] orvark | public:t-malv-15-3:1 [2024/04/29 13:33] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 78: | Line 78: | ||
| </ | </ | ||
| - | **Can you improve the function so it at least handles the false positives in the example above?** | + | **Can you improve the function so it handles |
| ===== 3. Replace bad with good ===== | ===== 3. Replace bad with good ===== | ||
| Line 100: | Line 100: | ||
| ===== 4. NLTK functions ===== | ===== 4. NLTK functions ===== | ||
| + | |||
| + | Before you can get started with the NLTK corpora you have download it with nltk.download() once. | ||
| <code python> | <code python> | ||
| import nltk | import nltk | ||
| - | nltk.download() | ||
| </ | </ | ||
| Line 154: | Line 155: | ||
| </ | </ | ||
| + | ===== Possible Solutions ===== | ||
| + | |||
| + | <code python> | ||
| + | #1 | ||
| + | my_str.upper() | ||
| + | my_int.str() | ||
| + | my_float.is_integer() | ||
| + | my_list.pop(2) | ||
| + | |||
| + | #2 | ||
| + | def is_male(proper_name): | ||
| + | return proper_name[-3: | ||
| + | #return proper_name.endswith(" | ||
| + | |||
| + | # return ... and ' ' in proper_name and proper_name.istitle() and " | ||
| + | # return ... and proper_name.find(' | ||
| + | |||
| + | #3 | ||
| + | def str_replace(text, | ||
| + | for bad in bad_list: | ||
| + | text = text.replace(bad, | ||
| + | return text | ||
| + | |||
| + | #4 | ||
| + | from nltk.book import text6 | ||
| + | text6.concordance(" | ||
| + | text6.similar(" | ||
| + | text6.collocations() | ||
| + | |||
| + | #5 | ||
| + | sorted(w for w in set(text6) if w.startswith(' | ||
| + | sorted(set(w for w in text6 if w.isupper()))) | ||
| + | |||
| + | #6 | ||
| + | rules[" | ||
| + | rules[" | ||
| + | |||
| + | for left, right in rules.items(): | ||
| + | print(left, " | ||
| + | |||
| + | |||
| + | </ | ||
/var/www/cadia.ru.is/wiki/data/attic/public/t-malv-15-3/1.1440059512.txt.gz · Last modified: 2024/04/29 13:32 (external edit)