List of usage examples for edu.stanford.nlp.ling IndexedWord beginPosition
@Override
public int beginPosition()
From source file:edu.illinois.cs.cogcomp.pipeline.handlers.StanfordDepHandler.java
License:Open Source License
/** * Gets the token index of a Stanford dependency node relative to the current sentence * //w ww . j a v a 2 s . co m * @param ta The TextAnnotation containing the sentences * @param node The Stanford Dependency node * @param sentId The sentence number * @return The token index relative to sentence */ private int getNodePosition(TextAnnotation ta, IndexedWord node, int sentId) { int sentenceStart = ta.getView(ViewNames.SENTENCE).getConstituents().get(sentId).getStartSpan(); int nodeCharacterOffset = node.beginPosition(); int tokenStartSpan = ta.getTokenIdFromCharacterOffset(nodeCharacterOffset); return tokenStartSpan - sentenceStart; }
From source file:eu.ubipol.opinionmining.nlp_engine.Sentence.java
License:Open Source License
protected Sentence(SemanticGraph dependencies, int indexStart, DatabaseAdapter adp, int beginPosition) { IndexedWord rootWord = dependencies.getFirstRoot(); sentenceRoot = new Token(rootWord.originalText(), rootWord.lemma(), rootWord.tag(), null, null, rootWord.index() + indexStart, rootWord.beginPosition(), rootWord.endPosition(), adp, beginPosition);//w w w . j a v a 2s . c om addChildTokens(sentenceRoot, rootWord, dependencies, indexStart, adp, beginPosition); sentenceRoot.transferScores(); if (sentenceRoot.isAKeyword()) sentenceRoot.addAspectScore(sentenceRoot.getScore(), sentenceRoot.getWeight(), sentenceRoot.getAspect()); indexStart += dependencies.size(); }
From source file:eu.ubipol.opinionmining.nlp_engine.Sentence.java
License:Open Source License
private void addChildTokens(Token rootToken, IndexedWord currentRoot, SemanticGraph dependencies, int indexStart, DatabaseAdapter adp, int beginPosition) { for (IndexedWord child : dependencies.getChildren(currentRoot)) { Token childToken = new Token(child.originalText(), child.lemma(), child.tag(), rootToken, dependencies.getEdge(currentRoot, child).toString(), child.index() + indexStart, child.beginPosition(), child.endPosition(), adp, beginPosition); rootToken.addChildToken(childToken); addChildTokens(childToken, child, dependencies, indexStart, adp, beginPosition); }/*ww w .jav a 2 s .co m*/ }