NLP | Leacock Chordorow (LCH) and Synset Path Similarity

Leacock Chordorow (LCH): is a similarity measure that is an extended version of path-based similarity as it includes taxonomy depth. Therefore, it is the negative logarithm of the shortest path (spath) between the two concepts (synset_1 and synset_2) divided by twice the total taxonomy depth (D), as shown in Fig. Below.

Code # 1: Introducing Synsets.

from nltk.corpus import wordnet 

 

syn1 = wordnet.synsets ( `hello` ) [ 0

syn2 = wordnet.synsets ( `selling` ) [ 0

  

print ( " hello name: " , syn1.name ()) 

print ( "selling name:" , syn2.name ()) 

Output:

 hello name: hello.n.01 selling name: selling.n.01 

Code # 2: Path Affinity

syn1.path_similarity (syn2) 

Output:

 0.08333333333333333 

Code # 3: Similarity Leacock Chordorow (LCH)

syn 1.lch_similarity (syn2) 

Output:

 1.1526795099383855