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


Java LibSvmStringOutcomeDataWriter类代码示例

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


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

示例1: train

import org.cleartk.ml.libsvm.LibSvmStringOutcomeDataWriter; //导入依赖的package包/类
@Override
public void train(CollectionReader collectionReader, File outputDirectory) throws Exception {
  AggregateBuilder builder = new AggregateBuilder();
  builder.add(UriToDocumentTextAnnotator.getDescription());
  builder.add(SentenceAnnotator.getDescription());
  builder.add(TokenAnnotator.getDescription());
  builder.add(PosTaggerAnnotator.getDescription());
  builder.add(DefaultSnowballStemmer.getDescription("English"));
  builder.add(AnalysisEngineFactory.createEngineDescription(GoldQuestionCategoryAnnotator.class));
  AnalysisEngineDescription documentClassificationAnnotator = AnalysisEngineFactory.createEngineDescription(
      QuestionCategoryAnnotator.class, CleartkAnnotator.PARAM_IS_TRAINING, true,
      DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY, outputDirectory,
      DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME, LibSvmStringOutcomeDataWriter.class.getName());
  builder.add(documentClassificationAnnotator);
  SimplePipeline.runPipeline(collectionReader, builder.createAggregateDescription());
  System.err.println("Train model and write model.jar file.");
  HideOutput hider = new HideOutput();
  Train.main(outputDirectory, this.trainingArguments.toArray(new String[this.trainingArguments.size()]));
  hider.restoreOutput();
}
 
开发者ID:utk4rsh,项目名称:question-classifier,代码行数:21,代码来源:QuestionCategoryEvaluation.java

示例2: train

import org.cleartk.ml.libsvm.LibSvmStringOutcomeDataWriter; //导入依赖的package包/类
@Override
protected void train(CollectionReader collectionReader, File directory) throws Exception {
	String tmpView = "DP";

	AggregateBuilder b = new AggregateBuilder();

	b.add(AnalysisEngineFactory.createEngineDescription(PrepareClearTk.class, PrepareClearTk.PARAM_VIEW_NAME,
			tmpView, PrepareClearTk.PARAM_ANNOTATION_TYPE, DramatisPersonae.class,
			PrepareClearTk.PARAM_SUBANNOTATIONS, Arrays.asList(Figure.class)));
	b.add(AnalysisEngineFactory.createEngineDescription(BreakIteratorSegmenter.class), CAS.NAME_DEFAULT_SOFA,
			tmpView);
	b.add(AnalysisEngineFactory.createEngineDescription(ClearTkGenderAnnotator.class,
			DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME, LibSvmStringOutcomeDataWriter.class,
			DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY, directory), CAS.NAME_DEFAULT_SOFA, tmpView);
	b.add(AnalysisEngineFactory.createEngineDescription(XmiWriter.class, XmiWriter.PARAM_TARGET_LOCATION,
			"target/xmi"));

	SimplePipeline.runPipeline(collectionReader, b.createAggregate());

	Train.main(directory, new String[] { "-t", "0" });
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:22,代码来源:Evaluation.java

示例3: main

import org.cleartk.ml.libsvm.LibSvmStringOutcomeDataWriter; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription(XmiReader.class,
			XmiReader.PARAM_SOURCE_LOCATION, "src/main/resources/gender/*/*.xmi", XmiReader.PARAM_LENIENT, true);

	String tmpView = "DP";

	AggregateBuilder b = new AggregateBuilder();

	b.add(AnalysisEngineFactory.createEngineDescription(PrepareClearTk.class, PrepareClearTk.PARAM_VIEW_NAME,
			tmpView, PrepareClearTk.PARAM_ANNOTATION_TYPE, DramatisPersonae.class,
			PrepareClearTk.PARAM_SUBANNOTATIONS, Arrays.asList(Figure.class)));
	b.add(AnalysisEngineFactory.createEngineDescription(BreakIteratorSegmenter.class), CAS.NAME_DEFAULT_SOFA,
			tmpView);
	b.add(AnalysisEngineFactory.createEngineDescription(ClearTkGenderAnnotator.class,
			DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME, LibSvmStringOutcomeDataWriter.class,
			DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY, "target/models"), CAS.NAME_DEFAULT_SOFA, tmpView);
	b.add(AnalysisEngineFactory.createEngineDescription(XmiWriter.class, XmiWriter.PARAM_TARGET_LOCATION,
			"target/xmi"));
	SimplePipeline.runPipeline(reader, b.createAggregateDescription());

	Train.main(new File("target/models"), new String[] { "-t", "0" });
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:23,代码来源:Training.java

示例4: testLibsvm

import org.cleartk.ml.libsvm.LibSvmStringOutcomeDataWriter; //导入依赖的package包/类
@Test
public void testLibsvm() throws Exception {
  String outDirectoryName = outputDirectoryName + "/libsvm";

  AnalysisEngineDescription dataWriter = AnalysisEngineFactory.createEngineDescription(
      ExamplePosAnnotator.class,
      CleartkSequenceAnnotator.PARAM_DATA_WRITER_FACTORY_CLASS_NAME,
      ViterbiDataWriterFactory.class.getName(),
      DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
      outDirectoryName,
      DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
      LibSvmStringOutcomeDataWriter.class.getName(),
      ViterbiDataWriterFactory.PARAM_OUTCOME_FEATURE_EXTRACTOR_NAMES,
      new String[] { DefaultOutcomeFeatureExtractor.class.getName() });

  testClassifier(dataWriter, outDirectoryName, 1, "-t", "0"); // MultiClassLIBSVMClassifier.score
                                                              // is not implemented so we cannot
                                                              // have a stack size greater than 1.
  String firstLine = FileUtil.loadListOfStrings(new File(outDirectoryName
      + "/2008_Sichuan_earthquake.txt.pos"))[0].trim();
  boolean badTags = firstLine.equals("2008/NN Sichuan/NN earthquake/NN From/NN Wikipedia/NN ,/NN the/NN free/NN encyclopedia/NN");
  assertFalse(badTags);
  assertEquals(
      "2008/NN Sichuan/NN earthquake/NN From/IN Wikipedia/NN ,/, the/DT free/NN encyclopedia/NN",
      firstLine);

}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:28,代码来源:ExamplePosClassifierTest.java

示例5: testLibsvm

import org.cleartk.ml.libsvm.LibSvmStringOutcomeDataWriter; //导入依赖的package包/类
@Test
public void testLibsvm() throws Exception {
  String libsvmDirectoryName = outputDirectory + "/libsvm";
  AnalysisEngineDescription dataWriter = AnalysisEngineFactory.createEngineDescription(
      NonSequenceExamplePosAnnotator.class,
      DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
      LibSvmStringOutcomeDataWriter.class.getName(),
      DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
      libsvmDirectoryName);
  testClassifier(dataWriter, libsvmDirectoryName, "-t", "0", "-c", "0.1");

  String firstLine = FileUtil.loadListOfStrings(new File(libsvmDirectoryName
      + "/2008_Sichuan_earthquake.txt.pos"))[0].trim();
  checkPOS(firstLine);
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:16,代码来源:NonSequenceExamplePosAnnotatorTest.java

示例6: main

import org.cleartk.ml.libsvm.LibSvmStringOutcomeDataWriter; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  Options options = CliFactory.parseArguments(Options.class, args);

  // ////////////////////////////////////////
  // Create collection reader to load URIs
  // ////////////////////////////////////////
  CollectionReader reader = UriCollectionReader.getCollectionReaderFromDirectory(
      options.getTrainDirectory(),
      UriCollectionReader.RejectSystemFiles.class,
      UriCollectionReader.RejectSystemDirectories.class);

  // ////////////////////////////////////////
  // Create document classification pipeline
  // ////////////////////////////////////////
  AggregateBuilder builder = new AggregateBuilder();

  // Convert URIs in CAS URI View to Plain Text
  builder.add(UriToDocumentTextAnnotator.getDescription());

  // Label documents with gold labels for training
  builder.add(AnalysisEngineFactory.createEngineDescription(GoldDocumentCategoryAnnotator.class));

  // NLP pre-processing components
  builder.add(SentenceAnnotator.getDescription()); // Sentence segmentation
  builder.add(TokenAnnotator.getDescription()); // Tokenization
  builder.add(DefaultSnowballStemmer.getDescription("English")); // Stemming

  // The simple document classification annotator
  builder.add(AnalysisEngineFactory.createEngineDescription(
      BasicDocumentClassificationAnnotator.class,
      DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
      LibSvmStringOutcomeDataWriter.class.getName(),
      DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
      options.getModelsDirectory()));

  // ///////////////////////////////////////////
  // Run pipeline to create training data file
  // ///////////////////////////////////////////
  SimplePipeline.runPipeline(reader, builder.createAggregateDescription());

  // //////////////////////////////////////////////////////////////////////////////
  // Train and write model
  // //////////////////////////////////////////////////////////////////////////////
  JarClassifierBuilder.trainAndPackage(
      options.getModelsDirectory(),
      options.getTrainingArguments().toArray(new String[options.getTrainingArguments().size()]));
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:48,代码来源:TrainModel.java

示例7: testMultiClassLIBSVM

import org.cleartk.ml.libsvm.LibSvmStringOutcomeDataWriter; //导入依赖的package包/类
@Test
public void testMultiClassLIBSVM() throws Exception {
  // create the data writer
  StringAnnotator annotator = new StringAnnotator();
  annotator.initialize(UimaContextFactory.createUimaContext(
      DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
      this.outputDirectoryName,
      DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
      LibSvmStringOutcomeDataWriter.class.getName()));

  // run process to produce a bunch of instances
  annotator.process(null);

  annotator.collectionProcessComplete();

  // check that the output files were written for each class
  BufferedReader reader = new BufferedReader(new FileReader(new File(
      this.outputDirectoryName,
      "training-data.libsvm")));
  Assert.assertTrue(reader.readLine().length() > 0);
  reader.close();

  // run the training command
  HideOutput hider = new HideOutput();
  Train.main(this.outputDirectoryName, "-c", "10", "-t", "0");
  hider.restoreOutput();

  // read in the classifier and test it on new instances
  LibSvmStringOutcomeClassifierBuilder builder = new LibSvmStringOutcomeClassifierBuilder();
  LibSvmStringOutcomeClassifier classifier;
  classifier = builder.loadClassifierFromTrainingDirectory(this.outputDirectory);
  for (Instance<String> instance : ExampleInstanceFactory.generateStringInstances(1000)) {
    List<Feature> features = instance.getFeatures();
    String outcome = instance.getOutcome();
    Assert.assertEquals(outcome, classifier.classify(features));

    Map<String, Double> scoredOutcomes = classifier.score(features);
    for (String otherOutcome : Arrays.asList("A", "B", "C")) {
      if (!otherOutcome.equals(outcome)) {
        Assert.assertTrue(scoredOutcomes.get(outcome) > scoredOutcomes.get(otherOutcome));
      }
    }
  }
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:45,代码来源:LibSvmTest.java


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