本文整理汇总了Java中edu.stanford.nlp.sequences.DocumentReaderAndWriter类的典型用法代码示例。如果您正苦于以下问题:Java DocumentReaderAndWriter类的具体用法?Java DocumentReaderAndWriter怎么用?Java DocumentReaderAndWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentReaderAndWriter类属于edu.stanford.nlp.sequences包,在下文中一共展示了DocumentReaderAndWriter类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: train
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的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
示例2: adapt
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
/**
* @param filename adaptation file
* @param trainDataset original dataset (used in training)
*/
public void adapt(String filename, Dataset<String, String> trainDataset,
DocumentReaderAndWriter<IN> readerWriter) {
flags.ocrTrain = false; // ?? Do we need this? (Pi-Chuan Sat Nov 5 15:42:49 2005)
ObjectBank<List<IN>> docs =
makeObjectBankFromFile(filename, readerWriter);
adapt(docs, trainDataset);
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:12,代码来源:CMMClassifier.java
示例3: main
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
Properties props = StringUtils.argsToProperties(args);
NumberSequenceClassifier nsc =
new NumberSequenceClassifier(props, true, props);
String trainFile = nsc.flags.trainFile;
String testFile = nsc.flags.testFile;
String textFile = nsc.flags.textFile;
String loadPath = nsc.flags.loadClassifier;
String serializeTo = nsc.flags.serializeTo;
if (loadPath != null) {
nsc.loadClassifierNoExceptions(loadPath);
nsc.flags.setProperties(props);
} else if (trainFile != null) {
nsc.train(trainFile);
}
if (serializeTo != null) {
nsc.serializeClassifier(serializeTo);
}
if (testFile != null) {
nsc.classifyAndWriteAnswers(testFile, nsc.makeReaderAndWriter());
}
if (textFile != null) {
DocumentReaderAndWriter readerAndWriter =
new PlainTextDocumentReaderAndWriter();
nsc.classifyAndWriteAnswers(textFile, readerAndWriter);
}
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:33,代码来源:NumberSequenceClassifier.java
示例4: classifyToString
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
public static String classifyToString(List<CoreMap> sentence, DocumentReaderAndWriter<CoreMap> readerAndWriter, AbstractSequenceClassifier classif) {
PlainTextDocumentReaderAndWriter.OutputStyle outFormat =
PlainTextDocumentReaderAndWriter.OutputStyle.fromShortName("inlineXML");
DocumentReaderAndWriter<CoreMap> tmp = readerAndWriter;
readerAndWriter = new PlainTextDocumentReaderAndWriter<CoreMap>();
readerAndWriter.init(classif.flags);
StringBuilder sb = new StringBuilder();
sb.append(((PlainTextDocumentReaderAndWriter<CoreMap>) readerAndWriter).getAnswers(sentence, outFormat, true));
return sb.toString();
}
开发者ID:OpenCCG,项目名称:openccg,代码行数:13,代码来源:NERApp.java
示例5: evaluate
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
/**
* Evaluate the postprocessor given an input file specified in the flags.
*
* @param preProcessor
* @param pwOut
*/
protected void evaluate(Preprocessor preProcessor, PrintWriter pwOut) {
System.err.println("Starting evaluation...");
DocumentReaderAndWriter<CoreLabel> docReader = new ProcessorTools.PostprocessorDocumentReaderAndWriter(preProcessor);
ObjectBank<List<CoreLabel>> lines =
classifier.makeObjectBankFromFile(flags.testFile, docReader);
Counter<String> labelTotal = new ClassicCounter<String>();
Counter<String> labelCorrect = new ClassicCounter<String>();
int total = 0;
int correct = 0;
PrintWriter pw = new PrintWriter(IOTools.getWriterFromFile("apply.out"));
for (List<CoreLabel> line : lines) {
line = classifier.classify(line);
pw.println(Sentence.listToString(ProcessorTools.toPostProcessedSequence(line)));
total += line.size();
for (CoreLabel label : line) {
String hypothesis = label.get(CoreAnnotations.AnswerAnnotation.class);
String reference = label.get(CoreAnnotations.GoldAnswerAnnotation.class);
labelTotal.incrementCount(reference);
if (hypothesis.equals(reference)) {
correct++;
labelCorrect.incrementCount(reference);
}
}
}
pw.close();
double accuracy = ((double) correct) / ((double) total);
accuracy *= 100.0;
pwOut.println("EVALUATION RESULTS");
pwOut.printf("#datums:\t%d%n", total);
pwOut.printf("#correct:\t%d%n", correct);
pwOut.printf("accuracy:\t%.2f%n", accuracy);
pwOut.println("==================");
// Output the per label accuracies
pwOut.println("PER LABEL ACCURACIES");
for (String refLabel : labelTotal.keySet()) {
double nTotal = labelTotal.getCount(refLabel);
double nCorrect = labelCorrect.getCount(refLabel);
double acc = (nCorrect / nTotal) * 100.0;
pwOut.printf(" %s\t%.2f%n", refLabel, acc);
}
}
开发者ID:stanfordnlp,项目名称:phrasal,代码行数:52,代码来源:CRFPostprocessor.java
示例6: main
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
/** The main method, which is essentially the same as in CRFClassifier. See the class documentation. */
public static void main(String[] args) throws Exception {
System.err.println("CRFBiasedClassifier invoked at " + new Date()
+ " with arguments:");
for (String arg : args) {
System.err.print(" " + arg);
}
System.err.println();
Properties props = StringUtils.argsToProperties(args);
CRFBiasedClassifier<CoreLabel> crf = new CRFBiasedClassifier<CoreLabel>(props);
String testFile = crf.flags.testFile;
String loadPath = crf.flags.loadClassifier;
if (loadPath != null) {
crf.loadClassifierNoExceptions(loadPath, props);
} else if (crf.flags.loadJarClassifier != null) {
crf.loadJarClassifier(crf.flags.loadJarClassifier, props);
} else {
crf.loadDefaultClassifier();
}
if(crf.flags.classBias != null) {
StringTokenizer biases = new java.util.StringTokenizer(crf.flags.classBias,",");
while (biases.hasMoreTokens()) {
StringTokenizer bias = new java.util.StringTokenizer(biases.nextToken(),":");
String cname = bias.nextToken();
double w = Double.parseDouble(bias.nextToken());
crf.setBiasWeight(cname,w);
System.err.println("Setting bias for class "+cname+" to "+w);
}
}
if (testFile != null) {
DocumentReaderAndWriter<CoreLabel> readerAndWriter = crf.makeReaderAndWriter();
if (crf.flags.printFirstOrderProbs) {
crf.printFirstOrderProbs(testFile, readerAndWriter);
} else if (crf.flags.printProbs) {
crf.printProbs(testFile, readerAndWriter);
} else if (crf.flags.useKBest) {
int k = crf.flags.kBest;
crf.classifyAndWriteAnswersKBest(testFile, k, readerAndWriter);
} else {
crf.classifyAndWriteAnswers(testFile, readerAndWriter);
}
}
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:47,代码来源:CRFBiasedClassifier.java
示例7: train
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void train(Collection<List<IN>> docs,
DocumentReaderAndWriter<IN> readerAndWriter) {
throw new UnsupportedOperationException();
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:7,代码来源:ClassifierCombiner.java
示例8: main
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
/** Command-line version of the classifier. See the class
* comments for examples of use, and SeqClassifierFlags
* for more information on supported flags.
*/
public static void main(String[] args) throws Exception {
StringUtils.printErrInvocationString("CMMClassifier", args);
Properties props = StringUtils.argsToProperties(args);
CMMClassifier<CoreLabel> cmm = new CMMClassifier<CoreLabel>(props);
String testFile = cmm.flags.testFile;
String textFile = cmm.flags.textFile;
String loadPath = cmm.flags.loadClassifier;
String serializeTo = cmm.flags.serializeTo;
// cmm.crossValidateTrainAndTest(trainFile);
if (loadPath != null) {
cmm.loadClassifierNoExceptions(loadPath, props);
} else if (cmm.flags.loadJarClassifier != null) {
cmm.loadJarClassifier(cmm.flags.loadJarClassifier, props);
} else if (cmm.flags.trainFile != null) {
if (cmm.flags.biasedTrainFile != null) {
cmm.trainSemiSup();
} else {
cmm.train();
}
} else {
cmm.loadDefaultClassifier();
}
if (serializeTo != null) {
cmm.serializeClassifier(serializeTo);
}
if (testFile != null) {
cmm.classifyAndWriteAnswers(testFile, cmm.makeReaderAndWriter());
} else if (cmm.flags.testFiles != null) {
cmm.classifyAndWriteAnswers(cmm.flags.baseTestDir, cmm.flags.testFiles,
cmm.makeReaderAndWriter());
}
if (textFile != null) {
DocumentReaderAndWriter<CoreLabel> readerAndWriter =
new PlainTextDocumentReaderAndWriter<CoreLabel>();
cmm.classifyAndWriteAnswers(textFile, readerAndWriter);
}
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:47,代码来源:CMMClassifier.java
示例9: train
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
public void train(Collection<List<CoreLabel>> docs,
DocumentReaderAndWriter<CoreLabel> readerAndWriter) {}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:3,代码来源:RegexNERSequenceClassifier.java
示例10: train
import edu.stanford.nlp.sequences.DocumentReaderAndWriter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void train(Collection<List<CoreLabel>> docs,
DocumentReaderAndWriter<CoreLabel> readerAndWriter) {
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:6,代码来源:NumberSequenceClassifier.java
注:本文中的edu.stanford.nlp.sequences.DocumentReaderAndWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论