Search code examples
javadictionarywordnet

ERROR: Make sure the NICT wordnet db is stored in classpath at: /wnjpn.db


I am trying to calculate the similarity between two words for my application. I have used the wordnet dictionary. While executing the code it requires wnjpn.db in the class path. When I executing the code as a java application it works fine when I add this db file to src folder in app, but while I trying to run from web page it gives error that

 ERROR: Make sure the NICT wordnet db is stored in classpath at: /wnjpn.db 

sample code look like

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 similarity {

public  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) };
*/
public  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"};


            double distance = compute("OTHER OFFENSE","PROSTITUTION");
            System.out.println( distance);


}

}


Solution

  • Found Solution.

    add--> Folder to the Java Resources --->Some Folder

    Add wnjpn.db to that folder-->go to the project properties--> Java Build Path

    Image 1

    Click to add Folder--> select folder in your wnjpn.db file is stored--> click Ok

    image 2

    It will automatically load wnjpn.db file at runtime. It works for me.