當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。