Java 如何解决Web API中获得的值与ws4j中通过源代码获得的值之间的差异?

Java 如何解决Web API中获得的值与ws4j中通过源代码获得的值之间的差异?,java,nlp,matching,ws4j,Java,Nlp,Matching,Ws4j,我使用ws4j库开发了以下用于句子语义匹配的API。但是我没有得到语义上的相似性。 ouptut作为图像附加,显示冗余或0的值。 有没有错过的图书馆可以叫 package ws4jv01; import edu.cmu.lti.lexical_db.ILexicalDatabase; import edu.cmu.lti.lexical_db.NictWordNet; import edu.cmu.lti.ws4j.RelatednessCalculator; import edu.cmu.l

我使用ws4j库开发了以下用于句子语义匹配的API。但是我没有得到语义上的相似性。 ouptut作为图像附加,显示冗余或0的值。 有没有错过的图书馆可以叫

package ws4jv01;

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;

public class SentenceMatcherSimilarityMatrix
{
 private static ILexicalDatabase db = new NictWordNet();
 public double[][] getSimilarityMatrix( String[] words1, String[] words2, RelatednessCalculator rc )
{
    double[][] result = new double[words1.length][words2.length];
    for ( int i=0; i<words1.length; i++ ){
        for ( int j=0; j<words2.length; j++ ) {
            double score = rc.calcRelatednessOfWords(words1[i], words2[j]);
            result[i][j] = score;
          }
        }
    return result;
  }
  private void compute (String[] words1, String[] words2)
  {
    System.out.println("WuPalmer");
    RelatednessCalculator rc1 = new WuPalmer(db);
       {
        double[][] s1 = getSimilarityMatrix(words1, words2,rc1);
        for(int i=0; i<words1.length; i++){
            for(int j=0; j< words2.length; j++){
                System.out.print(s1[i][j] +"\t");
            } 
            System.out.println();
        }}
    System.out.println();
    System.out.println();

    System.out.println("Resnik");
    RelatednessCalculator rc2 = new Resnik(db);
    {
        double[][] s2 = getSimilarityMatrix(words1, words2,rc2);
        for(int i=0; i<words1.length; i++){
            for(int j=0; j< words2.length; j++){
                System.out.print(s2[i][j] +"\t");
            } 
            System.out.println();
        }}
    System.out.println();
    System.out.println();

    System.out.println("JiangConrath");
    RelatednessCalculator rc3 = new JiangConrath(db);
    {
        double[][] s2 = getSimilarityMatrix(words1, words2,rc3);
        for(int i=0; i<words1.length; i++){
            for(int j=0; j< words2.length; j++){
                System.out.print(s2[i][j] +"\t");
            } 
            System.out.println();
        }}
    System.out.println();
    System.out.println();

    System.out.println("Lin");
    RelatednessCalculator rc4 = new Lin(db);
    {
        double[][] s2 = getSimilarityMatrix(words1, words2,rc4);
        for(int i=0; i<words1.length; i++){
            for(int j=0; j< words2.length; j++){
                System.out.print(s2[i][j] +"\t");
            } 
            System.out.println();
        }}
    System.out.println();
    System.out.println();

    System.out.println("LeacockChodrow");
    RelatednessCalculator rc5 = new LeacockChodorow(db);
    {
        double[][] s2 = getSimilarityMatrix(words1, words2,rc5);
        for(int i=0; i<words1.length; i++){
            for(int j=0; j< words2.length; j++){
                System.out.print(s2[i][j] +"\t");
            } 
            System.out.println();
        }}
    System.out.println();
    System.out.println();

    System.out.println("Path");
    RelatednessCalculator rc6 = new Path(db);
    {
        double[][] s2 = getSimilarityMatrix(words1, words2,rc6);
        for(int i=0; i<words1.length; i++){
            for(int j=0; j< words2.length; j++){
                System.out.print(s2[i][j] +"\t");
            } 
            System.out.println();
        }}
    System.out.println();
    System.out.println();

    System.out.println("Lesk");
    RelatednessCalculator rc7 = new Lesk(db);
    {
        double[][] s2 = getSimilarityMatrix(words1, words2,rc7);
        for(int i=0; i<words1.length; i++){
            for(int j=0; j< words2.length; j++){
                System.out.print(s2[i][j] +"\t");
            } 
            System.out.println();
        }}
    System.out.println();
    System.out.println();

    System.out.println("HirstStOnge");
    RelatednessCalculator rc8 = new HirstStOnge(db);
    {
        double[][] s2 = getSimilarityMatrix(words1, words2,rc8);

        for(int i=0; i<words1.length; i++){
            for(int j=0; j< words2.length; j++){
                System.out.print(s2[i][j] +"\t");
            } 
            System.out.println();
           }}
          }

public static void main(String[] args) 
{
    String sent1 = "The boy is playing with a dog.";
    String sent2 = "The kid is playing with his pet.";

    String[] words1 = sent1.split(" ");
    String[] words2 = sent2.split(" ");
    SentenceMatcherSimilarityMatrix sm1 = new SentenceMatcherSimilarityMatrix(); 
    sm1.compute(words1, words2);
}
}
包ws4jv01;
导入edu.cmu.lti.lexical_db.ILexicalDatabase;
导入edu.cmu.lti.lexical_db.NictWordNet;
导入edu.cmu.lti.ws4j.RelatednessCalculator;
导入edu.cmu.lti.ws4j.impl.HirstStOnge;
导入edu.cmu.lti.ws4j.impl.JiangConrath;
导入edu.cmu.lti.ws4j.impl.LeacockChodorow;
导入edu.cmu.lti.ws4j.impl.Lesk;
导入edu.cmu.lti.ws4j.impl.Lin;
导入edu.cmu.lti.ws4j.impl.Path;
导入edu.cmu.lti.ws4j.impl.Resnik;
导入edu.cmu.lti.ws4j.impl.wupamer;
公共类语句匹配相似矩阵
{
私有静态ILexicalDatabase db=new-NictWordNet();
public double[]getSimilarityMatrix(字符串[]字1,字符串[]字2,关系计算器rc)
{
双精度[]结果=新的双精度[words1.length][words2.length];

对于(int i=0;i)您的代码似乎正在运行。真正大的冗余值对应于出现在两个句子中的相同单词,而出现零是因为除两个之外的所有相似性度量都只会比较共享相同词性的单词。这在JAVA8上行得通吗?