User Tools

Site Tools


public:t-malv-15-3:1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
public:t-malv-15-3:1 [2015/08/20 09:18] – [4. NLTK functions] orvarkpublic:t-malv-15-3:1 [2024/04/29 13:33] (current) – external edit 127.0.0.1
Line 109: Line 109:
 Apply NLTK functions to do the following: Apply NLTK functions to do the following:
  
-  * Import text6 from NLTK+  * Import text6 from nltk
   * Show the concordance of the word "coconut"   * Show the concordance of the word "coconut"
   * Find words occuring in similar contexts to "coconut"   * Find words occuring in similar contexts to "coconut"
Line 155: Line 155:
 </code> </code>
  
 +===== 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:] == "son"
 +    #return proper_name.endswith("son")
 +
 +# return ... and ' ' in proper_name and proper_name.istitle() and "Gillian" in proper_name
 +# return ... and proper_name.find(' ') and proper_name.istitle() and proper_name.find("Gillian")
 +
 +#3
 +def str_replace(text, bad_list, good=''):
 +    for bad in bad_list:
 +        text = text.replace(bad, good)
 +    return text
 +
 +#4
 +from nltk.book import text6
 +text6.concordance("coconut")
 +text6.similar("coconut")
 +text6.collocations()
 +
 +#5
 +sorted(w for w in set(text6) if w.startswith('z')) # w[0] == 'z'
 +sorted(set(w for w in text6 if w.isupper())))
 +
 +#6
 +rules["N"] += ["dog", "cat"]
 +rules["V"].append("hates")
 +
 +for left, right in rules.items():
 +    print(left, "->", ' | '.join(right))
 +
 +
 +</code>
/var/www/cadia.ru.is/wiki/data/attic/public/t-malv-15-3/1.1440062300.txt.gz · Last modified: 2024/04/29 13:32 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki