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 08:19] – [2. Naive is_male] orvarkpublic:t-malv-15-3:1 [2024/04/29 13:33] (current) – external edit 127.0.0.1
Line 49: Line 49:
 </code> </code>
  
-**Return the your code for applying the functions you selected.** +**Return the your code for applying the four functions you selected in the last part.** 
-Note to use print(my_...) to show the change the function made if it does not return a value.+Note to use print(my_...) to show the change the function made.
  
  
Line 78: Line 78:
 </code> </code>
  
-**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 some of the false positives in the example above?**
  
 ===== 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() 
 </code> </code>
  
Line 154: 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.1440058754.txt.gz · Last modified: 2024/04/29 13:32 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki