日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

本文介紹了如何解決在Web API中獲得的值與通過ws4j中的源代碼獲得的值之間的差異?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用ws4j庫開發(fā)了以下用于句子語義匹配的API。但我沒能得到語義上的相似之處。
輸出以圖像的形式附加,其中顯示冗余或0的值。
是否有遺漏調(diào)用的庫?

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] +"	");
            } 
            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] +"	");
            } 
            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] +"	");
            } 
            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] +"	");
            } 
            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] +"	");
            } 
            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] +"	");
            } 
            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] +"	");
            } 
            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] +"	");
            } 
            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);
}
}

Result set

推薦答案

相似性矩陣呈現(xiàn)中的細微優(yōu)化:

for (int i = 0; i <= words1.length; i++) {
    for (int j = 0; j <= words2.length; j++) {
        if(i==0 && j==0) {
            System.out.print(" " + "	"); 
        } else if(i==0) {
            System.out.print(words2[j-1] + "	");
        } else if(j==0) {
            System.out.print(words1[i-1] + "	");
        } else {
            System.out.print(s1[i-1][j-1] + "	");
        }
    }
    System.out.println();
}

這將使矩陣顯示為:

這篇關(guān)于如何解決在Web API中獲得的值與通過ws4j中的源代碼獲得的值之間的差異?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,

分享到:
標簽:API Web ws4j 如何解決 差異 源代碼
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數(shù)有氧達人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定