Search code examples
pythonnlpnltksimilaritywordnet

How to select required sense from wordnet:synset in a python script


I am reading input from a file and calculating wordnet-based similarity/relatedness measures like LIN, Banerjee and Pedersen Measure(BNP), Jiang and Conrath Measure (JNC) for the words in each line. I am using the following code to get the synsets:

synsets=[]
for entry in line1:
   synsets.append(wn.synsets(entry)[0])

But this would get me only the first sense in the synset of the correspong word. But in some cases i may want 2nd or 3rd or maybe some other sense depending on the word. Eg: for water the first sense is H2O, but i want to select the second one, ie "body of water". How to make the code more adpaptive without user prompt?


Solution

  • Normally, when you measure the similarity between word A and word B, you compare every sense of A with every sense of B and take the similarity between the closest senses to be your similarity score.

    If you had a large context of each word's occurrence (...the bank of the river... and ...to deposit money in a bank...), you could use it to decide which sense of "bank" is relevant.