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) throws org.maltparser.core.exception.MaltChainedException
        public virtual bool predict(FeatureVector featureVector, SingleDecision decision)
        {
            AtomicModel model = getAtomicModel((SingleFeatureValue)featureVector.FeatureModel.DivideFeatureFunction.FeatureValue);

            if (model == null)
            {
                if (Guide.Configuration.LoggerInfoEnabled)
                {
                    Guide.Configuration.logInfoMessage("Could not predict the next parser decision because there is " + "no divide or master model that covers the divide value '" + ((SingleFeatureValue)featureVector.FeatureModel.DivideFeatureFunction.FeatureValue).IndexCode + "', as default" + " class code '1' is used. ");
                }
                decision.addDecision(1);                 // default prediction
                return(true);
            }
            return(model.predict(getModelFeatureVector(model, featureVector), decision));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a candidate to the k-best list
        /// </summary>
        /// <param name="actionCode"> the integer representation  of candidate action </param>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void add(int actionCode) throws org.maltparser.core.exception.MaltChainedException
        public virtual void add(int actionCode)
        {
            if (k != -1 && addCandidateIndex >= k)
            {
                return;
            }
            if (addCandidateIndex >= kBestList.Count)
            {
                kBestList.Add(new Candidate());
            }
            kBestList[addCandidateIndex].ActionCode = actionCode;
            if (addCandidateIndex == 0)
            {
                //			if (decision instanceof SingleDecision) {
                //				((SingleDecision)decision).addDecision(actionCode);
                //			}
                decision.addDecision(actionCode);
                topCandidateIndex++;
            }
            addCandidateIndex++;
        }
Exemplo n.º 3
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);
        }