use of edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence in project cogcomp-nlp by CogComp.
the class ClassifierComparison method structuredCVal.
public static EvaluateDiscrete structuredCVal(StructuredCommaClassifier model, Parser parser, boolean useGoldFeatures, boolean testOnTrain) throws Exception {
Comma.useGoldFeatures(useGoldFeatures);
int k = 5;
parser.reset();
FoldParser foldParser = new FoldParser(parser, k, SplitPolicy.sequential, 0, false);
EvaluateDiscrete cvalResult = new EvaluateDiscrete();
for (int i = 0; i < k; foldParser.setPivot(++i)) {
foldParser.setFromPivot(false);
foldParser.reset();
LinkedHashSet<CommaSRLSentence> trainSentences = new LinkedHashSet<>();
for (Object comma = foldParser.next(); comma != null; comma = foldParser.next()) {
trainSentences.add(((Comma) comma).getSentence());
}
model.train(new ArrayList<>(trainSentences), null);
if (!testOnTrain)
foldParser.setFromPivot(true);
foldParser.reset();
LinkedHashSet<CommaSRLSentence> testSentences = new LinkedHashSet<>();
for (Object comma = foldParser.next(); comma != null; comma = foldParser.next()) {
testSentences.add(((Comma) comma).getSentence());
}
EvaluateDiscrete evaluator = model.test(new ArrayList<>(testSentences), null);
cvalResult.reportAll(evaluator);
}
cvalResult.printPerformance(System.out);
return cvalResult;
}
use of edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence in project cogcomp-nlp by CogComp.
the class CommaLabeler method addView.
@Override
public void addView(TextAnnotation ta) throws AnnotatorException {
// Check that we have the required views
for (String requiredView : requiredViews) {
if (!ta.hasView(requiredView))
throw new AnnotatorException("Missing required view " + requiredView);
}
// Create the Comma structure
CommaSRLSentence sentence = new CommaSRLSentence(ta, ta);
PredicateArgumentView srlView = new PredicateArgumentView(viewName, "illinois-comma", ta, 1.0d);
for (Comma comma : sentence.getCommas()) {
String label = classifier.discreteValue(comma);
int position = comma.getPosition();
Constituent predicate = new Constituent("Predicate:" + label, viewName, ta, position, position + 1);
predicate.addAttribute(PredicateArgumentView.SenseIdentifer, label);
srlView.addConstituent(predicate);
Constituent leftArg = comma.getPhraseToLeftOfComma(1);
if (leftArg != null) {
Constituent leftArgConst = new Constituent(leftArg.getLabel(), viewName, ta, leftArg.getStartSpan(), leftArg.getEndSpan());
srlView.addConstituent(leftArgConst);
srlView.addRelation(new Relation("LeftOf" + label, predicate, leftArgConst, 1.0d));
}
Constituent rightArg = comma.getPhraseToRightOfComma(1);
if (rightArg != null) {
Constituent rightArgConst = new Constituent(rightArg.getLabel(), viewName, ta, rightArg.getStartSpan(), rightArg.getEndSpan());
srlView.addConstituent(rightArgConst);
srlView.addRelation(new Relation("RightOf" + label, predicate, rightArgConst, 1.0d));
}
}
ta.addView(viewName, srlView);
}
use of edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence in project cogcomp-nlp by CogComp.
the class ListCommasConstrainedInference$subjectto method makeConstraint.
public FirstOrderConstraint makeConstraint(Object __example) {
if (!(__example instanceof CommaSRLSentence)) {
String type = __example == null ? "null" : __example.getClass().getName();
System.err.println("Constraint 'ListCommasConstrainedInference$subjectto(CommaSRLSentence)' defined on line 280 of CommaClassifier.lbj received '" + type + "' as input.");
new Exception().printStackTrace();
System.exit(1);
}
CommaSRLSentence s = (CommaSRLSentence) __example;
FirstOrderConstraint __result = new FirstOrderConstant(true);
{
FirstOrderConstraint LBJava$constraint$result$0 = null;
LBJava$constraint$result$0 = __listCommas.makeConstraint(s);
__result = new FirstOrderConjunction(__result, LBJava$constraint$result$0);
}
return __result;
}
Aggregations