Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean predict(org.maltparser.core.feature.FeatureVector featureVector, org.maltparser.parser.history.action.SingleDecision decision, boolean one_prediction) throws org.maltparser.core.exception.MaltChainedException
        public virtual bool predict(FeatureVector featureVector, SingleDecision decision, bool one_prediction)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.ArrayList<org.maltparser.ml.lib.MaltFeatureNode> featureList = new java.util.ArrayList<org.maltparser.ml.lib.MaltFeatureNode>();
            List <MaltFeatureNode> featureList = new List <MaltFeatureNode>();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int size = featureVector.size();
            int size = featureVector.Count;

            for (int i = 1; i <= size; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.feature.value.FeatureValue featureValue = featureVector.getFeatureValue(i-1);
                FeatureValue featureValue = featureVector.GetFeatureValue(i - 1);
                if (featureValue != null && !(excludeNullValues == true && featureValue.NullValue))
                {
                    if (!featureValue.Multiple)
                    {
                        SingleFeatureValue singleFeatureValue = (SingleFeatureValue)featureValue;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int index = featureMap.getIndex(i, singleFeatureValue.getIndexCode());
                        int index = featureMap.getIndex(i, singleFeatureValue.IndexCode);
                        if (index != -1 && singleFeatureValue.Value != 0)
                        {
                            featureList.Add(new MaltFeatureNode(index, singleFeatureValue.Value));
                        }
                    }
                    else
                    {
                        foreach (int?value in ((MultipleFeatureValue)featureValue).Codes)
                        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int v = featureMap.getIndex(i, value);
                            int v = featureMap.getIndex(i, value.Value);
                            if (v != -1)
                            {
                                featureList.Add(new MaltFeatureNode(v, 1));
                            }
                        }
                    }
                }
            }
            try
            {
                if (one_prediction)
                {
                    decision.KBestList.add(model.predict_one(featureList.ToArray()));
                }
                else
                {
                    decision.KBestList.addList(model.predict(featureList.ToArray()));
                }
            }
            catch (System.OutOfMemoryException e)
            {
                throw new LibException("Out of memory. Please increase the Java heap size (-Xmx<size>). ", e);
            }
            return(true);
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void addInstance(org.maltparser.core.feature.FeatureVector featureVector, org.maltparser.parser.history.action.SingleDecision decision) throws org.maltparser.core.exception.MaltChainedException
        public virtual void addInstance(FeatureVector featureVector, SingleDecision decision)
        {
            //		featureVector.getFeatureModel().getDivideFeatureFunction().update();
            SingleFeatureValue featureValue = (SingleFeatureValue)featureVector.FeatureModel.DivideFeatureFunction.FeatureValue;

            if (!divideModels.ContainsKey(featureValue.IndexCode))
            {
                divideModels[featureValue.IndexCode] = new AtomicModel(featureValue.IndexCode, this);
            }
            FeatureVector divideFeatureVector = featureVector.FeatureModel.getFeatureVector("/" + featureVector.SpecSubModel.SubModelName);

            divideModels[featureValue.IndexCode].addInstance(divideFeatureVector, decision);
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private AtomicModel getAtomicModel(org.maltparser.core.feature.value.SingleFeatureValue featureValue) throws org.maltparser.core.exception.MaltChainedException
        private AtomicModel getAtomicModel(SingleFeatureValue featureValue)
        {
            //((SingleFeatureValue)masterFeatureVector.getFeatureModel().getDivideFeatureFunction().getFeatureValue()).getIndexCode()
            if (divideModels != null && divideModels.ContainsKey(featureValue.IndexCode))
            {
                return(divideModels[featureValue.IndexCode]);
            }
            else if (masterModel != null && masterModel.Frequency > 0)
            {
                return(masterModel);
            }
            return(null);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public TableFeature(SymbolTableHandler tableHandler) throws org.maltparser.core.exception.MaltChainedException
        public TableFeature(SymbolTableHandler tableHandler)
        {
            this.tableHandler = tableHandler;
            featureValue      = new SingleFeatureValue(this);
        }
Exemplo n.º 5
0
        //	public DistanceFeature(FeatureRegistry registry) throws MaltChainedException {
        //		this(registry.getSymbolTableHandler());
        //	}

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public DistanceFeature(org.maltparser.core.symbol.SymbolTableHandler tableHandler) throws org.maltparser.core.exception.MaltChainedException
        public DistanceFeature(SymbolTableHandler tableHandler)
        {
            featureValue      = new SingleFeatureValue(this);
            this.tableHandler = tableHandler;
            normalization     = new LinkedHashMap <int, string>();
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void addInstance(org.maltparser.parser.history.action.SingleDecision decision, org.maltparser.core.feature.FeatureVector featureVector) throws org.maltparser.core.exception.MaltChainedException
        public virtual void addInstance(SingleDecision decision, FeatureVector featureVector)
        {
            if (featureVector == null)
            {
                throw new LibException("The feature vector cannot be found");
            }
            else if (decision == null)
            {
                throw new LibException("The decision cannot be found");
            }

            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StringBuilder sb = new StringBuilder();
                StringBuilder sb = new StringBuilder();
                sb.Append(decision.DecisionCode + "\t");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n = featureVector.size();
                int n = featureVector.Count;
                for (int i = 0; i < n; i++)
                {
                    FeatureValue featureValue = featureVector.GetFeatureValue(i);
                    if (featureValue == null || (excludeNullValues == true && featureValue.NullValue))
                    {
                        sb.Append("-1");
                    }
                    else
                    {
                        if (!featureValue.Multiple)
                        {
                            SingleFeatureValue singleFeatureValue = (SingleFeatureValue)featureValue;
                            if (singleFeatureValue.Value == 1)
                            {
                                sb.Append(singleFeatureValue.IndexCode);
                            }
                            else if (singleFeatureValue.Value == 0)
                            {
                                sb.Append("-1");
                            }
                            else
                            {
                                sb.Append(singleFeatureValue.IndexCode);
                                sb.Append(":");
                                sb.Append(singleFeatureValue.Value);
                            }
                        }
                        else
                        {                         //if (featureValue instanceof MultipleFeatureValue) {
                            ISet <int> values = ((MultipleFeatureValue)featureValue).Codes;
                            int        j      = 0;
                            foreach (int?value in values)
                            {
                                sb.Append(value.ToString());
                                if (j != values.Count - 1)
                                {
                                    sb.Append("|");
                                }
                                j++;
                            }
                        }
                        //					else {
                        //						throw new LibException("Don't recognize the type of feature value: "+featureValue.getClass());
                        //					}
                    }
                    sb.Append('\t');
                }
                sb.Append('\n');
                instanceOutput.Write(sb.ToString());
                instanceOutput.Flush();
                increaseNumberOfInstances();
                //			sb.setLength(0);
            }
            catch (IOException e)
            {
                throw new LibException("The learner cannot write to the instance file. ", e);
            }
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public InputArcFeature(org.maltparser.core.io.dataformat.DataFormatInstance dataFormatInstance, org.maltparser.core.symbol.SymbolTableHandler tableHandler) throws org.maltparser.core.exception.MaltChainedException
        public InputArcFeature(DataFormatInstance dataFormatInstance, SymbolTableHandler tableHandler)
        {
            this.dataFormatInstance = dataFormatInstance;
            this.tableHandler       = tableHandler;
            featureValue            = new SingleFeatureValue(this);
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean predict(org.maltparser.core.feature.FeatureModel featureModel, org.maltparser.parser.history.action.ComplexDecisionAction decision, boolean one_prediction) throws org.maltparser.core.exception.MaltChainedException
        public bool predict(FeatureModel featureModel, ComplexDecisionAction decision, bool one_prediction)
        {
            if (decision.numberOfDecisions() > 2)
            {
                throw new MaltChainedException("Number of decisions is greater than two,  which is unsupported in the light-weight parser (lw.parser)");
            }
            featureModel.update();
            bool success = true;

            for (int i = 0; i < decision.numberOfDecisions(); i++)
            {
                LWClassifier classifier = null;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.parser.history.action.SingleDecision singleDecision = decision.getSingleDecision(i);
                SingleDecision singleDecision = decision.getSingleDecision(i);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StringBuilder classifierString = new StringBuilder();
                StringBuilder classifierString = new StringBuilder();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StringBuilder decisionModelString = new StringBuilder();
                StringBuilder decisionModelString = new StringBuilder();
                if (singleDecision.RelationToNextDecision == RelationToNextDecision.BRANCHED)
                {
                    decisionModelString.Append("bdm");
                }
                else if (singleDecision.RelationToNextDecision == RelationToNextDecision.SEQUANTIAL)
                {
                    decisionModelString.Append("sdm");
                }
                else
                {
                    decisionModelString.Append("odm");
                }
                decisionModelString.Append(i);
                string decisionSymbol = "";
                if (i == 1 && singleDecision.RelationToNextDecision == RelationToNextDecision.BRANCHED)
                {
                    decisionSymbol = singleDecision.DecisionSymbol;
                    decisionModelString.Append(decisionSymbol);
                }
                decisionModelString.Append('.');
                FeatureVector featureVector = featureModel.getFeatureVector(decisionSymbol, singleDecision.TableContainer.TableContainerName);

                if (featureModel.hasDivideFeatureFunction())
                {
                    SingleFeatureValue featureValue = (SingleFeatureValue)featureModel.DivideFeatureFunction.FeatureValue;
                    classifierString.Append(decisionModelString);
                    classifierString.Append(string.Format("{0:D3}", featureValue.IndexCode));
                    classifierString.Append('.');
                    classifierString.Append(classifierName);
                    classifier = classifiers[classifierString.ToString()];
                    if (classifier != null)
                    {
                        FeatureVector dividefeatureVector = featureModel.getFeatureVector("/" + featureVector.SpecSubModel.SubModelName);
                        success = classifier.predict(dividefeatureVector, singleDecision, one_prediction) && success;
                        continue;
                    }
                    classifierString.Length = 0;
                }

                classifierString.Append(decisionModelString);
                classifierString.Append(classifierName);
                classifier = classifiers[classifierString.ToString()];
                if (classifier != null)
                {
                    success = classifier.predict(featureVector, singleDecision, one_prediction) && success;
                }
                else
                {
                    singleDecision.addDecision(1);
                }
                if (!singleDecision.continueWithNextDecision())
                {
                    break;
                }
            }
            return(success);
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public ColumnFeature() throws org.maltparser.core.exception.MaltChainedException
        public ColumnFeature()
        {
            featureValue = new SingleFeatureValue(this);
        }