edu.isi.karma.modeling.semantictypes.crfmodelhandler
Class CRFModelHandler

java.lang.Object
  extended by edu.isi.karma.modeling.semantictypes.crfmodelhandler.CRFModelHandler

public class CRFModelHandler
extends java.lang.Object

This class is an API to the mycrf package. It allows instantiating CRF models, training them and using them for prediction.

Author:
amangoel

Nested Class Summary
static class CRFModelHandler.ColumnFeature
           
 
Constructor Summary
CRFModelHandler()
          Making the empty constructor private to prevent instantiation of this class.
 
Method Summary
 boolean addOrUpdateLabel(java.lang.String label, java.util.List<java.lang.String> examples, java.util.Map<CRFModelHandler.ColumnFeature,java.util.Collection<java.lang.String>> columnFeatures)
          Adds the passed list of examples to the model.
 boolean getExamplesForLabel(java.lang.String label, java.util.ArrayList<java.lang.String> examples)
           
 boolean getLabels(java.util.List<java.lang.String> labels)
           
 java.lang.String getModelFilePath()
          Returns the path to the file that the CRF Model is using
 boolean predictLabelForExamples(java.util.List<java.lang.String> examples, int numPredictions, java.util.List<java.lang.String> predictedLabels, java.util.List<java.lang.Double> confidenceScores, java.util.List<double[]> exampleProbabilities, java.util.Map<CRFModelHandler.ColumnFeature,java.util.Collection<java.lang.String>> columnFeatures)
           
 boolean readModelFromFile(java.lang.String modelFile)
           
 boolean removeAllLabels()
           
 boolean removeLabel(java.lang.String label)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CRFModelHandler

public CRFModelHandler()
Making the empty constructor private to prevent instantiation of this class. This class should only be used to access its static methods.

Method Detail

getModelFilePath

public java.lang.String getModelFilePath()
Returns the path to the file that the CRF Model is using

Returns:
Path to the Model file

addOrUpdateLabel

public boolean addOrUpdateLabel(java.lang.String label,
                                java.util.List<java.lang.String> examples,
                                java.util.Map<CRFModelHandler.ColumnFeature,java.util.Collection<java.lang.String>> columnFeatures)
Adds the passed list of examples to the model. Regenerates 100 feature functions to represent the label, if examples of this label already exist in the model.

Parameters:
label - True label for the list of example.
examples - List of example strings.
columnFeatures - Map of column features.
Returns:
True if success, else False

getExamplesForLabel

public boolean getExamplesForLabel(java.lang.String label,
                                   java.util.ArrayList<java.lang.String> examples)
Parameters:
label - The label for which examples are being requested.
examples - The list argument that will be used to return the list of examples in the model for the supplied label.
Returns:
True, if successful, else False

getLabels

public boolean getLabels(java.util.List<java.lang.String> labels)
Parameters:
labels - The ordered list of labels is returned in this argument.
Returns:
True, if successful, else False

predictLabelForExamples

public boolean predictLabelForExamples(java.util.List<java.lang.String> examples,
                                       int numPredictions,
                                       java.util.List<java.lang.String> predictedLabels,
                                       java.util.List<java.lang.Double> confidenceScores,
                                       java.util.List<double[]> exampleProbabilities,
                                       java.util.Map<CRFModelHandler.ColumnFeature,java.util.Collection<java.lang.String>> columnFeatures)
Parameters:
examples - - list of examples of an unknown type
numPredictions - - required number of predictions in descending order
predictedLabels - - the argument in which the ordered list of labels is returned. the size of this list could be smaller than numPredictions if there aren't that many labels in the model already
confidenceScores - - the probability of the examples belonging to the labels returned.
exampleProbabilities - - the size() == examples.size(). It contains, for each example, in the same order, a double array that contains the probability of belonging to the labels returned in predictedLabels.
columnFeatures - - this Map supplies ColumnFeatures such as ColumnName, etc.
Returns:
True, if successful, else False

readModelFromFile

public boolean readModelFromFile(java.lang.String modelFile)
Parameters:
modelFile - The path of the file from which the model should be read.
Returns:
True is successfully read. False, otherwise. This function takes the path of file as input and creates an environment that consists of globalData, crfModel, list of examples of each label, etc. It reads an empty file also.

removeAllLabels

public boolean removeAllLabels()
Returns:
True if successfully cleared the model. False, otherwise. This method removes all labels from the CRF model. This is effectively same as setting the model to a state, where an empty file has been read for the first time. Since, each change in the model is immediately reflected in the model file, this method also completely clears the model file.

removeLabel

public boolean removeLabel(java.lang.String label)