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

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

Introduction

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

Prototype

@Override
public final void setValue(String value) 

Source Link

Usage

From source file:BuildBinarizedDataset.java

public static boolean setSpanLabel(Tree tree, Pair<Integer, Integer> span, String value) {
    if (!(tree.label() instanceof CoreLabel)) {
        throw new AssertionError("Expected CoreLabels");
    }/*from  www . j  a  va2 s .c  om*/
    CoreLabel label = (CoreLabel) tree.label();
    if (label.get(CoreAnnotations.BeginIndexAnnotation.class).equals(span.first)
            && label.get(CoreAnnotations.EndIndexAnnotation.class).equals(span.second)) {
        label.setValue(value);
        return true;
    }
    if (label.get(CoreAnnotations.BeginIndexAnnotation.class) > span.first
            && label.get(CoreAnnotations.EndIndexAnnotation.class) < span.second) {
        return false;
    }
    for (Tree child : tree.children()) {
        if (setSpanLabel(child, span, value)) {
            return true;
        }
    }
    return false;
}

From source file:conditionalCFG.ConditionalCFGParser.java

License:Open Source License

private CoreLabel getCoreLabel(int labelIndex) {
    if (originalCoreLabels[labelIndex] != null) {
        CoreLabel terminalLabel = originalCoreLabels[labelIndex];
        if (terminalLabel.value() == null && terminalLabel.word() != null) {
            terminalLabel.setValue(terminalLabel.word());
        }/*from w  w  w  .  j  ava  2  s.  c om*/
        return terminalLabel;
    }

    String wordStr = wordIndex.get(words[labelIndex]);
    CoreLabel terminalLabel = new CoreLabel();
    terminalLabel.setValue(wordStr);
    terminalLabel.setWord(wordStr);
    terminalLabel.setBeginPosition(beginOffsets[labelIndex]);
    terminalLabel.setEndPosition(endOffsets[labelIndex]);
    if (originalTags[labelIndex] != null) {
        terminalLabel.setTag(originalTags[labelIndex].tag());
    }
    return terminalLabel;
}

From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordParser.java

License:Open Source License

protected CoreLabel tokenToWord(Token aToken) {
    CoreLabel l = CoreNlpUtils.tokenToWord(aToken);
    l.setValue(aToken.getCoveredText());
    if (!readPos) {
        l.setTag(null);/*ww  w .  j  a v a2  s .  c  o m*/
    }
    return l;
}

From source file:opendial.bn.values.RelationalVal.java

License:Open Source License

public int addNode(String value) {
    CoreLabel label = new CoreLabel();
    label.setWord(value);/*from  w ww  . j av  a  2s  .c  o  m*/
    label.setValue(value);
    IndexedWord fword = new IndexedWord(label);
    fword.setIndex(graph.size());
    graph.addVertex(fword);
    cachedHashCode = 0;
    return fword.index();
}

From source file:opennlp.tools.parse_thicket.opinion_processor.DefaultSentimentProcessor.java

License:Apache License

/**
 * Sets the labels on the tree (except the leaves) to be the integer value
 * of the sentiment prediction. Makes it easy to print out with
 * Tree.toString()//from  ww w.  j  av  a 2s.co m
 */
static void setSentimentLabels(Tree tree) {
    if (tree.isLeaf()) {
        return;
    }

    for (Tree child : tree.children()) {
        setSentimentLabels(child);
    }

    Label label = tree.label();
    if (!(label instanceof CoreLabel)) {
        throw new IllegalArgumentException("Required a tree with CoreLabels");
    }
    CoreLabel cl = (CoreLabel) label;
    cl.setValue(Integer.toString(RNNCoreAnnotations.getPredictedClass(tree)));
}

From source file:org.knime.ext.textprocessing.nodes.tagging.stanfordnlpnetagger.StanfordNlpNeDocumentTagger.java

License:Open Source License

/**
 * {@inheritDoc}//from   w  ww. ja  v  a2  s.c  om
 */
@Override
protected List<TaggedEntity> tagEntities(final Sentence sentence) {
    List<HasWord> wordList = new ArrayList<>();
    for (Term t : sentence.getTerms()) {
        for (Word w : t.getWords()) {
            wordList.add(new edu.stanford.nlp.ling.Word(w.getText()));
        }
    }
    List<CoreLabel> coreLabelList = edu.stanford.nlp.ling.SentenceUtils.toCoreLabelList(wordList);
    List<CoreLabel> taggedWords = m_tagger.classifySentence(coreLabelList);

    List<TaggedEntity> taggedEntities = new ArrayList<TaggedEntity>();
    CoreLabel previousCl = null;
    int count = 0;
    for (CoreLabel tw : taggedWords) {
        // getting the tag from current CoreLabel
        String answer = tw.getString(CoreAnnotations.AnswerAnnotation.class);
        // checking if tag is available (O means no tag)
        if (!answer.equals("O")) {
            // checking if successive terms with same tags should be combined to one term
            if (m_combineMultiWords) {
                // check if a previous CoreLabel with tag exists
                if (previousCl == null) {
                    previousCl = tw;
                } else {
                    // check if tag from previous corelabel matches tag from current corelabel and combine them
                    if (answer.equals(previousCl.getString(CoreAnnotations.AnswerAnnotation.class))) {
                        String prevValue = previousCl.getString(CoreAnnotations.ValueAnnotation.class);
                        String currentValue = tw.getString(CoreAnnotations.ValueAnnotation.class);
                        CoreLabel combinedCl = tw;
                        combinedCl.setValue(prevValue + TOKEN_SEPARATOR + currentValue);
                        previousCl = combinedCl;
                    } else {
                        addTaggedEntity(taggedEntities, previousCl);
                        previousCl = tw;
                    }
                    // add tagged entity if tagged term is the last one of the sentence
                    if (count == taggedWords.size() - 1) {
                        addTaggedEntity(taggedEntities, previousCl);
                    }
                }
            } else {
                addTaggedEntity(taggedEntities, tw);
            }
        } else {
            if (previousCl != null) {
                addTaggedEntity(taggedEntities, previousCl);
            }
            previousCl = null;
        }
        count++;
    }
    return taggedEntities;
}

From source file:reactivetechnologies.sentigrade.engine.nlp.SentimentAnalyzer.java

License:Apache License

private static void outputPredictedClass(Tree tree) {
    Label label = tree.label();/*from   w  w  w.  j a  v a  2 s .  co  m*/
    if (!(label instanceof CoreLabel)) {
        throw new IllegalArgumentException("Required a tree with CoreLabels");
    }
    CoreLabel cl = (CoreLabel) label;
    cl.setValue(Integer.toString(RNNCoreAnnotations.getPredictedClass(tree)));

}

From source file:semRewrite.substitutor.CoreLabelSequence.java

License:Open Source License

/** *************************************************************
 * Change the value() of each CoreLabel to be all caps
 */// www.j a v a 2 s. c  o m
public semRewrite.substitutor.CoreLabelSequence toUpperCase() {

    //System.out.println("CoreLabelSequence.toUpperCase(): labels: " + labels);
    List<CoreLabel> lcl = new ArrayList<>();
    for (CoreLabel cl : labels) {
        CoreLabel newcl = new CoreLabel();
        newcl.setValue(cl.value().toUpperCase());
        newcl.setIndex(cl.index());
        lcl.add(newcl);
    }
    semRewrite.substitutor.CoreLabelSequence cls = new semRewrite.substitutor.CoreLabelSequence(lcl);
    //System.out.println("CoreLabelSequence.toUpperCase(): cls: " + cls);
    return cls;
}

From source file:semRewrite.substitutor.CoreLabelSequence.java

License:Open Source License

/** *************************************************************
 *//*w  w w.j  a v  a 2s  .  c  o m*/
public semRewrite.substitutor.CoreLabelSequence removePunctuation() {

    //System.out.println("CoreLabelSequence.toUpperCase(): removePunctuation: " + labels);
    semRewrite.substitutor.CoreLabelSequence cls = new semRewrite.substitutor.CoreLabelSequence(labels);
    for (CoreLabel cl : labels) {
        String puncRE = "[\\.\\,\\;\\:\\[\\]\\{\\}\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\-\\=\\_\\+\\`\\~\\<\\>\\/\\?]";
        if (cl.value().matches(puncRE))
            cl.setValue(cl.value().replace(puncRE, ""));
    }
    //System.out.println("CoreLabelSequence.toUpperCase(): cls: " + cls);
    return cls;
}

From source file:semRewrite.substitutor.ExternalSubstitutor.java

License:Open Source License

private static List<CoreLabel> stringToCoreLabelList(String s) {

    ArrayList<CoreLabel> al = new ArrayList<>();
    String[] splits = s.split(" ");
    for (String word : splits) {
        CoreLabel cl = new CoreLabel();
        cl.setValue(word);
        al.add(cl);/* www  .j  a  v a  2  s . com*/
    }
    return al;
}