How to find the similarity between two words in java using wordnet?

WordNet is a lexical database of the english language.

Here is my prjoect to find the similarity between two word using WS4J in java using eclipse editor.

First of all download two jar files.
1. jawjaw-1.0.2.jar 
2. ws4j-1.0.1.jar     

Now you have to add these jar files into your java project as shown below:

Steps(1-6) for adding .rar file to the eclipse


1. create a folder by name "lib" in your project.


2. Now copy the two downloaded jar file and paste to this lib folder.



3. Right click on your project>> select build path>> configure build path.

4. click on the add jar


5. Select your project>> lib folder>> the two jar files.


6. Click OK.


7.Now move towards the coding part.
copy this code and paste to the class file


import edu.cmu.lti.lexical_db.ILexicalDatabase;
import edu.cmu.lti.lexical_db.NictWordNet;
import edu.cmu.lti.ws4j.RelatednessCalculator;
import edu.cmu.lti.ws4j.impl.HirstStOnge;
import edu.cmu.lti.ws4j.impl.JiangConrath;
import edu.cmu.lti.ws4j.impl.LeacockChodorow;
import edu.cmu.lti.ws4j.impl.Lesk;
import edu.cmu.lti.ws4j.impl.Lin;
import edu.cmu.lti.ws4j.impl.Path;
import edu.cmu.lti.ws4j.impl.Resnik;
import edu.cmu.lti.ws4j.impl.WuPalmer;
import edu.cmu.lti.ws4j.util.WS4JConfiguration;

public class Wordnet {

private static ILexicalDatabase db = new NictWordNet();
/*
//available options of metrics
private static RelatednessCalculator[] rcs = { new HirstStOnge(db),
new LeacockChodorow(db), new Lesk(db), new WuPalmer(db),
new Resnik(db), new JiangConrath(db), new Lin(db), new Path(db) };
*/
private static double compute(String word1, String word2) {
WS4JConfiguration.getInstance().setMFS(true);
double s = new WuPalmer(db).calcRelatednessOfWords(word1, word2);
return s;
}

public static void main(String[] args) {
String[] words = {"add", "get", "filter", "remove", "check", "find", "collect", "create"};

for(int i=0; i<words.length-1; i++){
for(int j=i+1; j<words.length; j++){
double distance = compute(words[i], words[j]);
System.out.println(words[i] +" -  " +  words[j] + " = " + distance);
}
}
}

}

Please comment:



See also...How to connect Java Eclipse to MySQL Server?


 

   How to download and install MySQL server with Workbench?

2 comments:

All about journals and research paper | What is impact factor? | how the impact factor is calculated? | who calculate the impact factor? Scopous journals

Figure 1: One of my Research Papers When the Scholars are in their Master or PhD or in any research field. They are supposed to writ...