As stated here I use the Java version of Wordnet::similarity.
This is the server side code. I recieve a List with two elements (i.e. two sentences) and then compute the similarity matrix for those two sentences
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) {
}
}
The client queries the server for sentence similarity in a serial way (i.e. it sends another request after the similarity score of the previous pair is recieved)
Here's the output I get on server side
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)
I don't understand why it crashes when connection is established for the second time.