Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import json
  2.  
  3.  
  4. dictionary = json.load(open("saved_dictionary/my_dictionary.txt")) #wczytanie wcześniej utworzonego słownika, który zawiera hasła wraz z ich kategorią
  5. columns = [] #iterujac slownik dodaje do listy key
  6. lista = []
  7. for key in dictionary.keys(): #key - miasta / values - [warszawa,poznan,....]
  8. values = dictionary[str(key)] #lista miast
  9. columns.append(key + "\t\t" + (key + '_unikat'))
  10. print(values) #wyrzuca listę elementów z danego key
  11.  
  12.  
  13. articlename = 'Poznań' #w cudzysłowiu znajduje się tytuł badanego artykułu
  14. text = open('savedcleantext/'+ articlename + '.txt', 'r', encoding='utf-8')
  15. plaintext = text.read() #wczytanie czystej treści danego artykułu
  16.  
  17. columnsString = "\t\t".join(columns)
  18. print("Nazwa artykułu" + "\t\t" + columnsString)
  19. print(articlename, end='')
  20.  
  21. c = {}
  22. n = 0
  23. for value in values:
  24. if value in plaintext:
  25. c[value] = c.get(value,0) + plaintext.count(value)
  26. n += c[value]
  27. sumvalue = len(c.keys())
  28. print(str(n).rjust(12) + str(sumvalue).rjust(18), end = '')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement