    001    package org.maltparser.ml;
    002
    003    import java.io.BufferedWriter;
    004    import java.util.ArrayList;
    005    import java.util.Map;
    006    import java.util.Set;
    007
    008    import org.maltparser.core.exception.MaltChainedException;
    009    import org.maltparser.core.feature.FeatureVector;
    010    import org.maltparser.core.feature.function.FeatureFunction;
    011    import org.maltparser.core.syntaxgraph.DependencyStructure;
    012    import org.maltparser.ml.liblinear.LiblinearException;
    013    import org.maltparser.parser.history.action.SingleDecision;
    014
    015
    016    public interface LearningMethod {
    017            public static final int BATCH = 0;
    018            public static final int CLASSIFY = 1;
    019            public void addInstance(SingleDecision decision, FeatureVector featureVector) throws MaltChainedException;
    020            public void finalizeSentence(DependencyStructure dependencyGraph)  throws MaltChainedException;
    021            public void noMoreInstances() throws MaltChainedException;
    022            public void train(FeatureVector featureVector) throws MaltChainedException;
    023
    024            /**
    025             * This method does a cross validation of the training instances added and return the average score over the
    026             * nrOfSplit divisions. This method is used by the decision tree model when deciding which parts
    027             * of the tree that shall be pruned.
    028             *
    029             * @param featureVector
    030             * @param nrOfSplits
    031             * @return a double
    032             * @throws MaltChainedException
    033             */
    034            public double crossValidate(FeatureVector featureVector, int nrOfSplits) throws MaltChainedException;
    035            public void moveAllInstances(LearningMethod method, FeatureFunction divideFeature, ArrayList<Integer> divideFeatureIndexVector) throws MaltChainedException;
    036            public void terminate() throws MaltChainedException;
    037            public boolean predict(FeatureVector features, SingleDecision decision) throws MaltChainedException;
    038            public BufferedWriter getInstanceWriter();
    039            public void increaseNumberOfInstances();
    040            public void decreaseNumberOfInstances();
    041
    042
    043            void divideByFeatureSet(
    044                            Set<Integer> featureIdsToCreateSeparateBranchesForSet,
    045                            ArrayList<Integer> divideFeatureIndexVector, String otherId)
    046                            throws MaltChainedException;
    047            public Map<Integer, Integer> createFeatureIdToCountMap(
    048                            ArrayList<Integer> divideFeatureIndexVector) throws MaltChainedException;
    049    }