1
如前所述here我使用Wordnet :: similarity的Java版本。爲什麼Java Wordnet會在第二次調用時崩潰?
這是服務器端代碼。我收到一個列表與兩個元件(即,兩個句子) ,然後計算爲這兩個句子
String wordNetDirectory = System.getenv("WNHOME");
JWS ws = new JWS(wordNetDirectory,"3.0");
Resnik res = ws.getResnik();
while(true) {
try {
Socket clientSocket = serverSocket.accept();
System.out.println("Socket Established...");
ObjectOutputStream outToClient = new ObjectOutputStream(clientSocket.getOutputStream());
ObjectInputStream inFromClient = new ObjectInputStream(clientSocket.getInputStream());
List<List<String>> sents;
sents = (List<List<String>>) inFromClient.readObject();
System.out.println("recieved");
List<String> s1 = sents.get(0);
List<String> s2 = sents.get(1);
Double sum = 0.0;
for(String w1 : s1) {
for(String w2 : s2) {
if(w1.equals(w2)) sum += 1;
else sum += res.max(w1, w2, "n"); // <- Server.java:54
}
}
sum /= (s1.size() * s2.size());
outToClient.writeObject(sum);
System.out.println("wrote " + sum);
} catch (IOException e) {
} catch (ClassNotFoundException e) {
}
}
客戶端將查詢句子相似度服務器以串行方式(相似性矩陣,即它發送之後的另一個請求以前對相似性得分是收到)
這裏的輸出我得到的服務器端
Socket Established...
recieved
wrote 0.111357828694864
Socket Established...
Exception in thread "main" java.lang.IllegalArgumentException
at edu.mit.jwi.item.IndexWordID.<init>(IndexWordID.java:62)
at edu.mit.jwi.CachingDictionary.getIndexWord(CachingDictionary.java:173)
at edu.sussex.nlp.jws.Resnik.res(Resnik.java:133)
at edu.sussex.nlp.jws.Resnik.max(Resnik.java:313)
at Server.start(Server.java:54)
at Main.main(Main.java:7)
我不明白爲什麼它崩潰當連接第二次建立時。
據我所知,這可能是因爲'w1'或'w2'爲空或全部空白,或者不出現在wordnet單詞列表中。你可以改變你試過的字符串。 – locoyou