• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SentenceIndexAnnotation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation的典型用法代码示例。如果您正苦于以下问题:Java SentenceIndexAnnotation类的具体用法?Java SentenceIndexAnnotation怎么用?Java SentenceIndexAnnotation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SentenceIndexAnnotation类属于edu.stanford.nlp.ling.CoreAnnotations包,在下文中一共展示了SentenceIndexAnnotation类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: TokenizedCoreLabelWrapper

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
/**
 *
 */
public TokenizedCoreLabelWrapper(final CoreLabel cl) {
  this.value = cl.get(ValueAnnotation.class);
  this.text = cl.get(TextAnnotation.class);
  LOGGER.trace("Wrapping token text: {}", this.text);
  this.originalText = cl.get(OriginalTextAnnotation.class);
  this.before = cl.get(BeforeAnnotation.class);
  this.after = cl.get(AfterAnnotation.class);

  this.startSentenceOffset = cl.get(CharacterOffsetBeginAnnotation.class);
  this.endSentenceOffset = cl.get(CharacterOffsetEndAnnotation.class);

  this.startOffset = Optional.ofNullable(cl.get(TokenBeginAnnotation.class));
  this.endOffset = Optional.ofNullable(cl.get(TokenEndAnnotation.class));
  LOGGER.trace("TokenBegin: {}", this.startOffset);
  LOGGER.trace("TokenEnd: {}", this.endOffset);

  this.idx = cl.get(IndexAnnotation.class);
  this.sentenceIdx = cl.get(SentenceIndexAnnotation.class);
  LOGGER.trace("Got sentence idx: {}", this.sentenceIdx);
}
 
开发者ID:hltcoe,项目名称:concrete-stanford-deprecated2,代码行数:24,代码来源:TokenizedCoreLabelWrapper.java


示例2: hashCode

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
/**
 * This hashcode uses only the docID, sentenceIndex, and index
 * See compareTo for more info
 */
@Override
public int hashCode() {
  boolean sensible = false;
  int result = 0;
  if (get(DocIDAnnotation.class) != null) {
    result = get(DocIDAnnotation.class).hashCode();
    sensible = true;
  }
  if (has(SentenceIndexAnnotation.class)) {
    result = 29 * result + get(SentenceIndexAnnotation.class);
    sensible = true;
  }
  if (has(IndexAnnotation.class)) {
    result = 29 * result + get(IndexAnnotation.class);
    sensible = true;
  }
  if ( ! sensible) {
    System.err.println("WARNING!!!  You have hashed an IndexedWord with no docID, sentIndex or wordIndex. You will almost certainly lose");
  }
  return result;
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:26,代码来源:IndexedWord.java


示例3: concreteSectionToCoreMapList

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
public static List<CoreMap> concreteSectionToCoreMapList(final Section sect, final String commText) {
  List<CoreMap> toRet = new ArrayList<>();
  List<Sentence> sentList = sect.getSentenceList();
  int tokOffset = 0;
  for (int i = 0; i < sentList.size(); i++) {
    Sentence st = sentList.get(i);
    CoreMap cm = new ArrayCoreMap();
    cm.set(SentenceIndexAnnotation.class, i);
    final TextSpan sts = st.getTextSpan();
    final int sentCharStart = sts.getStart();
    final int sentCharEnd = sts.getEnding();
    LOGGER.debug("Setting stanford sentence BeginChar = {}", sentCharStart);
    cm.set(CharacterOffsetBeginAnnotation.class, sentCharStart);
    LOGGER.debug("Setting stanford sentence EndChar = {}", sentCharEnd);
    cm.set(CharacterOffsetEndAnnotation.class, sentCharEnd);
    String sectText = commText.substring(sentCharStart, sentCharEnd);
    LOGGER.debug("Setting text: {}", sectText);
    cm.set(TextAnnotation.class, sectText);

    Tokenization tkz = st.getTokenization();
    List<CoreLabel> clList = tokenizationToCoreLabelList(tkz, i, sentCharStart);
    final int maxIdx = clList.size();
    LOGGER.debug("Setting stanford sentence token begin: {}", tokOffset);
    cm.set(TokenBeginAnnotation.class, tokOffset);
    final int tokEnd = tokOffset + maxIdx;
    LOGGER.debug("Setting stanford sentence token end: {}", tokEnd);
    cm.set(TokenEndAnnotation.class, tokEnd);
    cm.set(TokensAnnotation.class, clList);

    tokOffset = tokEnd;
    toRet.add(cm);
  }

  return toRet;
}
 
开发者ID:hltcoe,项目名称:concrete-stanford-deprecated2,代码行数:36,代码来源:ConcreteToStanfordMapper.java


示例4: CoreMapWrapper

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
/**
 *
 */
public CoreMapWrapper(final CoreMap cm, final AnalyticUUIDGenerator gen) {
  this.text = cm.get(TextAnnotation.class);
  this.idx = cm.get(SentenceIndexAnnotation.class);

  this.startOffset = cm.get(CharacterOffsetBeginAnnotation.class);
  this.endOffset = cm.get(CharacterOffsetEndAnnotation.class);

  this.tokenBeginOffset = cm.get(TokenBeginAnnotation.class);
  this.tokenEndOffset = cm.get(TokenEndAnnotation.class);
  this.clList = cm.get(TokensAnnotation.class);
  LOGGER.trace("CoreLabel list has {} elements.", clList.size());
  this.gen = gen;
}
 
开发者ID:hltcoe,项目名称:concrete-stanford-deprecated2,代码行数:17,代码来源:CoreMapWrapper.java


示例5: tagTokens

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
public List<String> tagTokens(String text) {

		List<String> tagged = new ArrayList<String>();

		Annotation document = runPipeline(text);

		// these are all the sentences in this document
		// a CoreMap is essentially a Map that uses class objects as keys
		// and has values with custom types
		List<CoreMap> sentences = document.get(SentencesAnnotation.class);

		for (CoreMap sentence : sentences) {
			// traversing the words in the current sentence
			// a CoreLabel is a CoreMap with additional token-specific methods
			for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
				// this is the text of the token
				String word = token.get(TextAnnotation.class);
				// this is the POS tag of the token
				String pos = token.get(PartOfSpeechAnnotation.class);
				// this is the NER label of the token
				String ne = token.get(NamedEntityTagAnnotation.class);
				// this is the lemma of the token
				String lemma = token.get(LemmaAnnotation.class);
				// this is the sentence index
				int sentId = token.get(SentenceIndexAnnotation.class);

				tagged.add(word + "/" + pos + "/" + ne + "/" + lemma + "/" + sentId);
			}

		}

		return tagged;
	}
 
开发者ID:sunil3590,项目名称:artificial-guy,代码行数:34,代码来源:NLP.java


示例6: sentIndex

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public int sentIndex() {
  Integer n = get(SentenceIndexAnnotation.class);
  if(n == null)
    return -1;
  return n;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:10,代码来源:CoreLabel.java


示例7: equals

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
/**
 * This .equals is dependent only on docID, sentenceIndex, and index.
 * It doesn't consider the actual word value, but assumes that it is
 * validly represented by token position.
 * All IndexedWords that lack these fields will be regarded as equal.
 */
@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (!(o instanceof IndexedWord)) return false;

  //now compare on appropriate keys
  final IndexedWord otherWord = (IndexedWord) o;
  String myDocID = getString(DocIDAnnotation.class);
  String otherDocID = otherWord.getString(DocIDAnnotation.class);
  if (myDocID == null) {
    if (otherDocID != null)
    return false;
  } else if ( ! myDocID.equals(otherDocID)) {
    return false;
  }
  Integer mySentInd = get(SentenceIndexAnnotation.class);
  Integer otherSentInd = otherWord.get(SentenceIndexAnnotation.class);
  if (mySentInd == null) {
    if (otherSentInd != null)
    return false;
  } else if ( ! mySentInd.equals(otherSentInd)) {
    return false;
  }
  Integer myInd = get(IndexAnnotation.class);
  Integer otherInd = otherWord.get(IndexAnnotation.class);
  if (myInd == null) {
    if (otherInd != null)
    return false;
  } else if ( ! myInd.equals(otherInd)) {
    return false;
  }
  return true;
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:40,代码来源:IndexedWord.java


示例8: addEntityMentions

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
	static void addEntityMentions(Map<String,Object> sent_info, CoreMap sentence) {
        List<CoreMap> coreMentions = sentence.get(MentionsAnnotation.class);
        List<Map> jsonMentions = new ArrayList<>();
        /* trying to figure out the keys in each mention. here's a printout from one.
MENTION August 2014
class edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation	August 2014
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetBeginAnnotation	3
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetEndAnnotation	14
class edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation	[August-2, 2014-3]
class edu.stanford.nlp.ling.CoreAnnotations$TokenBeginAnnotation	1
class edu.stanford.nlp.ling.CoreAnnotations$TokenEndAnnotation	3
class edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation	DATE
class edu.stanford.nlp.ling.CoreAnnotations$NormalizedNamedEntityTagAnnotation	2014-08
class edu.stanford.nlp.ling.CoreAnnotations$EntityTypeAnnotation	DATE
class edu.stanford.nlp.ling.CoreAnnotations$SentenceIndexAnnotation	0
class edu.stanford.nlp.time.TimeAnnotations$TimexAnnotation	<TIMEX3 tid="t1" type="DATE" value="2014-08">August 2014</TIMEX3>
MENTION Barack Obama
class edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation	Barack Obama
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetBeginAnnotation	17
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetEndAnnotation	29
class edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation	[Barack-5, Obama-6]
class edu.stanford.nlp.ling.CoreAnnotations$TokenBeginAnnotation	4
class edu.stanford.nlp.ling.CoreAnnotations$TokenEndAnnotation	6
class edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation	PERSON
class edu.stanford.nlp.ling.CoreAnnotations$EntityTypeAnnotation	PERSON
class edu.stanford.nlp.ling.CoreAnnotations$SentenceIndexAnnotation	0
MENTION Paris
class edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation	Paris
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetBeginAnnotation	66
class edu.stanford.nlp.ling.CoreAnnotations$CharacterOffsetEndAnnotation	71
class edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation	[Paris-5]
class edu.stanford.nlp.ling.CoreAnnotations$TokenBeginAnnotation	14
class edu.stanford.nlp.ling.CoreAnnotations$TokenEndAnnotation	15
class edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation	LOCATION
class edu.stanford.nlp.ling.CoreAnnotations$EntityTypeAnnotation	LOCATION
class edu.stanford.nlp.ling.CoreAnnotations$SentenceIndexAnnotation	1
         */
        for (CoreMap mention : coreMentions) {
//            U.p("MENTION " + mention);
//        	for (Class k : mention.keySet()) {
//        		U.pf("%s\t%s\n", k, mention.get(k));
//        	}
            Map m = new HashMap<String, Object>();
            m.put("tokspan", Lists.newArrayList(
            		mention.get(TokenBeginAnnotation.class).intValue(),
            		mention.get(TokenEndAnnotation.class).intValue()));
            m.put("charspan", Lists.newArrayList(
            		mention.get(CharacterOffsetBeginAnnotation.class).intValue(),
            		mention.get(CharacterOffsetEndAnnotation.class).intValue()));
            m.put("sentence", mention.get(SentenceIndexAnnotation.class).intValue());
            String entityType = mention.get(EntityTypeAnnotation.class);
            m.put("type", entityType);
            if (mention.containsKey(NormalizedNamedEntityTagAnnotation.class)) {
            	m.put("normalized", mention.get(NormalizedNamedEntityTagAnnotation.class));
            }
            if (mention.containsKey(TimexAnnotation.class)) {
            	m.put("timex_xml", mention.get(TimexAnnotation.class).toString());
            }
            jsonMentions.add(m);
        }
        sent_info.put("entitymentions", jsonMentions);
	}
 
开发者ID:UKPLab,项目名称:tac2015-event-detection,代码行数:64,代码来源:JsonPipeline.java


示例9: resolveCoRef

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
public String resolveCoRef(String text) {

		// to hold resolved string
		String resolved = new String();

		// run the pipeline
		Annotation document = runPipeline(text);

		// get all coref chains and sentences
		Map<Integer, CorefChain> corefs = document.get(CorefChainAnnotation.class);
		List<CoreMap> sentences = document.get(SentencesAnnotation.class);

		// process each sentence
		for (CoreMap sentence : sentences) {

			int curSentIdx = sentence.get(SentenceIndexAnnotation.class);
			List<CoreLabel> tokens = sentence.get(TokensAnnotation.class);

			boolean isPronoun = false;
			for (CoreLabel token : tokens) {

				// process only pronouns
				isPronoun = false;
				String pos = token.get(PartOfSpeechAnnotation.class);
				if (pos.equals("PRP") || pos.equals("PP$")) {
					isPronoun = true;
				}

				Integer corefClustId = token.get(CorefClusterIdAnnotation.class);
				CorefChain chain = corefs.get(corefClustId);

				// if there is no chain to replace
				if (chain == null || chain.getMentionsInTextualOrder().size() == 1 || isPronoun == false) {
					resolved += token.word() + token.after();
				} else {

					int sentIndx = chain.getRepresentativeMention().sentNum - 1;

					CorefMention reprMent = chain.getRepresentativeMention();
					String rootWord = sentences.get(sentIndx)
							.get(TokensAnnotation.class)
							.get(reprMent.headIndex - 1)
							.originalText();

					if (curSentIdx != sentIndx || token.index() < reprMent.startIndex
							|| token.index() > reprMent.endIndex) {
						if (Character.isUpperCase(token.originalText().charAt(0))) {
							rootWord = WordUtils.capitalize(rootWord);
						}
						resolved += rootWord + token.after();
					} else {
						resolved += token.word() + token.after();
					}
				}
			}
		}

		return resolved;
	}
 
开发者ID:sunil3590,项目名称:artificial-guy,代码行数:60,代码来源:NLP.java


示例10: setSentIndex

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public void setSentIndex(int sentIndex) {
  set(SentenceIndexAnnotation.class, sentIndex);
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:7,代码来源:CoreLabel.java


示例11: IndexedWord

import edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation; //导入依赖的package包/类
/**
 * Constructor for setting docID, sentenceIndex, and
 * index without any other annotations.
 *
 * @param docID The document ID (arbitrary string)
 * @param sentenceIndex The sentence number in the document (normally 0-based)
 * @param index The index of the word in the sentence (normally 0-based)
 */
public IndexedWord(String docID, int sentenceIndex, int index) {
  super();
  this.set(DocIDAnnotation.class, docID);
  this.set(SentenceIndexAnnotation.class, sentenceIndex);
  this.set(IndexAnnotation.class, index);
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:15,代码来源:IndexedWord.java



注:本文中的edu.stanford.nlp.ling.CoreAnnotations.SentenceIndexAnnotation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SecurityInfo类代码示例发布时间:2022-05-23
下一篇:
Java LoggingMessage类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap