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


Java HasWord.word方法代碼示例

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


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

示例1: 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

示例2: 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:benblamey,項目名稱:stanford-nlp,代碼行數:20,代碼來源:ChineseEscaper.java

示例3: glueSentence

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/** Turn a List of HasWord into a String, by putting a space in between
 *  each word() value.
 *
 * @param sentence The List of HasWord
 * @return The sentence with tokens space separated.
 */
private static String glueSentence(List<HasWord> sentence) {
  StringBuilder result = new StringBuilder();
  if ( ! sentence.isEmpty()) {
    HasWord word = sentence.get(0);
    String s = word.word();
    result.append(s);
    for (int i = 1, sz = sentence.size(); i < sz; i++) {
      word = sentence.get(i);
      s = word.word();
      result.append(" ").append(s);
    }
  }
  return result.toString();
}
 
開發者ID:FabianFriedrich,項目名稱:Text2Process,代碼行數:21,代碼來源:DocumentPreprocessor.java

示例4: 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

示例5: printSamples

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
public void printSamples(List samples, PrintStream out) {
  for (int i = 0; i < document.size(); i++) {
    HasWord word = (HasWord) document.get(i);
    String s = "null";
    if (word!=null) {
      s = word.word();
    }
    out.print(StringUtils.padOrTrim(s, 10));
    for (int j = 0; j < samples.size(); j++) {
      int[] sequence = (int[]) samples.get(j);
      out.print(" " + StringUtils.padLeft(sequence[i], 2));
    }
    out.println();
  }
}
 
開發者ID:paulirwin,項目名稱:Stanford.NER.Net,代碼行數:16,代碼來源:SequenceGibbsSampler.java

示例6: 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

示例7: parse

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Parses the list of HasWord.  If the parse fails for some reason,
 * an X tree is returned instead of barfing.
 */
public Tree parse(List<? extends HasWord> lst) {
  try {
    ParserQuery pq = parserQuery();
    if (pq.parse(lst)) {
      Tree bestparse = pq.getBestParse();
      // -10000 denotes unknown words
      bestparse.setScore(pq.getPCFGScore() % -10000.0);
      return bestparse;
    }
  } catch (Exception e) {
    System.err.println("Following exception caught during parsing:");
    e.printStackTrace();
    System.err.println("Recovering using fall through strategy: will construct an (X ...) tree.");
  }
  // if can't parse or exception, fall through
  // TODO: merge with ParserAnnotatorUtils
  TreeFactory lstf = new LabeledScoredTreeFactory();
  List<Tree> lst2 = new ArrayList<Tree>();
  for (HasWord obj : lst) {
    String s = obj.word();
    Tree t = lstf.newLeaf(s);
    Tree t2 = lstf.newTreeNode("X", Collections.singletonList(t));
    lst2.add(t2);
  }
  return lstf.newTreeNode("X", lst2);
}
 
開發者ID:benblamey,項目名稱:stanford-nlp,代碼行數:31,代碼來源:LexicalizedParser.java

示例8: xTree

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Construct a fall through tree in case we can't parse this sentence
 * @param words
 * @return a tree with X for all the internal nodes
 */
public static Tree xTree(List<? extends HasWord> words) {
  TreeFactory lstf = new LabeledScoredTreeFactory();
  List<Tree> lst2 = new ArrayList<Tree>();
  for (HasWord obj : words) {
    String s = obj.word();
    Tree t = lstf.newLeaf(s);
    Tree t2 = lstf.newTreeNode("X", Collections.singletonList(t));
    lst2.add(t2);
  }
  return lstf.newTreeNode("X", lst2);
}
 
開發者ID:benblamey,項目名稱:stanford-nlp,代碼行數:17,代碼來源:ParserAnnotatorUtils.java

示例9: apply

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Converts a Sentence/List/String into a Tree.  If it can't be parsed,
 * it is made into a trivial tree in which each word is attached to a
 * dummy tag ("X") and then to a start nonterminal (also "X").  In all
 * circumstances, the input will be treated as a single sentence to be
 * parsed.
 *
 * @param in The input Sentence/List/String
 * @return A Tree that is the parse tree for the sentence.  If the parser
 *         fails, a new Tree is synthesized which attaches all words to the
 *         root.
 * @throws IllegalArgumentException If argument isn't a List or String
 */
@Override
public Tree apply(Object in) {
  List<? extends HasWord> lst;
  if (in instanceof String) {
    TokenizerFactory<? extends HasWord> tf = op.tlpParams.treebankLanguagePack().getTokenizerFactory();
    Tokenizer<? extends HasWord> tokenizer = tf.getTokenizer(new BufferedReader(new StringReader((String) in)));
    lst = tokenizer.tokenize();
  } else if (in instanceof List) {
    lst = ErasureUtils.<List<? extends HasWord>>uncheckedCast(in);
  } else {
    throw new IllegalArgumentException("Can only parse Sentence/List/String");
  }

  try {
    LexicalizedParserQuery pq = new LexicalizedParserQuery(this);
    if (pq.parse(lst)) {
      Tree bestparse = pq.getBestParse();
      // -10000 denotes unknown words
      bestparse.setScore(pq.getPCFGScore() % -10000.0);
      return bestparse;
    }
  } catch (Exception e) {
    System.err.println("Following exception caught during parsing:");
    e.printStackTrace();
    System.err.println("Recovering using fall through strategy: will construct an (X ...) tree.");
  }
  // if can't parse or exception, fall through
  // TODO: merge with ParserAnnotatorUtils
  TreeFactory lstf = new LabeledScoredTreeFactory();
  List<Tree> lst2 = new ArrayList<Tree>();
  for (HasWord obj : lst) {
    String s = obj.word();
    Tree t = lstf.newLeaf(s);
    Tree t2 = lstf.newTreeNode("X", Collections.singletonList(t));
    lst2.add(t2);
  }
  return lstf.newTreeNode("X", lst2);
}
 
開發者ID:amark-india,項目名稱:eventspotter,代碼行數:52,代碼來源:LexicalizedParser.java

示例10: apply

import edu.stanford.nlp.ling.HasWord; //導入方法依賴的package包/類
/**
 * Converts a Sentence/List/String into a Tree.  If it can't be parsed,
 * it is made into a trivial tree in which each word is attached to a
 * dummy tag ("X") and then to a start nonterminal (also "X").  In all
 * circumstances, the input will be treated as a single sentence to be
 * parsed.
 *
 * @param in The input Sentence/List/String
 * @return A Tree that is the parse tree for the sentence.  If the parser
 *         fails, a new Tree is synthesized which attaches all words to the
 *         root.
 * @throws IllegalArgumentException If argument isn't a List or String
 */
@Override
public Tree apply(Object in) {
  List<? extends HasWord> lst;
  if (in instanceof String) {
    TokenizerFactory<? extends HasWord> tf = op.tlpParams.treebankLanguagePack().getTokenizerFactory();
    Tokenizer<? extends HasWord> tokenizer = tf.getTokenizer(new BufferedReader(new StringReader((String) in)));
    lst = tokenizer.tokenize();
  } else if (in instanceof List) {
    lst = ErasureUtils.<List<? extends HasWord>>uncheckedCast(in);
  } else {
    throw new IllegalArgumentException("Can only parse Sentence/List/String");
  }

  try {
    LexicalizedParserQuery pq = new LexicalizedParserQuery(this);
    if (pq.parse(lst)) {
      Tree bestparse = pq.getBestParse();
      // -10000 denotes unknown words
      bestparse.setScore(pq.getPCFGScore() % -10000.0);
      return bestparse;
    }
  } catch (Exception e) {
    logger.trace("Following exception caught during parsing:");
    e.printStackTrace();
    logger.trace("Recovering using fall through strategy: will construct an (X ...) tree.");
  }
  // if can't parse or exception, fall through
  // TODO: merge with ParserAnnotatorUtils
  TreeFactory lstf = new LabeledScoredTreeFactory();
  List<Tree> lst2 = new ArrayList<Tree>();
  for (HasWord obj : lst) {
    String s = obj.word();
    Tree t = lstf.newLeaf(s);
    Tree t2 = lstf.newTreeNode("X", Collections.singletonList(t));
    lst2.add(t2);
  }
  return lstf.newTreeNode("X", lst2);
}
 
開發者ID:chbrown,項目名稱:stanford-parser,代碼行數:52,代碼來源:LexicalizedParser.java

示例11: 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

示例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: 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:chbrown,項目名稱:stanford-parser,代碼行數:66,代碼來源:Tree.java


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