AllenYuan

searchengine - relation

Apr 26th, 2020
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. // ...
  2.     def relation(self, concordance1, concordance2):
  3.         if type(concordance1) != dict:
  4.             raise ValueError('Supplied Argument 1 should be of type dict')
  5.         if type(concordance2) != dict:
  6.             raise ValueError('Supplied Argument 2 should be of type dict')
  7.         relevance = 0
  8.         # calculate topvalue = max{count1*count2}
  9.         topvalue = 0
  10.         for word, count in concordance1.items():
  11.             if word in concordance2:
  12.                 topvalue += count * concordance2[word]
  13.         # return topvalue / (|v1||v2|) which is a measurement of how relevant the two
  14.         # vectors are to each other
  15.         if (self.magnitude(concordance1) * self.magnitude(concordance2)) != 0:
  16.             return topvalue / (self.magnitude(concordance1) * self.magnitude(concordance2))
  17.         else:
  18.             return 0
  19. // ...
Advertisement
Add Comment
Please, Sign In to add comment