• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ObjectBank类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: loadStringCounter

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
public static Counter<String> loadStringCounter(String filename) {

    Counter<String> res = new ClassicCounter<String>();
    for (String line : ObjectBank.getLineIterator(filename)) {

      String[] tokens = line.split("\t");
      res.incrementCount(tokens[0], Double.parseDouble(tokens[1]));

    }
    return res;
  }
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:12,代码来源:FileUtils.java


示例17: train

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Train a model given a preprocessor.
 * 
 * @param preProcessor
 */
protected void train(Preprocessor preProcessor) {
  DocumentReaderAndWriter<CoreLabel> docReader = 
      new ProcessorTools.PostprocessorDocumentReaderAndWriter(preProcessor);
  ObjectBank<List<CoreLabel>> lines =
    classifier.makeObjectBankFromFile(flags.trainFile, docReader);

  classifier.train(lines, docReader);
  System.err.println("Finished training.");
}
 
开发者ID:stanfordnlp,项目名称:phrasal,代码行数:15,代码来源:CRFPostprocessor.java


示例18: tagFile

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
/**
 * Tag text file using PrefixTagger.
 *
 * @param textFile
 *          File to tag
 */
public void tagFile(String textFile) {

  for (String line : ObjectBank.getLineIterator(new File(textFile))) {

    line = line.replaceAll("$", " ");
    line = line + Tagger.EOS_WORD;
    IString[] in = IStrings.toIStringArray(line.split("\\s+"));

    // System.err.println("sent: "+Arrays.toString(in));
    for (int i = 0; i < in.length - 1; ++i) {
      int from = Math.max(0, i - leftWindow);
      int to = Math.min(i + 1 + rightWindow, in.length);
      int offset = -rightWindow;
      IString[] seq = new IString[to - from];
      System.arraycopy(in, from, seq, 0, seq.length);
      // System.err.printf("tagging(%d,%d,%d): %s\n",from,to,offset,Arrays.toString(seq));
      Pair<IString, Float> tag = getBestTag(seq);
      if (i > 0)
        System.out.print(" ");
      int loc = seq.length - 1 + offset;
      // System.err.printf("tagging(%d,%d,%d,%s): %s\n",from,to,offset,tag.first.word(),Arrays.toString(seq));
      System.out.print(seq[loc]);
      System.out.print("/");
      System.out.print(tag.first.toString());
    }
    System.out.print("\n");
  }
}
 
开发者ID:stanfordnlp,项目名称:phrasal,代码行数:35,代码来源:PrefixTagger.java


示例19: readSRLFile

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
private void readSRLFile(String srlFile) {
  srlMap = new HashMap<String,CollectionValuedMap<Integer,String>>();
  for (String line : ObjectBank.getLineIterator(new File(srlFile))) {
    String[] bits = line.split("\\s+", 3);
    String filename = bits[0];
    int treeNum = Integer.parseInt(bits[1]);
    String info = bits[2];
    CollectionValuedMap<Integer,String> cvm = srlMap.get(filename);
    if (cvm == null) {
      cvm = new CollectionValuedMap<Integer,String>();
      srlMap.put(filename, cvm);
    }
    cvm.add(treeNum, info);
  }
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:16,代码来源:MemoryTreebank.java


示例20: readSRLFile

import edu.stanford.nlp.objectbank.ObjectBank; //导入依赖的package包/类
private void readSRLFile(String srlFile) {
  srlMap = Generics.newHashMap();
  for (String line : ObjectBank.getLineIterator(new File(srlFile))) {
    String[] bits = line.split("\\s+", 3);
    String filename = bits[0];
    int treeNum = Integer.parseInt(bits[1]);
    String info = bits[2];
    CollectionValuedMap<Integer,String> cvm = srlMap.get(filename);
    if (cvm == null) {
      cvm = new CollectionValuedMap<Integer,String>();
      srlMap.put(filename, cvm);
    }
    cvm.add(treeNum, info);
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:16,代码来源:MemoryTreebank.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HtmlPage类代码示例发布时间:2022-05-22
下一篇:
Java CPlatformView类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap