Search in sources :

Example 81 with TextAnnotation

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation in project cogcomp-nlp by CogComp.

the class MultilingualEreReaderTest method testReader.

private static void testReader(EREEventReader reader) {
    assertTrue(reader.hasNext());
    XmlTextAnnotation xmlTa = reader.next();
    TextAnnotation ta = xmlTa.getTextAnnotation();
    assertTrue(ta.hasView(ViewNames.MENTION_ERE));
    assertTrue(ta.getView(ViewNames.MENTION_ERE).getConstituents().size() > 5);
    assertTrue(ta.getView(ViewNames.MENTION_ERE).getRelations().size() > 0);
    assertTrue(ta.hasView(ViewNames.EVENT_ERE));
    assertTrue(ta.getView(ViewNames.EVENT_ERE).getConstituents().size() > 1);
    assertTrue(ta.getView(ViewNames.EVENT_ERE).getRelations().size() > 2);
}
Also used : XmlTextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.XmlTextAnnotation) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) XmlTextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.XmlTextAnnotation)

Example 82 with TextAnnotation

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation in project cogcomp-nlp by CogComp.

the class StanfordCorefHandler method addView.

@Override
protected void addView(TextAnnotation ta) throws AnnotatorException {
    Annotation document = new Annotation(ta.text);
    pipeline.annotate(document);
    CoreferenceView vu = new CoreferenceView(viewName, ta);
    Map corefChain = document.get(CorefCoreAnnotations.CorefChainAnnotation.class);
    for (Object key : corefChain.keySet()) {
        CorefChain chain = (CorefChain) corefChain.get(key);
        Constituent representative = createConstituentGivenMention(document, chain, chain.getRepresentativeMention(), ta);
        List<Constituent> consList = new ArrayList<>();
        for (CorefChain.CorefMention m : chain.getMentionsInTextualOrder()) {
            consList.add(createConstituentGivenMention(document, chain, m, ta));
        }
        // remove the representative itself
        consList.remove(representative);
        vu.addCorefEdges(representative, consList);
    }
    ta.addView(viewName, vu);
}
Also used : CoreferenceView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.CoreferenceView) CorefChain(edu.stanford.nlp.coref.data.CorefChain) CorefCoreAnnotations(edu.stanford.nlp.coref.CorefCoreAnnotations) CoreMap(edu.stanford.nlp.util.CoreMap) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Annotation(edu.stanford.nlp.pipeline.Annotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 83 with TextAnnotation

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation in project cogcomp-nlp by CogComp.

the class CreateTestFeaturesResource method addFeatCollection.

private void addFeatCollection() throws EdisonException, IOException {
    Map<Integer, String> map = new HashMap<>();
    FeatureCollection featureCollection = new FeatureCollection("features");
    featureCollection.addFeatureExtractor(WordFeatureExtractorFactory.conflatedPOS);
    featureCollection.addFeatureExtractor(WordFeatureExtractorFactory.gerundMarker);
    featureCollection.addFeatureExtractor(WordFeatureExtractorFactory.nominalizationMarker);
    for (TextAnnotation ta : tas) {
        for (int tokenId = 0; tokenId < ta.size(); tokenId++) {
            Constituent c = new Constituent("", "", ta, tokenId, tokenId + 1);
            Set<Feature> features = featureCollection.getFeatures(c);
            if (features.size() > 0) {
                String id = ta.getTokenizedText() + ":" + tokenId;
                map.put(id.hashCode(), features.toString());
            }
        }
    }
    IOUtils.writeObject(map, FEATURE_COLLECTION_FILE);
}
Also used : HashMap(java.util.HashMap) FeatureCollection(edu.illinois.cs.cogcomp.edison.features.FeatureCollection) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 84 with TextAnnotation

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation in project cogcomp-nlp by CogComp.

the class CreateTestFeaturesResource method addBrownFeatures.

private void addBrownFeatures() throws EdisonException {
    logger.info("\tadding Brown cluster features");
    WordFeatureExtractor brownFeatureGenerator = WordFeatureExtractorFactory.getBrownFeatureGenerator("", "brownBllipClusters", new int[] { 4, 5 });
    for (TextAnnotation ta : tas) {
        addFeatures(ta, brownFeatureGenerator);
    }
}
Also used : WordFeatureExtractor(edu.illinois.cs.cogcomp.edison.features.WordFeatureExtractor) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)

Example 85 with TextAnnotation

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation in project cogcomp-nlp by CogComp.

the class CreateTestFeaturesResource method addWordNet.

private void addWordNet() throws EdisonException {
    logger.info("\tadding wordNet");
    WordNetManager.loadConfigAsClasspathResource(true);
    for (TextAnnotation ta : tas) {
        addFeatures(ta, WordFeatureExtractorFactory.getWordNetFeatureExtractor(WordNetFeatureExtractor.WordNetFeatureClass.existsEntry, WordNetFeatureExtractor.WordNetFeatureClass.synsetsFirstSense, WordNetFeatureExtractor.WordNetFeatureClass.lexicographerFileNamesAllSenses));
    }
}
Also used : TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)

Aggregations

TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)218 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)95 Test (org.junit.Test)65 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)49 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)48 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)29 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)28 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)25 ArrayList (java.util.ArrayList)23 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)22 LinkedHashSet (java.util.LinkedHashSet)21 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)16 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)16 FeatureExtractor (edu.illinois.cs.cogcomp.edison.features.FeatureExtractor)16 ProjectedPath (edu.illinois.cs.cogcomp.edison.features.lrec.ProjectedPath)16 FeatureManifest (edu.illinois.cs.cogcomp.edison.features.manifest.FeatureManifest)16 FileInputStream (java.io.FileInputStream)16 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)14 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)12 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)11