当前位置: 首页>>代码示例>>Java>>正文


Java DEPTree类代码示例

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


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

示例1: createTreeFromTokens

import edu.emory.clir.clearnlp.dependency.DEPTree; //导入依赖的package包/类
/**
 * Creates the ClearNLP Deptree from word tokens for a sentence.
 *
 * @param tokens
 *            the tokens
 * @return the DEP tree
 */
private static DEPTree createTreeFromTokens(final List<WordToken> tokens) {
	// Generate DEPTree from WordTokens
	final DEPTree tree = new DEPTree(tokens.size());
	int tokenIndex = 0;
	for (final WordToken wt : tokens) {
		final DEPNode node = new DEPNode(tokenIndex++, wt.getCoveredText());
		node.setPOSTag(wt.getPartOfSpeech());
		final FSArray lemmas = wt.getLemmas();
		if (lemmas != null && lemmas.size() > 0) {
			final WordLemma wl = (WordLemma) lemmas.get(0);
			node.setLemma(wl.getLemmaForm());
		}
		tree.add(node);
	}
	return tree;
}
 
开发者ID:tenode,项目名称:baleen-extras,代码行数:24,代码来源:ClearNlpParser.java

示例2: process

import edu.emory.clir.clearnlp.dependency.DEPTree; //导入依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

  for (Annotation window : JCasUtil.select(jCas, this.windowClass)) {
    List<TOKEN_TYPE> tokens = this.tokenOps.selectTokens(jCas, window);
    if (tokens.size() <= 0) {
      return;
    }

    List<String> tokenStrings = JCasUtil.toText(tokens);

    // As of version 1.3.0, ClearNLP does all processing through its own dependency tree
    // structure
    DEPTree clearNlpDepTree = new DEPTree(tokenStrings);

    this.tagger.process(clearNlpDepTree);

    // Note the ClearNLP counts index 0 as the sentence dependency node, so the POS tag indices
    // are shifted by one from the token indices
    for (int i = 0; i < tokens.size(); i++) {
      TOKEN_TYPE token = tokens.get(i);
      DEPNode node = clearNlpDepTree.get(i+1);
      this.tokenOps.setPos(jCas, token, node.getPOSTag());
    }
  }
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:27,代码来源:PosTagger_ImplBase.java

示例3: process

import edu.emory.clir.clearnlp.dependency.DEPTree; //导入依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

  for (WINDOW_TYPE window : JCasUtil.select(jCas, this.windowClass)) {
    List<TOKEN_TYPE> tokens = this.tokenOps.selectTokens(jCas, window);

    // Extract data from CAS and stuff it into ClearNLP data structures
    DEPTree tree = new DEPTree(tokens.size());
    for (int i = 0; i < tokens.size(); i++) {
      TOKEN_TYPE token = tokens.get(i);
      String lemma = this.tokenOps.getLemma(jCas, token);
      String pos = this.tokenOps.getPos(jCas, token);
      DEPNode node = new DEPNode(i + 1, token.getCoveredText(), lemma, pos, new DEPFeat());
      tree.add(node);
    }

    // Run the parser
    this.parser.process(tree);

    // convert ClearNLP output back into CAS type system annotation
    this.addTreeToCas(jCas, tree, window, tokens);
  }
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:24,代码来源:DependencyParser_ImplBase.java

示例4: tagPartOfSpeech

import edu.emory.clir.clearnlp.dependency.DEPTree; //导入依赖的package包/类
@Override
public void tagPartOfSpeech(JCas jcas, List<Token> tokens) {
  List<String> tokenTexts = tokens.stream().map(Token::getCoveredText).collect(toList());
  DEPTree tree = new DEPTree(tokenTexts);
  tagger.process(tree);
  IntStream.range(0, tokens.size())
          .forEach(i -> tokens.get(i).setPartOfSpeech(tree.get(i + 1).getPOSTag()));
}
 
开发者ID:oaqa,项目名称:bioasq,代码行数:9,代码来源:ClearParserProvider.java

示例5: doProcess

import edu.emory.clir.clearnlp.dependency.DEPTree; //导入依赖的package包/类
@Override
protected void doProcess(final JCas jCas) throws AnalysisEngineProcessException {

	for (final Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
		final List<WordToken> tokens = JCasUtil.selectCovered(jCas, WordToken.class, sentence);

		final DEPTree tree = ClearNlpParser.createTreeFromTokens(tokens);

		// Perform parsing
		depParser.process(tree);

		// Convert tree back to our annotations
		for (int i = 0; i < tree.size(); i++) {
			final DEPNode node = tree.get(i);

			// Logic taken from DKPro Core (ASL)
			// https://github.com/dkpro/dkpro-core/blob/master/dkpro-core-clearnlp-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/clearnlp/ClearNlpParser.java
			if (node.hasHead()) {
				final Dependency dep = new Dependency(jCas);
				if (node.getHead().getID() != 0) {
					dep.setGovernor(tokens.get(node.getHead().getID()));
					dep.setDependencyType(node.getLabel());
				} else {
					dep.setGovernor(tokens.get(node.getID()));
					dep.setDependencyType("ROOT");
				}
				dep.setDependent(tokens.get(node.getID()));
				dep.setBegin(dep.getDependent().getBegin());
				dep.setEnd(dep.getDependent().getEnd());
				addToJCasIndex(dep);
			}
		}
	}
}
 
开发者ID:tenode,项目名称:baleen-extras,代码行数:35,代码来源:ClearNlpParser.java

示例6: doProcess

import edu.emory.clir.clearnlp.dependency.DEPTree; //导入依赖的package包/类
@Override
protected void doProcess(final JCas jCas) throws AnalysisEngineProcessException {
	final String text = jCas.getDocumentText();

	final InputStream stream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
	final List<List<String>> sentences = tokeniser.segmentize(stream);

	int sentenceStart = 0;

	for (final List<String> sentence : sentences) {

		final DEPTree tree = new DEPTree(sentence);

		posTagger.process(tree);
		mpAnalyser.process(tree);

		// This is a little painful. The DepNode's a just strings, so we need to find them in
		// the text so we get the offsets.
		int tokenStart = 0;
		int tokenEnd = sentenceStart;

		for (int i = 0; i < tree.size(); i++) {

			final String word = tree.get(i).getWordForm();
			final String lemma = tree.get(i).getLemma();
			final String pos = tree.get(i).getPOSTag();

			tokenStart = text.indexOf(word, tokenEnd);

			if (tokenStart >= 0) {
				// Add a word token if we have found our word
				tokenEnd = tokenStart + word.length();

				final WordToken wordToken = new WordToken(jCas);
				wordToken.setBegin(tokenStart);
				wordToken.setEnd(tokenEnd);
				wordToken.setPartOfSpeech(pos);

				final WordLemma wordLemma = new WordLemma(jCas);
				wordLemma.setBegin(tokenStart);
				wordLemma.setEnd(tokenEnd);
				wordLemma.setLemmaForm(lemma);

				final FSArray lemmaArray = new FSArray(jCas, 1);
				lemmaArray.set(0, wordLemma);
				wordToken.setLemmas(lemmaArray);

				addToJCasIndex(wordToken);
			} else if (word.equals(DEPLib.ROOT_TAG)) {
				// Ignore tags
			} else {
				getLogger().warn("Not found a tokenised word in document text: " + word);
			}

		}

		// Do we have a non-zero length sentence?
		// If so create a setence
		if (sentenceStart != tokenEnd) {
			final Sentence s = new Sentence(jCas);
			s.setBegin(sentenceStart);
			s.setEnd(tokenEnd);
			addToJCasIndex(s);
		}

		sentenceStart = tokenEnd;

	}
}
 
开发者ID:tenode,项目名称:baleen-extras,代码行数:70,代码来源:ClearNlpTokeniser.java

示例7: extractSRLInfo

import edu.emory.clir.clearnlp.dependency.DEPTree; //导入依赖的package包/类
/**
 * Converts the output from the ClearParser Semantic Role Labeler to the ClearTK Predicate and
 * SemanticArgument Types.
 * 
 * @param jCas
 * @param tokens
 *          - In order list of tokens
 * @param tree
 *          - DepdendencyTree output by ClearParser SRLPredict
 */
private void extractSRLInfo(JCas jCas, List<TOKEN_TYPE> tokens, DEPTree tree) {
  Map<Integer, PREDICATE_TYPE> headIdToPredicate = Maps.newHashMap();
  Map<PREDICATE_TYPE, List<ARGUMENT_TYPE>> predicateArguments = Maps.newHashMap();

  // Start at node 1, since node 0 is considered the head of the sentence
  for (int i = 1; i < tree.size(); i++) {
    // Every ClearParser parserNode will contain an srlInfo field.
    DEPNode parserNode = tree.get(i);
    TOKEN_TYPE token = tokens.get(i - 1);

    List<SRLArc> semanticHeads = parserNode.getSemanticHeadArcList();
    if (semanticHeads.isEmpty()) {
      continue;
    }

    // Parse semantic head relations to get SRL triplets
    for (SRLArc shead : semanticHeads) {
      int headId = shead.getNode().getID();
      TOKEN_TYPE headToken = tokens.get(headId - 1);
      PREDICATE_TYPE pred;
      List<ARGUMENT_TYPE> args;
      if (!headIdToPredicate.containsKey(headId)) {
        String rolesetId = shead.getNode().getFeat(DEPLib.FEAT_PB);
        pred = this.srlOps.createPredicate(jCas, headToken, rolesetId);
        headIdToPredicate.put(headId, pred);
        args = Lists.newArrayList();
        predicateArguments.put(pred, args);
      } else {
        pred = headIdToPredicate.get(headId);
        args = predicateArguments.get(pred);
      }
      args.add(this.srlOps.createArgument(jCas, token, shead.getLabel()));
    }
  }

  // Store Arguments in Predicate
  for (Map.Entry<PREDICATE_TYPE, List<ARGUMENT_TYPE>> entry : predicateArguments.entrySet()) {
    PREDICATE_TYPE predicate = entry.getKey();
    List<ARGUMENT_TYPE> arguments = entry.getValue();
    this.srlOps.setPredicateArguments(jCas, predicate, arguments);
  }

}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:54,代码来源:SemanticRoleLabeler_ImplBase.java


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