differan - #!/usr/bin/env python # -*- coding: utf-8...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#!/usr/bin/env python # -*- coding: utf-8 -*- ##differan.py #Creates distinct frequency dictionaries from two text files, which are used #to form a third dictionary containing all words which occur in one or both #dictionaries. The third dictionary also contains the coefficients #of difference, which are calculated from the frequencies of the first two #dictionaries: cof = (freq1-freq2)/(freq1+freq2). ##Using these three dictionaries, words are sorted by their cof are outputted #along with their frequencies in the original two dictionaries. import re c1 = '2001.txt' c5 = '2005.txt' ## Creates frequency dictionaries from the two text files. word_list1 = re.split('\s+', file(c1).read().lower()) word_list5 = re.split('\s+', file(c5).read().lower()) freq_d1 = {} freq_d5 = {} for word in word_list1: word = re.sub(r'[^a-z]','',word) try: freq_d1[word] += 1 except: freq_d1[word] = 1 for word in word_list5: word = re.sub(r'[^a-z]','',word) try: freq_d5[word] += 1 except: freq_d5[word] = 1 for word in freq_d1.keys():
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/06/2009 for the course LING 571 taught by Professor Staff during the Fall '08 term at San Diego State.

Page1 / 2

differan - #!/usr/bin/env python # -*- coding: utf-8...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online