230 likes | 374 Views
Lecture 6: Comparing Things Word Similarity. Methods in Computational Linguistics II Queens College. Today. List Comprehensions Determining Word Similarity Co-occurrences WordNet. List Comprehensions. Compact way to process every item in a list. [x for x in array]. Methods.
E N D
Lecture 6: Comparing ThingsWord Similarity Methods in Computational Linguistics II Queens College
Today List Comprehensions Determining Word Similarity Co-occurrences WordNet
List Comprehensions Compact way to process every item in a list. [x for x in array]
Methods Using the iterating variable, x, methods can be applied. Their value is stored in the resulting list. [len(x) for x in array]
Conditionals Elements from the original list can be omitted from the resulting list, using conditional statements [x for x in array if len(x) == 3]
Building up These can be combined to build up complicated lists [x.upper() for x in array if len(x) > 3 and x.startswith(‘t’)]
Lists Containing Lists Lists can contain lists [[a, 1], [b, 2], [d, 4]] ...or tuples [(a, 1), (b, 2), (d, 4)] [ [d, d*d] for d in array if d < 4]
Lists within lists are often called 2-d arrays This is another way we store tables. Similar to nested dictionaries. a = [[0,1], [1,0] a[1][1] a[0][0]
Using multiple lists Multiple lists can be processed simultaneously in a list comprehension [x*y for x in array1 for y in array2]
Co-occurrences • How would you identify common co-occurrences? • Define a co-occurrence: • “school bus” vs. “school river”
Anything else? What relationships would you like to know about between words?
Next Time • Word Similarity • Wordnet • Data structures • 2-d arrays. • Trees • Graphs