當前位置: 首頁>>代碼示例>>Java>>正文


Java HasWord.setWord方法代碼示例

本文整理匯總了Java中edu.stanford.nlp.ling.HasWord.setWord方法的典型用法代碼示例。如果您正苦於以下問題:Java HasWord.setWord方法的具體用法?Java HasWord.setWord怎麽用?Java HasWord.setWord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在edu.stanford.nlp.ling.HasWord的用法示例。


在下文中一共展示了HasWord.setWord方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: perClusterUpdateSen

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
public static void perClusterUpdateSen(ArrayList<List<HasWord>> processedText,
		int common_sentNum, int representative_sentNum,
	int coreStartIndex, int coreEndIndex,
	int commonStartIndex, int commonEndIndex){
	
	List<HasWord> representative_sentence = 
			processedText.get(representative_sentNum-1);
	List<HasWord> common_sentence = 
			processedText.get(common_sentNum-1);
	
	HasWord replace = new Word();
	String replaceStr = "";
	for (int i = coreStartIndex-1; i < coreEndIndex - 1; i++){
		replaceStr += representative_sentence.get(i).toString();
		replaceStr += " ";
	}
	replace.setWord(replaceStr.trim());
	for (int i=commonStartIndex-1; i < commonEndIndex-1; i++){
		common_sentence.set(i,new Word());
		common_sentence.get(i).setWord("");
	}
	common_sentence.set(commonStartIndex-1, replace);
	
}
 
開發者ID:cs-zyluo,項目名稱:CausalNet,代碼行數:25,代碼來源:Coreferencer.java

示例2: tag

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
public Sentence tag(Sentence sent) {
	List<HasWord> ss = new ArrayList<HasWord>();
	for (Token t : sent) {
		HasWord hw = new Word();
		hw.setWord(t.toString());
		ss.add(hw);
	} 
	List<TaggedWord> sst = tagger.tagSentence(ss);
	for (tuple2<Integer,TaggedWord> item : x.enumerate(sst)) {
		Token tk = sent.get(item.key);
		tk.annotate("pos", item.value.tag());
		sent.setAt(item.key).value(tk);
	}
	  
	return sent;
}
 
開發者ID:WantedTechnologies,項目名稱:xpresso,代碼行數:17,代碼來源:MaxentPosTagger.java

示例3: apply

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/** <i>Note:</i> At present this clobbers the input list items.
 *  This should be fixed.
 */
public List<HasWord> apply(List<HasWord> arg) {
  List<HasWord> ans = new ArrayList<HasWord>(arg);
  for (HasWord wd : ans) {
    String w = wd.word();
    Matcher m2 = p2.matcher(w);
    // System.err.println("Escaper: w is " + w);
    if (m2.find()) {
      // System.err.println("  Found pattern.");
      w = m2.replaceAll("$1");
      // System.err.println("  Changed it to: " + w);
    }
    String newW = StringUtils.tr(w,
                                 "!\"#$%&'()*+,-./0123456789:;<=>[email protected][\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
                                 "\uFF01\uFF02\uFF03\uFF04\uFF05\uFF06\uFF07\uFF08\uFF09\uFF0A\uFF0B\uFF0C\uFF0D\uFF0E\uFF0F\uFF10\uFF11\uFF12\uFF13\uFF14\uFF15\uFF16\uFF17\uFF18\uFF19\uFF1A\uFF1B\uFF1C\uFF1D\uFF1E\uFF1F\uFF20\uFF21\uFF22\uFF23\uFF24\uFF25\uFF26\uFF27\uFF28\uFF29\uFF2A\uFF2B\uFF2C\uFF2D\uFF2E\uFF2F\uFF30\uFF31\uFF32\uFF33\uFF34\uFF35\uFF36\uFF37\uFF38\uFF39\uFF3A\uFF3B\uFF3C\uFF3D\uFF3E\uFF3F\uFF40\uFF41\uFF42\uFF43\uFF44\uFF45\uFF46\uFF47\uFF48\uFF49\uFF4A\uFF4B\uFF4C\uFF4D\uFF4E\uFF4F\uFF50\uFF51\uFF52\uFF53\uFF54\uFF55\uFF56\uFF57\uFF58\uFF59\uFF5A\uFF5B\uFF5C\uFF5D\uFF5E");
    wd.setWord(newW);
  }
  return ans;
}
 
開發者ID:FabianFriedrich,項目名稱:Text2Process,代碼行數:22,代碼來源:ChineseEscaper.java

示例4: apply

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/** <i>Note:</i> At present this clobbers the input list items.
 *  This should be fixed.
 */
public List<HasWord> apply(List<HasWord> arg) {
  List<HasWord> ans = new ArrayList<HasWord>(arg);
  for (HasWord wd : ans) {
    String w = wd.word();
    Matcher m2 = p2.matcher(w);
    // System.err.println("Escaper: w is " + w);
    if (m2.find()) {
      // System.err.println("  Found pattern.");
      w = m2.replaceAll("$1");
      // System.err.println("  Changed it to: " + w);
    }
    String newW = UTF8EquivalenceFunction.replaceAscii(w);
    wd.setWord(newW);
  }
  return ans;
}
 
開發者ID:paulirwin,項目名稱:Stanford.NER.Net,代碼行數:20,代碼來源:ChineseEscaper.java

示例5: yield

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Gets the yield of the tree.  The <code>Label</code> of all leaf nodes
 * is returned
 * as a list ordered by the natural left to right order of the
 * leaves.  Null values, if any, are inserted into the list like any
 * other value.  This has been rewritten to thread, so only one List
 * is used.
 *
 * @param y The list in which the yield of the tree will be placed.
 *          Normally, this will be empty when the routine is called, but
 *          if not, the new yield is added to the end of the list.
 * @return a <code>List</code> of the data in the tree's leaves.
 */
@SuppressWarnings("unchecked")
public <T> List<T> yield(List<T> y) {
	if (isLeaf()) {
		if(label() instanceof HasWord) {
			HasWord hw = (HasWord) label();
			hw.setWord(label().value());
		}
		y.add((T) label());

  } else {
    Tree[] kids = children();
    for (int i = 0; i < kids.length; i++) {
      kids[i].yield(y);
    }
  }
  return y;
}
 
開發者ID:paulirwin,項目名稱:Stanford.NER.Net,代碼行數:31,代碼來源:Tree.java

示例6: restoreOriginalWords

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
private void restoreOriginalWords(List<? extends HasWord> sentence) {
  if (originalWords == null) {
    return;
  }
  if (sentence.size() != originalWords.size()) {
    return;
  }
  if (originalWords.size() != originalLemmas.size()) {
    throw new AssertionError("originalWords and originalLemmas of different sizes");
  }
  Iterator<String> wordsIterator = originalWords.iterator();
  Iterator<String> lemmasIterator = originalLemmas.iterator();
  for (HasWord word : sentence) {
    word.setWord(wordsIterator.next());
    String lemma = lemmasIterator.next();
    if ((word instanceof HasLemma) && (lemma != null)) {
      ((HasLemma) word).setLemma(lemma);
    }
  }
}
 
開發者ID:chbrown,項目名稱:stanford-parser,代碼行數:21,代碼來源:LexicalizedParserQuery.java

示例7: apply

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/** Converts an input list of {@link HasWord} in IBM Arabic to
 *  LDC ATBv3 representation. The method safely copies the input object
 *  prior to escaping.
 *
 *  @param sentence A collection of type {@link edu.stanford.nlp.ling.Word}
 *  @return A copy of the input with each word escaped.
 *  @throws RuntimeException If a word is mapped to null
 */
public List<HasWord> apply(List<HasWord> sentence) {
  List<HasWord> newSentence = new ArrayList<HasWord>(sentence);

  for (HasWord wd : newSentence)
    wd.setWord(apply(wd.word()));

  return newSentence;
}
 
開發者ID:FabianFriedrich,項目名稱:Text2Process,代碼行數:17,代碼來源:IBMArabicEscaper.java

示例8: apply

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Americanize the HasWord or String coming in.
 *
 * @param w A HasWord or String to covert to American if needed.
 * @return Either the input or an Americanized version of it.
 */
public HasWord apply(HasWord w) {
  String str = w.word();
  String outStr = americanize(str, capitalizeTimex);
  if (!outStr.equals(str)) {
    w.setWord(outStr);
  }
  return w;
}
 
開發者ID:FabianFriedrich,項目名稱:Text2Process,代碼行數:15,代碼來源:Americanize.java

示例9: apply

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Americanize the HasWord or String coming in.
 *
 * @param w A HasWord or String to covert to American if needed.
 * @return Either the input or an Americanized version of it.
 */
@Override
public HasWord apply(HasWord w) {
  String str = w.word();
  String outStr = americanize(str, capitalizeTimex);
  if (!outStr.equals(str)) {
    w.setWord(outStr);
  }
  return w;
}
 
開發者ID:paulirwin,項目名稱:Stanford.NER.Net,代碼行數:16,代碼來源:Americanize.java

示例10: percolateHeads

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Finds the heads of the tree.  This code assumes that the label
 * does store and return sensible values for the category, word, and tag.
 * It will be a no-op otherwise.  The tree is modified.  The routine
 * assumes the Tree has word leaves and tag preterminals, and copies
 * their category to word and tag respectively, if they have a null
 * value.
 *
 * @param hf The headfinding algorithm to use
 */
public void percolateHeads(HeadFinder hf) {
  Label cwt = label();
  if (isLeaf()) {
    if (cwt instanceof HasWord) {
      HasWord w = (HasWord) cwt;
      if (w.word() == null) {
        w.setWord(cwt.value());
      }
    }
  } else {
    Tree[] kids = children();
    for (int i = 0; i < kids.length; i++) {
      kids[i].percolateHeads(hf);
    }
    Tree head = hf.determineHead(this);
    if (head != null) {
      Label headCwt = head.label();
      String headTag = null;
      if (headCwt instanceof HasTag) {
        headTag = ((HasTag) headCwt).tag();
      }
      if (headTag == null && head.isLeaf()) {
        // below us is a leaf
        headTag = cwt.value();
      }
      String headWord = null;
      if (headCwt instanceof HasWord) {
        headWord = ((HasWord) headCwt).word();
      }
      if (headWord == null && head.isLeaf()) {
        // below us is a leaf
        // this might be useful despite case for leaf above in
        // case the leaf label type doesn't support word()
        headWord = headCwt.value();
      }
      if (cwt instanceof HasWord) {
        ((HasWord) cwt).setWord(headWord);
      }
      if (cwt instanceof HasTag) {
        ((HasTag) cwt).setTag(headTag);
      }
    } else {
      System.err.println("Head is null: " + this);
    }
  }
}
 
開發者ID:FabianFriedrich,項目名稱:Text2Process,代碼行數:57,代碼來源:Tree.java

示例11: getTreeFromInputStream

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
private Tree getTreeFromInputStream() throws NoSuchElementException {
  int wordIndex = 1;

  // FSA
  while (tokenizer.hasNext()) {
    String token = tokenizer.next();

    if (token.equals(leftParen)) {

      // cdm 20100225: This next line used to have "" instead of null, but the traditional and current tree normalizers depend on the label being null not "" when there is no label on a tree (like the outermost English PTB level)
      String label = (tokenizer.peek().equals(leftParen)) ? null : tokenizer.next();
      if (rightParen.equals(label)) {//Skip past empty trees
        continue;
      } else if (treeNormalizer != null) {
        label = treeNormalizer.normalizeNonterminal(label);
      }

      Tree newTree = treeFactory.newTreeNode(label, null); // dtrs are added below
      if(currentTree == null)
        stack.add(newTree);
      else {
        currentTree.addChild(newTree);
        stack.add(currentTree);
      }

      currentTree = newTree;

    } else if(token.equals(rightParen)) {
      if (stack.isEmpty()) {
        // Warn that file has too many right parens
        System.err.println("PennTreeReader: warning: file has extra non-matching right parenthesis [ignored]");
        break;
      }

      //Accept
      currentTree = stack.remove(stack.size() - 1);  // i.e., stack.pop()
      if (stack.isEmpty()) return currentTree;

    } else {

      if (currentTree == null) {
        // A careful Reader should warn here, but it's kind of useful to
        // suppress this because then the TreeReader doesn't print a ton of
        // messages if there is a README file in a directory of Trees.
        // System.err.println("PennTreeReader: warning: file has extra token not in a s-expression tree: " + token + " [ignored]");
        break;
      }

      String terminal = (treeNormalizer == null) ? token : treeNormalizer.normalizeTerminal(token);
      Tree leaf = treeFactory.newLeaf(terminal);
      if(leaf.label() instanceof HasIndex) {
        HasIndex hi = (HasIndex) leaf.label();
        hi.setIndex(wordIndex);
      }
      if(leaf.label() instanceof HasWord) {
        HasWord hw = (HasWord) leaf.label();
        hw.setWord(leaf.label().value());
      }
      wordIndex++;

      currentTree.addChild(leaf);
      // cdm: Note: this implementation just isn't as efficient as the old recursive descent parser (see 2008 code), where all the daughters are gathered before the tree is made....
    }
  }

  //Reject
  if (currentTree != null) {
    System.err.println("PennTreeReader: warning: incomplete tree (extra left parentheses in input): " + currentTree);
  }
  return null;
}
 
開發者ID:paulirwin,項目名稱:Stanford.NER.Net,代碼行數:72,代碼來源:PennTreeReader.java

示例12: percolateHeads

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Finds the heads of the tree.  This code assumes that the label
 * does store and return sensible values for the category, word, and tag.
 * It will be a no-op otherwise.  The tree is modified.  The routine
 * assumes the Tree has word leaves and tag preterminals, and copies
 * their category to word and tag respectively, if they have a null
 * value.
 *
 * @param hf The headfinding algorithm to use
 */
public void percolateHeads(HeadFinder hf) {
  Label nodeLabel = label();
  if (isLeaf()) {
    // Sanity check: word() is usually set by the TreeReader.
    if (nodeLabel instanceof HasWord) {
      HasWord w = (HasWord) nodeLabel;
      if (w.word() == null) {
        w.setWord(nodeLabel.value());
      }
    }

  } else {
    for (Tree kid : children()) {
      kid.percolateHeads(hf);
    }

    final Tree head = hf.determineHead(this);
    if (head != null) {
      final Label headLabel = head.label();

      // Set the head tag.
      String headTag = (headLabel instanceof HasTag) ? ((HasTag) headLabel).tag() : null;
      if (headTag == null && head.isLeaf()) {
        // below us is a leaf
        headTag = nodeLabel.value();
      }

      // Set the head word
      String headWord = (headLabel instanceof HasWord) ? ((HasWord) headLabel).word() : null;
      if (headWord == null && head.isLeaf()) {
        // below us is a leaf
        // this might be useful despite case for leaf above in
        // case the leaf label type doesn't support word()
        headWord = headLabel.value();
      }

      // Set the head index
      int headIndex = (headLabel instanceof HasIndex) ? ((HasIndex) headLabel).index() : -1;

      if (nodeLabel instanceof HasWord) {
        ((HasWord) nodeLabel).setWord(headWord);
      }
      if (nodeLabel instanceof HasTag) {
        ((HasTag) nodeLabel).setTag(headTag);
      }
      if (nodeLabel instanceof HasIndex && headIndex >= 0) {
        ((HasIndex) nodeLabel).setIndex(headIndex);
      }

    } else {
      System.err.println("Head is null: " + this);
    }
  }
}
 
開發者ID:paulirwin,項目名稱:Stanford.NER.Net,代碼行數:65,代碼來源:Tree.java

示例13: primeNext

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
private void primeNext() {
  nextSent = new ArrayList<HasWord>(nextSentCarryover);
  nextSentCarryover.clear();
  boolean seenBoundary = false;

  while (tokenizer.hasNext()) {

    HasWord token = tokenizer.next();
    if (splitTag != null) {
      String[] toks = splitTag.apply(token.word());
      token.setWord(toks[0]);
      if (token instanceof Label) {
        ((Label) token).setValue(toks[0]);
      }
      if(toks.length == 2 && token instanceof HasTag) {
        //wsg2011: Some of the underlying tokenizers return old
        //JavaNLP labels.  We could convert to CoreLabel here, but
        //we choose a conservative implementation....
        ((HasTag) token).setTag(toks[1]);
      }
    }

    if (sentDelims.contains(token.word())) {
      seenBoundary = true;
    } else if (seenBoundary && !delimFollowers.contains(token.word())) {
      nextSentCarryover.add(token);
      break;
    }

    if ( ! (token.word().matches("\\s+") ||
            token.word().equals(PTBLexer.NEWLINE_TOKEN))) {
      nextSent.add(token);
    }

    // If there are no words that can follow a sentence delimiter,
    // then there are two cases.  In one case is we already have a
    // sentence, in which case there is no reason to look at the
    // next token, since that just causes buffering without any
    // chance of the current sentence being extended, since
    // delimFollowers = {}.  In the other case, we have an empty
    // sentence, which at this point means the sentence delimiter
    // was a whitespace token such as \n.  We might as well keep
    // going as if we had never seen anything.
    if (seenBoundary && delimFollowers.size() == 0) {
      if (nextSent.size() > 0) {
        break;
      } else {
        seenBoundary = false;
      }
    }
  }

  if (nextSent.size() == 0 && nextSentCarryover.size() == 0) {
    IOUtils.closeIgnoringExceptions(inputReader);
    inputReader = null;
    nextSent = null;
  } else if (escaper != null) {
    nextSent = escaper.apply(nextSent);
  }
}
 
開發者ID:amark-india,項目名稱:eventspotter,代碼行數:61,代碼來源:DocumentPreprocessor.java

示例14: percolateHeads

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Finds the heads of the tree.  This code assumes that the label
 * does store and return sensible values for the category, word, and tag.
 * It will be a no-op otherwise.  The tree is modified.  The routine
 * assumes the Tree has word leaves and tag preterminals, and copies
 * their category to word and tag respectively, if they have a null
 * value.
 *
 * @param hf The headfinding algorithm to use
 */
public void percolateHeads(HeadFinder hf) {
  Label nodeLabel = label();
  if (isLeaf()) {
    // Sanity check: word() is usually set by the TreeReader.
    if (nodeLabel instanceof HasWord) {
      HasWord w = (HasWord) nodeLabel;
      if (w.word() == null) {
        w.setWord(nodeLabel.value());
      }
    }

  } else {
    Tree[] kids = children();
    for (int i = 0; i < kids.length; i++) {
      kids[i].percolateHeads(hf);
    }

    final Tree head = hf.determineHead(this);
    if (head != null) {
      final Label headLabel = head.label();

      // Set the head tag.
      String headTag = (headLabel instanceof HasTag) ? ((HasTag) headLabel).tag() : null;
      if (headTag == null && head.isLeaf()) {
        // below us is a leaf
        headTag = nodeLabel.value();
      }

      // Set the head word
      String headWord = (headLabel instanceof HasWord) ? ((HasWord) headLabel).word() : null;
      if (headWord == null && head.isLeaf()) {
        // below us is a leaf
        // this might be useful despite case for leaf above in
        // case the leaf label type doesn't support word()
        headWord = headLabel.value();
      }

      // Set the head index
      int headIndex = (headLabel instanceof HasIndex) ? ((HasIndex) headLabel).index() : -1;

      if (nodeLabel instanceof HasWord) {
        ((HasWord) nodeLabel).setWord(headWord);
      }
      if (nodeLabel instanceof HasTag) {
        ((HasTag) nodeLabel).setTag(headTag);
      }
      if (nodeLabel instanceof HasIndex && headIndex >= 0) {
        ((HasIndex) nodeLabel).setIndex(headIndex);
      }

    } else {
      System.err.println("Head is null: " + this);
    }
  }
}
 
開發者ID:amark-india,項目名稱:eventspotter,代碼行數:66,代碼來源:Tree.java

示例15: primeNext

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
private void primeNext() {
  nextSent = new ArrayList<HasWord>(nextSentCarryover);
  nextSentCarryover.clear();
  boolean seenBoundary = false;

  while (tokenizer.hasNext()) {

    HasWord token = tokenizer.next();
    if (splitTag != null) {
      String[] toks = splitTag.apply(token.word());
      token.setWord(toks[0]);
      if (token instanceof Label) {
        ((Label) token).setValue(toks[0]);
      }
      if(toks.length == 2 && token instanceof HasTag) {
        //wsg2011: Some of the underlying tokenizers return old
        //JavaNLP labels.  We could convert to CoreLabel here, but
        //we choose a conservative implementation....
        ((HasTag) token).setTag(toks[1]);
      }
    }

    if (sentDelims.contains(token.word())) {
      seenBoundary = true;
    } else if (seenBoundary && !delimFollowers.contains(token.word())) {
      nextSentCarryover.add(token);
      break;
    }

    if ( ! (wsPattern.matcher(token.word()).matches() ||
            token.word().equals(PTBLexer.NEWLINE_TOKEN))) {
      nextSent.add(token);
    }

    // If there are no words that can follow a sentence delimiter,
    // then there are two cases.  In one case is we already have a
    // sentence, in which case there is no reason to look at the
    // next token, since that just causes buffering without any
    // chance of the current sentence being extended, since
    // delimFollowers = {}.  In the other case, we have an empty
    // sentence, which at this point means the sentence delimiter
    // was a whitespace token such as \n.  We might as well keep
    // going as if we had never seen anything.
    if (seenBoundary && delimFollowers.size() == 0) {
      if (nextSent.size() > 0) {
        break;
      } else {
        seenBoundary = false;
      }
    }
  }

  if (nextSent.size() == 0 && nextSentCarryover.size() == 0) {
    IOUtils.closeIgnoringExceptions(inputReader);
    inputReader = null;
    nextSent = null;
  } else if (escaper != null) {
    nextSent = escaper.apply(nextSent);
  }
}
 
開發者ID:jaimeguzman,項目名稱:data_mining,代碼行數:61,代碼來源:DocumentPreprocessor.java


注:本文中的edu.stanford.nlp.ling.HasWord.setWord方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。