-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextUnderstandingProject.java
105 lines (87 loc) · 3.91 KB
/
TextUnderstandingProject.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//Entailment absolute threshold version
package eu.excitementproject.eop.biutee.text_understanding_project;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.uima.jcas.JCas;
import org.cyberneko.html.filters.Writer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.aliasi.util.Files;
import com.google.common.collect.Lists;
import eu.excitementproject.eop.biutee.rteflow.systems.excitement.BiuteeEDA;
import eu.excitementproject.eop.common.DecisionLabel;
import eu.excitementproject.eop.common.EDAException;
import eu.excitementproject.eop.common.TEDecision;
import eu.excitementproject.eop.common.exception.ComponentException;
import eu.excitementproject.eop.common.exception.ConfigurationException;
import eu.excitementproject.eop.common.utilities.configuration.ImplCommonConfig;
import eu.excitementproject.eop.lap.LAPAccess;
import eu.excitementproject.eop.lap.biu.test.BiuTestUtils;
import eu.excitementproject.eop.lap.biu.uima.BIUFullLAP;
import gate.creole.annic.apache.lucene.store.InputStream;
public class TextUnderstandingProject {
public final static int EntailmentsThreshold = 4; // first form
public final static double EntailmentPortion = 0.15; // second form
public final static double EntailmentConfidenceThreshold = -0.3; // third form
@SuppressWarnings("unchecked")
public static void main(String[] args){
try {
/* load lap and biutee */
//BiuTestUtils.assumeBiuEnvironment();
LAPAccess lap = new BIUFullLAP(
"../third-party/stanford-postagger-full-2008-09-28/models/left3words-wsj-0-18.tagger",
"../third-party/stanford-ner-2009-01-16/classifiers/ner-eng-ie.crf-3-all2008-distsim.ser.gz",
"localhost",
8080);
BiuteeEDA biutee = new BiuteeEDA();
biutee.initialize(new ImplCommonConfig(new File("biutee.xml")));
/* load jsons */
JSONArray toTagJson = new JSONArray(Files.readFromFile(new File("../TUProject/test1.json")));
JSONObject possibleTagsJson = new JSONObject(Files.readFromFile(new File("../TUProject/train1.json")));
List<String> tags = Lists.newArrayList(possibleTagsJson.keys());
/* run biutee */
for (int toTagIndex =0;toTagIndex < toTagJson.length();toTagIndex++){
JSONObject curEntry = toTagJson.getJSONObject(toTagIndex);
String t = curEntry.getString("input");
JSONArray curTags = new JSONArray();
for(String tag : tags){
JSONArray arr = possibleTagsJson.getJSONArray(tag);
int entailments = 0; // first & second form
//double confidenceSum = 0.0; // third form
for(int exampleNumber=0;exampleNumber < arr.length();exampleNumber++){
String h = (String) arr.get(exampleNumber);
JCas jcas = lap.generateSingleTHPairCAS(t,h);
TEDecision decision = biutee.process(jcas);
if (decision.getDecision() == DecisionLabel.Entailment){ // first & second form
entailments++;
if (entailments == EntailmentsThreshold) { // first form
curTags.put(tag);
break;
}
}
}
}
curEntry.put("tags", curTags);
}
/* write answers to file */
PrintWriter out = new PrintWriter( "../TUProject/ans1.json");
String s = toTagJson.toString();
out.println(s);
out.close();
/* THE END */
System.out.println("-- THE END --");
} catch (IOException | ConfigurationException | EDAException | ComponentException | JSONException e) {
e.printStackTrace();
}
}
}