Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ...
- def relation(self, concordance1, concordance2):
- if type(concordance1) != dict:
- raise ValueError('Supplied Argument 1 should be of type dict')
- if type(concordance2) != dict:
- raise ValueError('Supplied Argument 2 should be of type dict')
- relevance = 0
- # calculate topvalue = max{count1*count2}
- topvalue = 0
- for word, count in concordance1.items():
- if word in concordance2:
- topvalue += count * concordance2[word]
- # return topvalue / (|v1||v2|) which is a measurement of how relevant the two
- # vectors are to each other
- if (self.magnitude(concordance1) * self.magnitude(concordance2)) != 0:
- return topvalue / (self.magnitude(concordance1) * self.magnitude(concordance2))
- else:
- return 0
- // ...
Advertisement
Add Comment
Please, Sign In to add comment