當前位置: 首頁>>代碼示例>>Java>>正文


Java DataIndexer類代碼示例

本文整理匯總了Java中opennlp.tools.ml.model.DataIndexer的典型用法代碼示例。如果您正苦於以下問題:Java DataIndexer類的具體用法?Java DataIndexer怎麽用?Java DataIndexer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DataIndexer類屬於opennlp.tools.ml.model包,在下文中一共展示了DataIndexer類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDataIndexer

import opennlp.tools.ml.model.DataIndexer; //導入依賴的package包/類
@Override
   public DataIndexer getDataIndexer(ObjectStream<Event> events) throws IOException {

String dataIndexerName = getStringParam(DATA_INDEXER_PARAM,
					DATA_INDEXER_TWO_PASS_VALUE);

int cutoff = getCutoff();
boolean sortAndMerge = isSortAndMerge();
DataIndexer indexer = null;

if (DATA_INDEXER_ONE_PASS_VALUE.equals(dataIndexerName)) {
    indexer = new OnePassDataIndexer(events, cutoff, sortAndMerge);
} else if (DATA_INDEXER_TWO_PASS_VALUE.equals(dataIndexerName)) {
    indexer = new TwoPassDataIndexer(events, cutoff, sortAndMerge);
} else if (DATA_INDEXER_CHI_SQUARED.equals(dataIndexerName)) {
    indexer = new ChiSquaredDataIndexer(events, cutoff, sortAndMerge);
}
else {
    throw new IllegalStateException("Unexpected data indexer name: "
				    + dataIndexerName);
}
return indexer;
   }
 
開發者ID:USCDataScience,項目名稱:AgePredictor,代碼行數:24,代碼來源:AgeClassifyGIS.java

示例2: doTrain

import opennlp.tools.ml.model.DataIndexer; //導入依賴的package包/類
@Override
public MaxentModel doTrain(DataIndexer indexer) throws IOException {

  List<Double> vy = new ArrayList<Double>();
  List<Feature[]> vx = new ArrayList<Feature[]>();

  // outcomes
  int outcomes[] = indexer.getOutcomeList();

  int max_index = 0;
  
  // For each event ...
  for (int i = 0; i < indexer.getContexts().length; i++) {

    int outcome = outcomes[i];
    vy.add(Double.valueOf(outcome));

    int features[] = indexer.getContexts()[i];

    Feature[] x;
    if (bias >= 0) {
      x = new Feature[features.length + 1];
    } else {
      x = new Feature[features.length];
    }

    // for each feature ...
    for (int fi = 0; fi < features.length; fi++) {
      // TODO: SHOUDL BE indexer.getNumTimesEventsSeen()[i] and not fi !!!
      x[fi] = new FeatureNode(features[fi] + 1, indexer.getNumTimesEventsSeen()[i]);
    } 

    if (features.length > 0) {
      max_index = Math.max(max_index, x[features.length - 1].getIndex());
    }
    
    vx.add(x);
  }

  Problem problem = constructProblem(vy, vx, max_index, bias);
  Parameter parameter = new Parameter(solverType, c, eps, p);
  
  Model liblinearModel = Linear.train(problem, parameter);

  Map<String, Integer> predMap = new HashMap<String, Integer>();
  
  String predLabels[] = indexer.getPredLabels();
  for (int i = 0; i < predLabels.length; i++) {
    predMap.put(predLabels[i], i);
  }
  
  return new LiblinearModel(liblinearModel, indexer.getOutcomeLabels(), predMap);
}
 
開發者ID:apache,項目名稱:opennlp-addons,代碼行數:54,代碼來源:LiblinearTrainer.java

示例3: doTrain

import opennlp.tools.ml.model.DataIndexer; //導入依賴的package包/類
public MaxentModel doTrain(DataIndexer indexer) throws IOException {
int iterations = getIterations();

MaxentModel model;

int threads = getIntParam("Threads", 1);

model = trainModel(iterations, indexer, true, false, null, 0, threads);

return model;
   }
 
開發者ID:USCDataScience,項目名稱:AgePredictor,代碼行數:12,代碼來源:AgeClassifyGIS.java

示例4: trainModel

import opennlp.tools.ml.model.DataIndexer; //導入依賴的package包/類
/**
    * Train a model using the GIS algorithm.
    *
    * @param iterations
    *          The number of GIS iterations to perform.
    * @param indexer
    *          The object which will be used for event compilation.
    * @param printMessagesWhileTraining
    *          Determines whether training status messages are written to STDOUT.
    * @param smoothing
    *          Defines whether the created trainer will use smoothing while
    *          training the model.
    * @param modelPrior
    *          The prior distribution for the model.
    * @param cutoff
    *          The number of times a predicate must occur to be used in a model.
    * @return The newly trained model, which can be used immediately or saved to
    *         disk using an opennlp.tools.ml.maxent.io.GISModelWriter object.
    */
   public static GISModel trainModel(int iterations, DataIndexer indexer,
			      boolean printMessagesWhileTraining, boolean smoothing, Prior modelPrior,
			      int cutoff, int threads) {
GISTrainer trainer = new GISTrainer(printMessagesWhileTraining);
trainer.setSmoothing(smoothing);
trainer.setSmoothingObservation(SMOOTHING_OBSERVATION);
if (modelPrior == null) {
    modelPrior = new UniformPrior();
}

return trainer.trainModel(iterations, indexer, modelPrior, cutoff, threads);
   }
 
開發者ID:USCDataScience,項目名稱:AgePredictor,代碼行數:32,代碼來源:AgeClassifyGIS.java


注:本文中的opennlp.tools.ml.model.DataIndexer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。