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 07:38] – [2. Naive is_male] orvark | public:t-malv-15-3:1 [2024/04/29 13:33] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Lab 1 ====== | ====== Lab 1 ====== | ||
- | **Hand in your code in MySchool before midnight today (20 August). A single .py file containing the code in the same order as the given problems.** If you can't manage to complete a particular problem please hand in your incomplete code -- comment it out if it produces an error. | + | **Hand in your code in MySchool before midnight today (20 August). A single .py file containing the code in the same order as the given problems.** |
+ | |||
+ | If you can't manage to complete a particular problem please hand in your incomplete code -- comment it out if it produces an error. | ||
===== 1. Getting to know some helpful functions ===== | ===== 1. Getting to know some helpful functions ===== | ||
Line 47: | Line 49: | ||
</ | </ | ||
- | **Return the your code for applying the functions you selected.** | + | **Return the your code for applying the four functions you selected |
- | 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 54: | Line 56: | ||
<code python> | <code python> | ||
- | #Define a very simple and naive function to check if an Icelandic proper name belongs to a male. | + | #Define a very simple and naive function to check if an Icelandic proper name belongs to a male |
+ | #(e.g. ends with " | ||
def is_male(proper_name): | def is_male(proper_name): | ||
Line 75: | 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 97: | 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 151: | 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.1440056287.txt.gz · Last modified: 2024/04/29 13:32 (external edit)