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


Java ObjectBank.getLineIterator方法代码示例

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


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

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

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

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

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

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

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

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

示例14: readFileList

import edu.stanford.nlp.objectbank.ObjectBank; //导入方法依赖的package包/类
private static Collection<File> readFileList(String fileName) throws IOException {
  return ObjectBank.getLineIterator(fileName, new ObjectBank.PathToFileFunction());
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:4,代码来源:StanfordCoreNLP.java


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