Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rzanoli committed Mar 2, 2018
1 parent b59fa69 commit efee182
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
9 changes: 5 additions & 4 deletions src/main/java/eu/fbk/hlt/nlp/cluster/Comparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ public void run() {
graph.add(i, j, Abbreviation.id);
//System.out.println("Abbreviation:" + kx_i.getText() + "\t" + kx_j.getText());
}
/*
// apply the Acronym criteria
else if (Acronym.evaluate(kx_i, kx_j)) {
// if (kxs.inDocument(kx_i, kx_j)) {
//if (keys.inDocument(kx_i, kx_j)) {
graph.add(i, j, Acronym.id);
//System.out.println("Acronym:" + kx_i.getText() + "\t" + kx_j.getText());
// }
}
//}
}*/
// apply the Entailment criteria
else if (Entailment.evaluate(kx_i, kx_j)) {
graph.add(i, j, Entailment.id);
Expand All @@ -108,7 +109,7 @@ else if (ModifierSwap.evaluate(kx_i, kx_j)) {
// apply the Singular/Plural criteria
else if (SingularPlural.evaluate(kx_i, kx_j)) {
graph.add(i, j, SingularPlural.id);
System.out.println("SingularPlural:" + kx_i.getText() + "\t" + kx_j.getText());
//System.out.println("SingularPlural:" + kx_i.getText() + "\t" + kx_j.getText());
}
// apply the Singular/Plural criteria
else if (PrepositionalVariant.evaluate(kx_i, kx_j)) {
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/eu/fbk/hlt/nlp/cluster/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import java.io.Writer;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

Expand Down Expand Up @@ -333,6 +337,10 @@ public void run() {
*/
public static void printGraphs(String graphs, Keyphrases keyphrases, String dirOut) throws Exception {

//Map<Integer,Integer> documentsDistributionInClusters = new HashMap<Integer,Integer>();
//Set<String> documentsCounts = new HashSet<String>();


StringBuilder out = new StringBuilder();
int nNodes = 0;
String[] splitGraphs = graphs.split("\n");
Expand All @@ -349,9 +357,21 @@ public static void printGraphs(String graphs, Keyphrases keyphrases, String dirO
fout.write(out.toString().substring(0, out.toString().length() - 1) + "\n");
fout.write("</KEC_graph>\n");
out = new StringBuilder();

/*
if (documentsDistributionInClusters.containsKey(documentsCounts.size())) {
int freq = documentsDistributionInClusters.get(documentsCounts.size()).intValue() + 1;
documentsDistributionInClusters.put(documentsCounts.size(), freq);
}
else {
int freq = 1;
documentsDistributionInClusters.put(documentsCounts.size(), freq);
}
documentsCounts = new HashSet<String>();*/


fout.close();
continue;

}
String[] splitLine = splitGraphs[i].split(" ");
if (splitLine.length == 1) {
Expand All @@ -371,6 +391,15 @@ public static void printGraphs(String graphs, Keyphrases keyphrases, String dirO
out.append(" <text>" + kx.getText() + "</text>\n");
out.append(" <ids>" + keyphrases.getIDs(kx) + "</ids>\n");
out.append(" </node>\n");

/*
String[] documents = keyphrases.getIDs(kx).split(" ");
for (int z = 0; z < documents.length; z++)
documentsCounts.add(documents[z]);
*/



} else {
int kxSourceID = Integer.parseInt(splitLine[0]);
int kxTargetID = Integer.parseInt(splitLine[1]);
Expand All @@ -379,6 +408,12 @@ public static void printGraphs(String graphs, Keyphrases keyphrases, String dirO
+ kxTargetID + "\"/>\n");
}
}

//System.out.println("Documents distriution in clusters");
//for (Integer freq : documentsDistributionInClusters.keySet()) {
//System.out.println(freq + "\t" + documentsDistributionInClusters.get(freq));
//}
//System.out.println("===================================");

}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/eu/fbk/hlt/nlp/cluster/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ else if (dots == 1 && this.characters >= 1)

// assign the wordnet PoS
if (this.PoS.startsWith("S") || this.PoS.startsWith("Y")) //- n (noun): SS,SP,SN,SPN,YA,YF
this.wordnetAnnotation = "n#" + this.lemma;
this.wordnetAnnotation = "n#" + this.lemma.toLowerCase();
else if (this.PoS.startsWith("V")) //- v (verb): VI,VI+E,VIY,VIY+E,VF,VF+E,VFY,VFY+E,VSP,VSP+E,VSPY,VSPY+E,VPP,VPP+E,VPPY,VPPY+E,VG,VG+E,VGY,VGY+E,VM,VM+E,VMY,VMY+E
this.wordnetAnnotation = "v#" + this.lemma;
this.wordnetAnnotation = "v#" + this.lemma.toLowerCase();
else if (this.PoS.startsWith("A") || this.PoS.startsWith("D")) // - a (adjective): AS,AP,AN,DS,DP,DN
this.wordnetAnnotation = "a#" + this.lemma;
this.wordnetAnnotation = "a#" + this.lemma.toLowerCase();
else if (this.PoS.startsWith("B")) // - r (adverb): B
this.wordnetAnnotation = "r#" + this.lemma;
this.wordnetAnnotation = "r#" + this.lemma.toLowerCase();

}

Expand Down
10 changes: 0 additions & 10 deletions src/main/java/eu/fbk/hlt/nlp/criteria/Synonym.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,18 @@ public static boolean evaluate(Keyphrase key1, Keyphrase key2, Keyphrases keys)
return false;
}

//String pippo = null;

int synonymsCount = 0;
for (int i = 0; i < key1.length(); i++) {
if (key1.get(i).getForm().equals(key2.get(i).getForm())) {
}
else if (key1.get(i).getPoS().equals(key2.get(i).getPoS()) &&
keys.synonyms(key1.get(i), key2.get(i))) {
synonymsCount++;
//pippo = "trovato t:" + key1.getText() + "\t" + key2.getText();
//System.out.println("trovato:" + key1.getText() + "\t" + key2.getText());
//System.out.println("trovato t:" + key1.get(i).getForm() + "\t" + key2.get(i).getForm());
}
else
return false;
}

if (synonymsCount == 1) {
//System.out.println(synonymsCount);
//System.out.println(pippo);;
}

return (synonymsCount == 1);

}
Expand Down

0 comments on commit efee182

Please sign in to comment.