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


Java ObjectBank类代码示例

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


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

示例1: loadSynsetRelation

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Loads the given relation from the prolog file, storing the result in
 * the given EdgeType.
 */
private void loadSynsetRelation(File path, String relation, EdgeType type) {
  if (loadedEdges.contains(type)) {
    throw new IllegalArgumentException("Unexpected error: trying to load " + type + " twice");
  }
  loadedEdges.add(type);

  for (String line : ObjectBank.getLineIterator(new File(path, "wn_" + relation + ".pl"))) {
    if (line.length() == 0) continue;
    String[] fields = line.substring(relation.length() + 1, line.length() - 2).split(",");

    SynsetID id1 = getSynsetID(fields[0]);
    SynsetID id2 = getSynsetID(fields[1]);

    id1.add(type, id2);
  }
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:21,代码来源:WordNet.java

示例2: loadWordRelation

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Loads the given relation from the prolog file, storing the result in
 * the given EdgeType.
 */
private void loadWordRelation(File path, String relation, EdgeType type) {
  if (loadedEdges.contains(type)) {
    throw new IllegalArgumentException("Unexpected error: trying to load " + type + " twice");
  }
  loadedEdges.add(type);

  for (String line : ObjectBank.getLineIterator(new File(path, "wn_" + relation + ".pl"))) {
    if (line.length() == 0) continue;
    String[] fields = line.substring(relation.length() + 1, line.length() - 2).split(",");

    final SynsetID sid1 = getSynsetID(fields[0]);
    final SynsetID sid2 = getSynsetID(fields[2]);

    if (sid1 == sid2) {
      System.err.println("WordNet.loadWordRelation(" + relation + "): skipping self-loop on " + sid1);
    } else {
      sid1.add(type, sid2);
    }
  }
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:25,代码来源:WordNet.java

示例3: splitIntoDocs

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
private static Iterator<String> splitIntoDocs(Reader r) {
  if (TREAT_FILE_AS_ONE_DOCUMENT) {
    return Collections.singleton(IOUtils.slurpReader(r)).iterator();
  } else {
    Collection<String> docs = new ArrayList<String>();
    ObjectBank<String> ob = ObjectBank.getLineIterator(r);
    StringBuilder current = new StringBuilder();
    for (String line : ob) {
      if (docPattern.matcher(line).lookingAt()) {
        // Start new doc, store old one if non-empty
        if (current.length() > 0) {
          docs.add(current.toString());
          current = new StringBuilder();
        }
      }
      current.append(line);
      current.append('\n');
    }
    if (current.length() > 0) {
      docs.add(current.toString());
    }
    return docs.iterator();
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:25,代码来源:CoNLLDocumentReaderAndWriter.java

示例4: readSVMLightFormat

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Constructs a Dataset by reading in a file in SVM light format.
 * the created dataset has the same feature and label index as given
 */
public static Dataset<String, String> readSVMLightFormat(String filename, Index<String> featureIndex, Index<String> labelIndex, List<String> lines) {
  Dataset<String, String> dataset;
  try {
    dataset = new Dataset<String, String>(10, featureIndex, labelIndex);
    for (String line : ObjectBank.getLineIterator(new File(filename))) {
      if(lines != null)
        lines.add(line);
      dataset.add(svmLightLineToDatum(line));
    }

  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  return dataset;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:20,代码来源:Dataset.java

示例5: PRCurve

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * reads scores with classes from a file, sorts by score and creates the arrays
 *
 */
public PRCurve(String filename, boolean svm) {
  try {

    ArrayList<Pair<Double, Integer>> dataScores = new ArrayList<Pair<Double, Integer>>();
    for(String line : ObjectBank.getLineIterator(new File(filename))) {
      List<String> elems = StringUtils.split(line);
      int cls = Double.valueOf(elems.get(0)).intValue();
      if (cls == -1) {
        cls = 0;
      }
      double score = Double.valueOf(elems.get(1)) + 0.5;
      Pair<Double, Integer> p = new Pair<Double, Integer>(new Double(score), Integer.valueOf(cls));
      dataScores.add(p);
    }
    init(dataScores);
  } catch (Exception e) {
    e.printStackTrace();
  }

}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:25,代码来源:PRCurve.java

示例6: classify

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Classify the tokens in a String. Each sentence becomes a separate document.
 *
 * @param str
 *          A String with tokens in one or more sentences of text to be
 *          classified.
 * @return {@link List} of classified sentences (each a List of something that
 *         extends {@link CoreMap}).
 */
public List<List<IN>> classify(String str) {
  ObjectBank<List<IN>> documents =
    makeObjectBankFromString(str, plainTextReaderAndWriter);
  List<List<IN>> result = new ArrayList<List<IN>>();

  for (List<IN> document : documents) {
    classify(document);

    List<IN> sentence = new ArrayList<IN>();
    for (IN wi : document) {
      // TaggedWord word = new TaggedWord(wi.word(), wi.answer());
      // sentence.add(word);
      sentence.add(wi);
    }
    result.add(sentence);
  }
  return result;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:28,代码来源:AbstractSequenceClassifier.java

示例7: classifyRaw

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Classify the tokens in a String. Each sentence becomes a separate document.
 * Doesn't override default readerAndWriter.
 *
 * @param str
 *          A String with tokens in one or more sentences of text to be
 *          classified.
 * @return {@link List} of classified sentences (each a List of something that
 *         extends {@link CoreMap}).
 */
public List<List<IN>> classifyRaw(String str,
                                  DocumentReaderAndWriter<IN> readerAndWriter) {
  ObjectBank<List<IN>> documents =
    makeObjectBankFromString(str, readerAndWriter);
  List<List<IN>> result = new ArrayList<List<IN>>();

  for (List<IN> document : documents) {
    classify(document);

    List<IN> sentence = new ArrayList<IN>();
    for (IN wi : document) {
      // TaggedWord word = new TaggedWord(wi.word(), wi.answer());
      // sentence.add(word);
      sentence.add(wi);
    }
    result.add(sentence);
  }
  return result;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:30,代码来源:AbstractSequenceClassifier.java

示例8: classifyFile

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Classify the contents of a file.
 *
 * @param filename
 *          Contains the sentence(s) to be classified.
 * @return {@link List} of classified List of IN.
 */
public List<List<IN>> classifyFile(String filename) {
  ObjectBank<List<IN>> documents =
    makeObjectBankFromFile(filename, plainTextReaderAndWriter);
  List<List<IN>> result = new ArrayList<List<IN>>();

  for (List<IN> document : documents) {
    // System.err.println(document);
    classify(document);

    List<IN> sentence = new ArrayList<IN>();
    for (IN wi : document) {
      sentence.add(wi);
      // System.err.println(wi);
    }
    result.add(sentence);
  }
  return result;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:26,代码来源:AbstractSequenceClassifier.java

示例9: segmentString

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
public List<String> segmentString(String sentence,
                                  DocumentReaderAndWriter<IN> readerAndWriter) {
  ObjectBank<List<IN>> docs = makeObjectBankFromString(sentence,
                                                       readerAndWriter);

  StringWriter stringWriter = new StringWriter();
  PrintWriter stringPrintWriter = new PrintWriter(stringWriter);
  for (List<IN> doc : docs) {
    classify(doc);
    readerAndWriter.printAnswers(doc, stringPrintWriter);
    stringPrintWriter.println();
  }
  stringPrintWriter.close();
  String segmented = stringWriter.toString();

  return Arrays.asList(segmented.split("\\s"));
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:18,代码来源:AbstractSequenceClassifier.java

示例10: makeObjectBankFromString

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Reads a String into an ObjectBank object. NOTE: that the current
 * implementation of ReaderIteratorFactory will first try to interpret each
 * string as a filename, so this method will yield unwanted results if it
 * applies to a string that is at the same time a filename. It prints out a
 * warning, at least.
 *
 * @param string The String which will be the content of the ObjectBank
 * @return The ObjectBank
 */
public ObjectBank<List<IN>>
  makeObjectBankFromString(String string,
                           DocumentReaderAndWriter<IN> readerAndWriter)
{
  if (flags.announceObjectBankEntries) {
    System.err.print("Reading data using " + readerAndWriter.getClass());

    if (flags.inputEncoding == null) {
      System.err.println("Getting data from " + string + " (default encoding)");
    } else {
      System.err.println("Getting data from " + string + " (" + flags.inputEncoding + " encoding)");
    }
  }
  // return new ObjectBank<List<IN>>(new
  // ResettableReaderIteratorFactory(string), readerAndWriter);
  // TODO
  return new ObjectBankWrapper<IN>(flags, new ObjectBank<List<IN>>(new ResettableReaderIteratorFactory(string),
      readerAndWriter), knownLCWords);
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:30,代码来源:AbstractSequenceClassifier.java

示例11: makeObjectBankFromFiles

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
public ObjectBank<List<IN>> makeObjectBankFromFiles(String[] trainFileList,
                                                    DocumentReaderAndWriter<IN> readerAndWriter) {
  // try{
  Collection<File> files = new ArrayList<File>();
  for (String trainFile : trainFileList) {
    File f = new File(trainFile);
    files.add(f);
  }
  // System.err.printf("trainFileList contains %d file%s.\n", files.size(),
  // files.size() == 1 ? "": "s");
  // TODO get rid of objectbankwrapper
  // return new ObjectBank<List<IN>>(new
  // ResettableReaderIteratorFactory(files), readerAndWriter);
  return new ObjectBankWrapper<IN>(flags, new ObjectBank<List<IN>>(new ResettableReaderIteratorFactory(files, flags.inputEncoding),
      readerAndWriter), knownLCWords);
  // } catch (IOException e) {
  // throw new RuntimeException(e);
  // }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:20,代码来源:AbstractSequenceClassifier.java

示例12: initLexicon

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
private static Map<String,String> initLexicon(String path) {
  synchronized (lexiconMap) {
    Map<String,String> lex = lexiconMap.get(path);
    if (lex != null) {
      return lex;
    } else {
      Timing.startDoing("Loading distsim lexicon from " + path);
      Map<String,String> lexic = Generics.newHashMap();
      for (String word : ObjectBank.getLineIterator(new File(path))) {
        String[] bits = word.split("\\s+");
        lexic.put(bits[0].toLowerCase(), bits[1]);
      }
      lexiconMap.put(path, lexic);
      Timing.endDoing();
      return lexic;
    }
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:19,代码来源:ExtractorDistsim.java

示例13: loadMixedCaseMap

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
public static Map<String,String> loadMixedCaseMap(String mapFile) {
  Map<String,String> map = Generics.newHashMap();
  try {
    InputStream is = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(mapFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    for(String line : ObjectBank.getLineIterator(br)) {
      line = line.trim();
      String[] els = line.split("\\s+");
      if(els.length != 2) 
        throw new RuntimeException("Wrong format: "+mapFile);
      map.put(els[0],els[1]);
    }
    br.close();
    is.close();
  } catch(IOException e){
    throw new RuntimeException(e);
  }
  return map;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:20,代码来源:TrueCaseAnnotator.java

示例14: PRCurve

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * reads scores with classes from a file, sorts by score and creates the arrays
 *
 */
public PRCurve(String filename, boolean svm) {
  try {

    ArrayList<Pair<Double, Integer>> dataScores = new ArrayList<Pair<Double, Integer>>();
    for(String line : ObjectBank.getLineIterator(new File(filename))) {
      List<String> elems = StringUtils.split(line);
      int cls = (new Double(elems.get(0).toString())).intValue();
      if (cls == -1) {
        cls = 0;
      }
      double score = Double.parseDouble(elems.get(1).toString()) + 0.5;
      Pair<Double, Integer> p = new Pair<Double, Integer>(new Double(score), Integer.valueOf(cls));
      dataScores.add(p);
    }
    init(dataScores);
  } catch (Exception e) {
    e.printStackTrace();
  }

}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:25,代码来源:PRCurve.java

示例15: main

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  ColumnDataClassifier columnDataClassifier = new ColumnDataClassifier("examples/cheese2007.prop");
  Classifier<String,String> classifier =
      columnDataClassifier.makeClassifier(columnDataClassifier.readTrainingExamples("examples/cheeseDisease.train"));
  for (String line : ObjectBank.getLineIterator("examples/cheeseDisease.test", "utf-8")) {
    Datum<String,String> d = columnDataClassifier.makeDatumFromLine(line);
    System.out.println(line + "  ==>  " + classifier.classOf(d));
  }
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:10,代码来源:StanfordClassifier.java


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