import nltk from estnltk import Text import urllib.request aadress1 = "http://www.tlu.ee/~kais/Digihum_tehnoloogiad/Nadal6/A2_2018_I.txt" tekst1 = urllib.request.urlopen(aadress1).read().decode("utf8").lower() aadress2 = "http://www.tlu.ee/~kais/Digihum_tehnoloogiad/Nadal6/B1_2018_I.txt" tekst2 = urllib.request.urlopen(aadress2).read().decode("utf8").lower() paarid1 = nltk.collocations.BigramCollocationFinder.from_words(Text(tekst1).postags).ngram_fd.items() paarid2 = nltk.collocations.BigramCollocationFinder.from_words(Text(tekst2).postags).ngram_fd.items() f = open("A2_sonaliigipaarid.txt", "w") print("Sõnaliigipaar Sagedus", file = f) for paar in reversed(sorted(paarid1, key=lambda p: p[1])): print("-".join(paar[0]), paar[1], file = f) f.close() f = open("B1_sonaliigipaarid.txt", "w") print("Sõnaliigipaar Sagedus", file = f) for paar in reversed(sorted(paarid2, key=lambda p: p[1])): print("-".join(paar[0]), paar[1], file = f) f.close()