Example usage for edu.stanford.nlp.ling CoreLabel keySet

List of usage examples for edu.stanford.nlp.ling CoreLabel keySet

Introduction

In this page you can find the example usage for edu.stanford.nlp.ling CoreLabel keySet.

Prototype

@Override
public Set<Class<?>> keySet() 

Source Link

Usage

From source file:de.iisys.ocr.pos.CustomNERFeatureFactory.java

License:Open Source License

@SuppressWarnings({ "unchecked", "SuspiciousMethodCalls" })
private void makeGenericKeyCache(CoreLabel c) {
    genericAnnotationKeys = Generics.newHashSet();
    for (Class<?> key : c.keySet()) {
        if (CoreLabel.genericValues.containsKey(key)) {
            Class<? extends GenericAnnotation<?>> genKey = (Class<? extends GenericAnnotation<?>>) key;
            genericAnnotationKeys.add(genKey);
        }/*from ww  w  . j a v  a 2 s.  c o  m*/
    }
}

From source file:edu.jhu.hlt.concrete.stanford.CoreMapWrapper.java

License:Open Source License

private StanfordToConcreteConversionOutput convertCoreLabels(final int cOffset) throws AnalyticException {
    TokenTagging nerTT = new TokenTaggingFactory(this.gen).create("NER")
            .setMetadata(AnnotationMetadataFactory.fromCurrentLocalTime().setTool("Stanford CoreNLP"));
    TokenTagging posTT = new TokenTaggingFactory(this.gen).create("POS")
            .setMetadata(AnnotationMetadataFactory.fromCurrentLocalTime().setTool("Stanford CoreNLP"));
    TokenTagging lemmaTT = new TokenTaggingFactory(this.gen).create("LEMMA")
            .setMetadata(AnnotationMetadataFactory.fromCurrentLocalTime().setTool("Stanford CoreNLP"));

    List<Token> tokList = new ArrayList<>(this.clList.size());
    for (CoreLabel cl : this.clList) {
        final Set<Class<?>> keySet = cl.keySet();
        Token t;/*from   w w  w  . j ava2s .  c o m*/
        if (keySet.contains(PartOfSpeechAnnotation.class)) {
            PreNERCoreLabelWrapper wrapper = new PreNERCoreLabelWrapper(cl);
            t = wrapper.getOrig().toConcreteToken(cOffset);
            wrapper.toPOSToken().ifPresent(tt -> posTT.addToTaggedTokenList(tt));
            wrapper.toNERToken().ifPresent(tt -> nerTT.addToTaggedTokenList(tt));
            wrapper.toLemmaToken().ifPresent(tt -> lemmaTT.addToTaggedTokenList(tt));
        } else {
            LOGGER.trace("Preparing to wrap CoreLabel: {}", cl.toShorterString(new String[0]));
            TokenizedCoreLabelWrapper wrapper = new TokenizedCoreLabelWrapper(cl);
            t = wrapper.toConcreteToken(cOffset);
        }

        tokList.add(t);
    }

    // this is literally just a 4-tuple
    // to make other things cleaner
    return new StanfordToConcreteConversionOutput(tokList, nerTT, posTT, lemmaTT);
}

From source file:org.jdmp.stanfordpos.CoreLabelMapMatrix.java

License:Open Source License

public CoreLabelMapMatrix(CoreLabel coreLabel) {
    for (Class c : coreLabel.keySet()) {
        if (CoreAnnotations.ValueAnnotation.class == c) {
            map.put("Value", coreLabel.getString(CoreAnnotations.ValueAnnotation.class));
        } else if (CoreAnnotations.TextAnnotation.class == c) {
            map.put("Token", coreLabel.getString(CoreAnnotations.TextAnnotation.class));
        } else if (CoreAnnotations.OriginalTextAnnotation.class == c) {
            map.put("OriginalText", coreLabel.getString(CoreAnnotations.OriginalTextAnnotation.class));
        } else if (CoreAnnotations.CharacterOffsetBeginAnnotation.class == c) {
            map.put("CharacterOffsetBegin",
                    String.valueOf(coreLabel.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class)));
        } else if (CoreAnnotations.CharacterOffsetEndAnnotation.class == c) {
            map.put("CharacterOffsetEnd",
                    String.valueOf(coreLabel.get(CoreAnnotations.CharacterOffsetEndAnnotation.class)));
        } else if (CoreAnnotations.PositionAnnotation.class == c) {
            map.put("CharacterOffsetEnd", coreLabel.getString(CoreAnnotations.PositionAnnotation.class));
        } else if (CoreAnnotations.BeforeAnnotation.class == c) {
            map.put("Before", coreLabel.getString(CoreAnnotations.BeforeAnnotation.class));
        } else if (CoreAnnotations.ShapeAnnotation.class == c) {
            map.put("Shape", coreLabel.getString(CoreAnnotations.ShapeAnnotation.class));
        } else if (CoreAnnotations.GoldAnswerAnnotation.class == c) {
            map.put("GoldAnswer", coreLabel.getString(CoreAnnotations.GoldAnswerAnnotation.class));
        } else if (CoreAnnotations.AnswerAnnotation.class == c) {
            map.put("Answer", coreLabel.getString(CoreAnnotations.AnswerAnnotation.class));
        } else if (CoreAnnotations.AfterAnnotation.class == c) {
            map.put("After", coreLabel.getString(CoreAnnotations.AfterAnnotation.class));
        } else {//  w ww. j  a  v a  2s  .c om
            throw new RuntimeException("unknown key class: " + c);
        }
    }
}