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

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

Introduction

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

Prototype

@Override
public String toShorterString(String... what) 

Source Link

Usage

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;/*ww  w . j a  v  a  2 s  .  com*/
        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);
}