本文整理汇总了Java中opennlp.tools.parser.AbstractBottomUpParser类的典型用法代码示例。如果您正苦于以下问题:Java AbstractBottomUpParser类的具体用法?Java AbstractBottomUpParser怎么用?Java AbstractBottomUpParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractBottomUpParser类属于opennlp.tools.parser包,在下文中一共展示了AbstractBottomUpParser类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parseSentence
import opennlp.tools.parser.AbstractBottomUpParser; //导入依赖的package包/类
private Parse parseSentence(final Sentence sentence, final Collection<WordToken> tokens) {
final String text = sentence.getCoveredText();
final Parse parse = new Parse(text, new Span(0, text.length()), AbstractBottomUpParser.INC_NODE, 1, 0);
// Add in the POS
int index = 0;
for (final WordToken token : tokens) {
final Span span = new Span(token.getBegin() - sentence.getBegin(), token.getEnd() - sentence.getBegin());
parse.insert(new Parse(text, span, AbstractBottomUpParser.TOK_NODE, 0, index));
index++;
}
// Parse the sentence
return parser.parse(parse);
}
开发者ID:tenode,项目名称:baleen-extras,代码行数:18,代码来源:OpenNLPParser.java
示例2: getTermTags
import opennlp.tools.parser.AbstractBottomUpParser; //导入依赖的package包/类
private void getTermTags(Parse parse, Multimap<String, String> termTags) {
String POS = "";
String text = "";
if (!parse.getType().equals(AbstractBottomUpParser.TOK_NODE)) {
POS = parse.getType();
text = parse.getCoveredText();
}
List<Parse> parts = Arrays.asList(parse.getChildren());
if (!POS.isEmpty() && !text.isEmpty()) {
termTags.put(POS, text);
}
for (Iterator<Parse> i = parts.iterator(); i.hasNext();) {
Parse c = i.next();
getTermTags(c, termTags);
}
}
开发者ID:TekstoSense,项目名称:word-root-finder,代码行数:17,代码来源:OpenNLPParser.java
示例3: parseSentence
import opennlp.tools.parser.AbstractBottomUpParser; //导入依赖的package包/类
/**
* Parses the sentence.
*
* @param sentence
* the sentence
* @param tokens
* the tokens
* @return the parses the
*/
private Parse parseSentence(final Sentence sentence, final Collection<WordToken> tokens) {
final String text = sentence.getCoveredText();
final Parse parse = new Parse(text, new Span(0, text.length()), AbstractBottomUpParser.INC_NODE, 1, 0);
// Add in the POS
int index = 0;
for (final WordToken token : tokens) {
final Span span = new Span(token.getBegin() - sentence.getBegin(), token.getEnd() - sentence.getBegin());
parse.insert(new Parse(text, span, AbstractBottomUpParser.TOK_NODE, 0, index));
index++;
}
// Parse the sentence
return parser.parse(parse);
}
开发者ID:dstl,项目名称:baleen,代码行数:27,代码来源:OpenNLPParser.java
示例4: createParseFromChunks
import opennlp.tools.parser.AbstractBottomUpParser; //导入依赖的package包/类
public Parse createParseFromChunks(String text, String[] tokens, Span[] tokenspans, String[] tags, String[] chunks) throws Exception {
Parse topParse = new Parse(text, new Span(0,text.length()), AbstractBottomUpParser.TOP_NODE, 1.0, 1);
Parse sentenceParse = new Parse(text, new Span(0,text.length()), "S", 1.0, 1);
topParse.insert(sentenceParse);
CSList<Parse> chunkParses = new CSList<Parse>();
int start = 0, chunkstart = 0;
String chunktype = null;
for (int currentChunk = 0, chunkCount = chunks.length;currentChunk < chunkCount;currentChunk++)
{
if (currentChunk > 0 && !chunks[currentChunk].startsWith(CHUNKER_CHUNK_CONT) && !chunks[currentChunk - 1].equals(CHUNKER_CHUNK_OTHER))
// this indicates end of a chunk, so create a chunk with accumulated parses
createChunkParse(text,sentenceParse,chunkParses,start,chunkstart,chunktype);
Parse tokenParse = new Parse(text, tokenspans[currentChunk], AbstractBottomUpParser.TOK_NODE, 1.0, 1);
Parse posParse = new Parse(text, tokenspans[currentChunk], tags[currentChunk], 1.0, 1);
posParse.insert(tokenParse);
if (chunks[currentChunk].equals(CHUNKER_CHUNK_OTHER))
{
sentenceParse.insert(posParse);
}
else if (chunks[currentChunk].startsWith(CHUNKER_CHUNK_START))
{
chunktype = chunks[currentChunk].substring(2);
chunkstart = start;
chunkParses.add(posParse);
}
else if (chunks[currentChunk].startsWith(CHUNKER_CHUNK_CONT))
chunkParses.add(posParse);
start += tokens[currentChunk].length() + 1;
}
if ((!StringSupport.equals(chunks[chunks.length - 1], CHUNKER_CHUNK_OTHER)) && chunkParses.size() > 0)
createChunkParse(text,sentenceParse,chunkParses,start,chunkstart,chunktype);
return topParse;
}
开发者ID:datancoffee,项目名称:sirocco,代码行数:37,代码来源:EnglishIndexer.java
示例5: getSentimentVector
import opennlp.tools.parser.AbstractBottomUpParser; //导入依赖的package包/类
private void getSentimentVector(Parse parse, SentenceFlags sentenceflags, ParseDepth parsedepth, RefSupport<FloatVector> parsevector) throws Exception {
parsevector.setValue(null);
if ((parse == null) || (StringSupport.equals(parse.getType(), "INC")) || (StringSupport.equals(parse.getType(), AbstractBottomUpParser.TOK_NODE)))
{
return ;
}
// check for TK: should not happen, as the recursion stops at POS, but be cautious
// check for null: sometimes the parse tree has null children
// check for not complete: depending on beam size, sentence sometimes does not get parsed correctly
Parse curparse = (!StringSupport.equals(parse.getType(), AbstractBottomUpParser.TOP_NODE)) ? parse : parse.getChildren()[0];
if (curparse.isPosTag())
{
RefSupport<FloatVector> refVar25 = new RefSupport<FloatVector>();
getSentimentVectorFromPOSParse(curparse,sentenceflags,refVar25);
parsevector.setValue(refVar25.getValue());
}
else
{
RefSupport<FloatVector> refVar26 = new RefSupport<FloatVector>();
accumulateVectors(curparse,sentenceflags,new CSList<Parse>(curparse.getChildren()),null,parsedepth,refVar26);
parsevector.setValue(refVar26.getValue());
if (parsevector.getValue() != null)
{
if (sentenceflags.isInQuotes(curparse.getSpan()))
parsevector.getValue().moveAllToAmbiguousSentiment();
Boolean isQSTop = tlQuestionSentenceTop.contains(curparse.getType());
Boolean isSTop = tlSentenceTop.contains(curparse.getType());
if (isQSTop || isTerminatedByQuestion(curparse))
{
parsevector.getValue().moveAllToAmbiguousSentiment();
}
else if (isSTop && parsevector.getValue().containsKey(FloatVector.SlyIronicSarcasticDimension))
{
parsevector.getValue().moveAllToAmbiguousSentiment();
}
if (isQSTop || isSTop)
{
CSList<LabelledSpan> lspans = parsevector.getValue().getDerivationSpans();
for (LabelledSpan lspan : lspans)
sentenceflags.getSpanFlags((Span)lspan).IsSentiment = true;
}
}
}
}
开发者ID:datancoffee,项目名称:sirocco,代码行数:50,代码来源:EnglishIndexer.java
示例6: isLeaf
import opennlp.tools.parser.AbstractBottomUpParser; //导入依赖的package包/类
private boolean isLeaf(Parse parse) {
Parse[] childParses = parse.getChildren();
return childParses.length == 1 && childParses[0].getType() == AbstractBottomUpParser.TOK_NODE;
}
开发者ID:ClearTK,项目名称:cleartk,代码行数:5,代码来源:DefaultOutputTypesHelper.java
示例7: process
import opennlp.tools.parser.AbstractBottomUpParser; //导入依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
String text = jCas.getDocumentText();
List<SENTENCE_TYPE> sentenceList = inputTypesHelper.getSentences(jCas);
for (SENTENCE_TYPE sentence : sentenceList) {
Parse parse = new Parse(
text,
new Span(sentence.getBegin(), sentence.getEnd()),
AbstractBottomUpParser.INC_NODE,
1,
null);
List<TOKEN_TYPE> tokenList = inputTypesHelper.getTokens(jCas, sentence);
for (TOKEN_TYPE token : tokenList) {
parse.insert(new Parse(
text,
new Span(token.getBegin(), token.getEnd()),
AbstractBottomUpParser.TOK_NODE,
0,
0));
}
if (useTagsFromCas) {
this.casTagger.setTokens(tokenList);
}
parse = this.parser.parse(parse);
// if the sentence was successfully parsed, add the tree to the
// sentence
if (parse.getType() == AbstractBottomUpParser.TOP_NODE) {
outputTypesHelper.addParse(jCas, parse, sentence, tokenList);
}
// add the POS tags to the tokens
if (!useTagsFromCas) {
setPOSTags(parse, tokenList.iterator(), jCas);
}
}
}
开发者ID:ClearTK,项目名称:cleartk,代码行数:45,代码来源:ParserAnnotator.java
示例8: getHead
import opennlp.tools.parser.AbstractBottomUpParser; //导入依赖的package包/类
public Parse getHead(final Parse[] constituents, final String type) {
if (constituents[0].getType() == AbstractBottomUpParser.TOK_NODE) {
return null;
}
HeadRule hr;
//right
if (type.equals("NP") || type.equals("NX")) {
final String[] tags1 = { "NN", "NNP", "NNPS", "NNS", "NX", "JJR", "POS" };
for (int ci = constituents.length - 1; ci >= 0; ci--) {
for (int ti = tags1.length - 1; ti >= 0; ti--) {
if (constituents[ci].getType().equals(tags1[ti])) {
return constituents[ci];
}
}
}
//left
for (final Parse constituent : constituents) {
if (constituent.getType().equals("NP")) {
return constituent;
}
}
//right
final String[] tags2 = { "$", "ADJP", "PRN" };
for (int ci = constituents.length - 1; ci >= 0; ci--) {
for (int ti = tags2.length - 1; ti >= 0; ti--) {
if (constituents[ci].getType().equals(tags2[ti])) {
return constituents[ci];
}
}
}
//right
for (int ci = constituents.length - 1; ci >= 0; ci--) {
if (constituents[ci].getType().equals("CD")) {
return constituents[ci];
}
}
//right
final String[] tags3 = { "JJ", "JJS", "RB", "QP" };
for (int ci = constituents.length - 1; ci >= 0; ci--) {
for (int ti = tags3.length - 1; ti >= 0; ti--) {
if (constituents[ci].getType().equals(tags3[ti])) {
return constituents[ci];
}
}
}
//else return the last word
return constituents[constituents.length - 1];
} else if ((hr = this.headRules.get(type)) != null) {
final String[] tags = hr.tags;
final int cl = constituents.length;
final int tl = tags.length;
if (hr.leftToRight) {
for (int ti = 0; ti < tl; ti++) {
for (int ci = 0; ci < cl; ci++) {
if (constituents[ci].getType().equals(tags[ti])) {
return constituents[ci];
}
}
}
//else return the first constituent
return constituents[0];
} else {
//right
for (int ti = 0; ti < tl; ti++) {
for (int ci = cl - 1; ci >= 0; ci--) {
if (constituents[ci].getType().equals(tags[ti])) {
return constituents[ci];
}
}
}
//else return the last constituent
return constituents[cl - 1];
}
}
return constituents[constituents.length - 1];
}
开发者ID:ixa-ehu,项目名称:ixa-pipe-parse,代码行数:77,代码来源:EnglishHeadRules.java
注:本文中的opennlp.tools.parser.AbstractBottomUpParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论