Advertisement
Guest User

Untitled

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