use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.
the class LocativePairConstrainedCommaClassifier method discreteValue.
public String discreteValue(Object __example) {
if (!(__example instanceof Comma)) {
String type = __example == null ? "null" : __example.getClass().getName();
System.err.println("Classifier 'LocativePairConstrainedCommaClassifier(Comma)' defined on line 276 of CommaClassifier.lbj received '" + type + "' as input.");
new Exception().printStackTrace();
System.exit(1);
}
CommaSRLSentence head = LocativePairConstrainedInference.findHead((Comma) __example);
LocativePairConstrainedInference inference = (LocativePairConstrainedInference) InferenceManager.get("edu.illinois.cs.cogcomp.comma.lbj.LocativePairConstrainedInference", head);
if (inference == null) {
inference = new LocativePairConstrainedInference(head);
InferenceManager.put(inference);
}
String result = null;
try {
result = inference.valueOf(__LocalCommaClassifier, __example);
} catch (Exception e) {
System.err.println("LBJava ERROR: Fatal error while evaluating classifier LocativePairConstrainedCommaClassifier: " + e);
e.printStackTrace();
System.exit(1);
}
return result;
}
use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.
the class OxfordCommaConstrainedCommaClassifier method discreteValue.
public String discreteValue(Object __example) {
if (!(__example instanceof Comma)) {
String type = __example == null ? "null" : __example.getClass().getName();
System.err.println("Classifier 'OxfordCommaConstrainedCommaClassifier(Comma)' defined on line 260 of CommaClassifier.lbj received '" + type + "' as input.");
new Exception().printStackTrace();
System.exit(1);
}
CommaSRLSentence head = OxfordCommaConstrainedInference.findHead((Comma) __example);
OxfordCommaConstrainedInference inference = (OxfordCommaConstrainedInference) InferenceManager.get("edu.illinois.cs.cogcomp.comma.lbj.OxfordCommaConstrainedInference", head);
if (inference == null) {
inference = new OxfordCommaConstrainedInference(head);
InferenceManager.put(inference);
}
String result = null;
try {
result = inference.valueOf(__LocalCommaClassifier, __example);
} catch (Exception e) {
System.err.println("LBJava ERROR: Fatal error while evaluating classifier OxfordCommaConstrainedCommaClassifier: " + e);
e.printStackTrace();
System.exit(1);
}
return result;
}
use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.
the class ParentSiblingPhraseFeatures method classify.
public FeatureVector classify(Object __example) {
if (!(__example instanceof Comma)) {
String type = __example == null ? "null" : __example.getClass().getName();
System.err.println("Classifier 'ParentSiblingPhraseFeatures(Comma)' defined on line 47 of CommaClassifier.lbj received '" + type + "' as input.");
new Exception().printStackTrace();
System.exit(1);
}
Comma c = (Comma) __example;
FeatureVector __result;
__result = new FeatureVector();
String __id;
String __value;
String[] ngrams = c.getParentSiblingPhraseNgrams();
for (int i = 0; i < ngrams.length; i++) {
__id = "" + (ngrams[i]);
__value = "true";
__result.addFeature(new DiscretePrimitiveStringFeature(this.containingPackage, this.name, __id, __value, valueIndexOf(__value), (short) 0));
}
return __result;
}
use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.
the class ClassifierComparison method getBayraktarBaselinePerformance.
/**
* prints Bayraktar baseline performance based on only those commas whose Bayraktar patterns
* have been annotated
*/
public static EvaluateDiscrete getBayraktarBaselinePerformance(Parser parser, boolean testOnGold) {
parser.reset();
EvaluateDiscrete bayraktarEvaluation = new EvaluateDiscrete();
Comma comma;
while ((comma = (Comma) parser.next()) != null) {
if (!BayraktarPatternLabeler.isLabelAvailable(comma))
continue;
Comma.useGoldFeatures(true);
String goldLabel = comma.getLabel();
Comma.useGoldFeatures(testOnGold);
String bayraktarPrediction = comma.getBayraktarLabel();
bayraktarEvaluation.reportPrediction(bayraktarPrediction, goldLabel);
}
return bayraktarEvaluation;
}
use of edu.illinois.cs.cogcomp.comma.datastructures.Comma 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);
}
Aggregations