gpt4 book ai didi

edu.illinois.cs.cogcomp.lbjava.nlp.Word类的使用及代码示例

转载 作者:知者 更新时间:2024-03-25 05:31:05 28 4
gpt4 key购买 nike

本文整理了Java中edu.illinois.cs.cogcomp.lbjava.nlp.Word类的一些代码示例,展示了Word类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Word类的具体详情如下:
包路径:edu.illinois.cs.cogcomp.lbjava.nlp.Word
类名称:Word

Word介绍

[英]Implementation of a word for natural language processing. Please note that in general, one can only count on the form and capitalized fields described below having meaningful values. The form field can be assumed to be filled in because it's hard to imagine a situation in which a Word object should be created without any knowledge of how that word appeared in text. The capitalized field is computed from the form by this class' constructor.

All other fields must be obtained or computed externally. Space is provided for them in this class' implementation as a convenience, since we expect the user will make frequent use of these fields.

This class extends from edu.illinois.cs.cogcomp.lbjava.parse.LinkedChild. Of course, this means that objects of this class contain references to both the previous and the next word in the sentence. Constructors are available that take the previous word as an argument, setting that reference. Thus, a useful technique for constructing all the words in a sentence will involve code that looks like this (where form is a String):

Word current = new Word(form); a loop of some sort {     current.next = new Word(form, current);     current = current.next; }
[中]自然语言处理的一个单词的实现。请注意,一般情况下,只能指望下面描述的formcapitalized字段具有有意义的值。form字段可以假定为已填充,因为很难想象在不知道该单词在文本中的显示方式的情况下创建Word对象。capitalized字段由此类的构造函数根据form计算得出。
所有其他字段必须从外部获取或计算。为了方便起见,在这个类的实现中为它们提供了空间,因为我们希望用户经常使用这些字段。
这门课是从edu扩展而来的。伊利诺伊州反恐精英。cogcomp。lbjava。作语法分析LinkedChild。当然,这意味着这个类的对象包含对句子中上一个单词和下一个单词的引用。可以使用构造函数将前一个单词作为参数,设置引用。因此,构建句子中所有单词的有用技术将涉及如下代码(其中form是一个字符串):
Word current = new Word(form); a loop of some sort {     current.next = new Word(form, current);     current = current.next; }

代码示例

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * Add the provided token to the sentence, for also do any additional word spliting.
 *
 * @param sentence the sentence to add the word to.
 * @param token the individual token.
 * @param tag the tag to annotate the word with.
 */
public static void addTokenToSentence(LinkedVector sentence, String token, String tag, ParametersForLbjCode prs) {
  NEWord word = new NEWord(new Word(token), null, tag);
  word.params = prs;
  addTokenToSentence(sentence, word);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-ner

/**
 * Add the provided token to the sentence, for also do any additional word spliting.
 *
 * @param sentence the sentence to add the word to.
 * @param token the individual token.
 * @param tag the tag to annotate the word with.
 */
public static void addTokenToSentence(LinkedVector sentence, String token, String tag, ParametersForLbjCode prs) {
  NEWord word = new NEWord(new Word(token), null, tag);
  word.params = prs;
  addTokenToSentence(sentence, word);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-mlner

/**
 * Add the provided token to the sentence, for also do any additional word spliting.
 *
 * @param sentence the sentence to add the word to.
 * @param token the individual token.
 * @param tag the tag to annotate the word with.
 */
public static void addTokenToSentence(LinkedVector sentence, String token, String tag) {
  NEWord word = new NEWord(new Word(token), null, tag);
  addTokenToSentence(sentence, word);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-standalone-nlp-pipeline

public IllinoisPOSHandler() 
{
  super("Illinois Part-Of-Speech Tagger", "0.2", "illinoispos");
  logger.info("Loading POS model..");
  tagger.discreteValue(new Token(new Word("The"), null, ""));
  logger.info("POS Tagger ready");
  tokensfield = CuratorViewNames.tokens;
  sentencesfield = CuratorViewNames.sentences;
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
   * Given textual input in the format shown below, this method parses and
   * returns the <code>Word</code> that the text represents.  Expected
   * format: <br><br>
   * <p/>
   * <code>(pos spelling)</code>
   *
   * @param text     Text representing a word in POS bracket form.
   * @param previous The word that came before this word in the sentence.
   * @return A <code>Word</code> represented by the input text or
   * <code>null</code> if the input does not represent a
   * <code>Word</code>.
   **/
  public static Word parsePOSBracketForm(String text, Word previous) {
    if (text.charAt(0) != '(' || text.charAt(text.length() - 1) != ')')
      return null;
    String[] tokens = text.split(" ");
    if (tokens.length != 2) return null;
    return new Word(tokens[1].substring(0, tokens[1].length() - 1),
        tokens[0].substring(1),
        previous);
  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * Given an array of <code>String</code>s, this method creates a new
 * {@link LinkedVector} containing {@link Word}s.
 *
 * @param a An array of <code>String</code>s.
 * @return A {@link LinkedVector} of {@link Word}s corresponding to the
 * input <code>String</code>s.
 **/
public static LinkedVector convert(String[] a) {
  if (a == null) return null;
  if (a.length == 0) return new LinkedVector();
  Word w = new Word(a[0]);
  for (int i = 1; i < a.length; ++i) {
    w.next = new Word(a[i], null, w);
    w = (Word) w.next;
  }
  return new LinkedVector(w);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava-NLP-tools

/**
 * Given an array of <code>String</code>s, this method creates a new
 * {@link LinkedVector} containing {@link Word}s.
 *
 * @param a An array of <code>String</code>s.
 * @return A {@link LinkedVector} of {@link Word}s corresponding to the
 * input <code>String</code>s.
 **/
public static LinkedVector convert(String[] a) {
  if (a == null) return null;
  if (a.length == 0) return new LinkedVector();
  Word w = new Word(a[0]);
  for (int i = 1; i < a.length; ++i) {
    w.next = new Word(a[i], null, w);
    w = (Word) w.next;
  }
  return new LinkedVector(w);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava-NLP-tools

/**
   * Given textual input in the format shown below, this method parses and
   * returns the <code>Word</code> that the text represents.  Expected
   * format: <br><br>
   * <p/>
   * <code>(pos spelling)</code>
   *
   * @param text     Text representing a word in POS bracket form.
   * @param previous The word that came before this word in the sentence.
   * @return A <code>Word</code> represented by the input text or
   * <code>null</code> if the input does not represent a
   * <code>Word</code>.
   **/
  public static Word parsePOSBracketForm(String text, Word previous) {
    if (text.charAt(0) != '(' || text.charAt(text.length() - 1) != ')')
      return null;
    String[] tokens = text.split(" ");
    if (tokens.length != 2) return null;
    return new Word(tokens[1].substring(0, tokens[1].length() - 1),
        tokens[0].substring(1),
        previous);
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-standalone-nlp-pipeline

public IllinoisChunkerHandler(String configFilename) {
  super("Illinois Chunker", "0.3", "illinoischunker");
  logger.info("Loading Chunker model..");
  tagger.discreteValue(new Token(new Word("The"), null, ""));
  logger.info("Chunker ready");
  // XXX If no configuration file is give use the default values from CuratorViewNames
  if (configFilename.trim().equals("")) {
    tokensfield = CuratorViewNames.tokens;
    sentencesfield = CuratorViewNames.sentences;
    posfield = CuratorViewNames.pos;
  }
  else {
    Properties config = new Properties();
    try {
      FileInputStream in = new FileInputStream(configFilename);
      config.load(new BufferedInputStream(in));
      in.close();
    } catch (IOException e) {
      logger.warn("Error reading configuration file. {}", configFilename);
    }
    tokensfield = config.getProperty("tokens.field", CuratorViewNames.tokens );
    sentencesfield = config.getProperty("sentences.field", CuratorViewNames.sentences );
    posfield = config.getProperty("pos.field", CuratorViewNames.pos );
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava-NLP-tools

Word w = new Word(tokens[1].substring(0, tokens[1].length() - 1),
    tokens[0].substring(1),
    0,
      new Word(tokens[i + 1].substring(0, tokens[i + 1].length() - 1),
          tokens[i].substring(1),
          w,

代码示例来源:origin: CogComp/cogcomp-nlp

Word w = new Word(tokens[1].substring(0, tokens[1].length() - 1),
    tokens[0].substring(1),
    0,
      new Word(tokens[i + 1].substring(0, tokens[i + 1].length() - 1),
          tokens[i].substring(1),
          w,

代码示例来源:origin: CogComp/cogcomp-nlp

/**
   * Produces the next object parsed from the input file; in this case, that object is guaranteed
   * to be a <code>LinkedVector</code> populated by <code>Token</code>s representing a sentence.
   **/
  public Object next() {
    String[] line = (String[]) super.next();
    while (line != null && (line.length < 2 || line[4].equals("-X-")))
      line = (String[]) super.next();
    if (line == null)
      return null;

    if (line[3].charAt(0) == 'I')
      line[3] = "B" + line[3].substring(1);
    Token t = new Token(new Word(line[5], line[4]), null, line[3]);
    String previous = line[3];

    for (line = (String[]) super.next(); line != null && line.length > 0; line =
        (String[]) super.next()) {
      if (line[3].charAt(0) == 'I' && !previous.endsWith(line[3].substring(2)))
        line[3] = "B" + line[3].substring(1);
      t.next = new Token(new Word(line[5], line[4]), t, line[3]);
      t = (Token) t.next;
      previous = line[3];
    }

    return new LinkedVector(t);
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-chunker

/**
   * Produces the next object parsed from the input file; in this case, that object is guaranteed
   * to be a <code>LinkedVector</code> populated by <code>Token</code>s representing a sentence.
   **/
  public Object next() {
    String[] line = (String[]) super.next();
    while (line != null && (line.length < 2 || line[4].equals("-X-")))
      line = (String[]) super.next();
    if (line == null)
      return null;

    if (line[3].charAt(0) == 'I')
      line[3] = "B" + line[3].substring(1);
    Token t = new Token(new Word(line[5], line[4]), null, line[3]);
    String previous = line[3];

    for (line = (String[]) super.next(); line != null && line.length > 0; line =
        (String[]) super.next()) {
      if (line[3].charAt(0) == 'I' && !previous.endsWith(line[3].substring(2)))
        line[3] = "B" + line[3].substring(1);
      t.next = new Token(new Word(line[5], line[4]), t, line[3]);
      t = (Token) t.next;
      previous = line[3];
    }

    return new LinkedVector(t);
  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
   * Produces the next object parsed from the input file; in this case, that object is guaranteed
   * to be a <code>LinkedVector</code> populated by <code>Token</code>s representing a sentence.
   **/
  public Object next() {
    String[] line = (String[]) super.next();
    while (line != null && line.length == 0)
      line = (String[]) super.next();
    if (line == null)
      return null;

    String pos = line[1];
    if (pos.equals("-"))
      pos = null;
    Token t = new Token(new Word(line[0], pos), null, line[2]);

    for (line = (String[]) super.next(); line != null && line.length > 0; line =
        (String[]) super.next()) {
      pos = line[1];
      if (pos.equals("-"))
        pos = null;
      t.next = new Token(new Word(line[0], pos), t, line[2]);
      t = (Token) t.next;
    }

    return new LinkedVector(t);
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-chunker

/**
   * Produces the next object parsed from the input file; in this case, that object is guaranteed
   * to be a <code>LinkedVector</code> populated by <code>Token</code>s representing a sentence.
   **/
  public Object next() {
    String[] line = (String[]) super.next();
    while (line != null && line.length == 0)
      line = (String[]) super.next();
    if (line == null)
      return null;

    String pos = line[1];
    if (pos.equals("-"))
      pos = null;
    Token t = new Token(new Word(line[0], pos), null, line[2]);

    for (line = (String[]) super.next(); line != null && line.length > 0; line =
        (String[]) super.next()) {
      pos = line[1];
      if (pos.equals("-"))
        pos = null;
      t.next = new Token(new Word(line[0], pos), t, line[2]);
      t = (Token) t.next;
    }

    return new LinkedVector(t);
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-mlner

private static Vector<NEWord> splitWord(NEWord word) {
  String[] sentence = {word.form + " "};
  Parser parser = new WordSplitter(new SentenceSplitter(sentence));
  LinkedVector words = (LinkedVector) parser.next();
  Vector<NEWord> res = new Vector<>();
  if (words == null) {
    res.add(word);
    return res;
  }
  String label = word.neLabel;
  for (int i = 0; i < words.size(); i++) {
    if (label.contains("B-") && i > 0)
      label = "I-" + label.substring(2);
    NEWord w = new NEWord(new Word(((Word) words.get(i)).form), null, label);
    res.addElement(w);
  }
  return res;
}

代码示例来源:origin: CogComp/cogcomp-nlp

private static Vector<NEWord> splitWord(NEWord word) {
  String[] sentence = {word.form + " "};
  Parser parser = new WordSplitter(new SentenceSplitter(sentence));
  LinkedVector words = (LinkedVector) parser.next();
  Vector<NEWord> res = new Vector<>();
  if (words == null) {
    res.add(word);
    return res;
  }
  String label = word.neLabel;
  for (int i = 0; i < words.size(); i++) {
    if (label.contains("B-") && i > 0)
      label = "I-" + label.substring(2);
    NEWord w = new NEWord(new Word(((Word) words.get(i)).form), null, label);
    res.addElement(w);
  }
  return res;
}

代码示例来源:origin: CogComp/cogcomp-nlp

Token t = first = new Token(new Word(s[0]), null, null);
  t.next = new Token(new Word(s[i]), t, null);
  t = (Token) t.next;

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-ner

private static Vector<NEWord> splitWord(NEWord word) {
  String[] sentence = {word.form + " "};
  Parser parser = new WordSplitter(new SentenceSplitter(sentence));
  LinkedVector words = (LinkedVector) parser.next();
  Vector<NEWord> res = new Vector<>();
  if (words == null) {
    res.add(word);
    return res;
  }
  String label = word.neLabel;
  for (int i = 0; i < words.size(); i++) {
    if (label.contains("B-") && i > 0)
      label = "I-" + label.substring(2);
    NEWord w = new NEWord(new Word(((Word) words.get(i)).form), null, label);
    res.addElement(w);
  }
  return res;
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-pos

Token t = first = new Token(new Word(s[0]), null, null);
  t.next = new Token(new Word(s[i]), t, null);
  t = (Token) t.next;

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com