/// <summary> /// Constructs a feature divide model. /// </summary> /// <param name="parent"> the parent guide model. </param> /// <exception cref="MaltChainedException"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public FeatureDivideModel(org.maltparser.parser.guide.Model parent) throws org.maltparser.core.exception.MaltChainedException public FeatureDivideModel(Model parent) { this.parent = parent; Frequency = 0; // this.masterFeatureVector = featureVector; string data_split_threshold = Guide.Configuration.getOptionValue("guide", "data_split_threshold").ToString().Trim(); if (!ReferenceEquals(data_split_threshold, null)) { try { divideThreshold = int.Parse(data_split_threshold); } catch (System.FormatException e) { throw new GuideException("The --guide-data_split_threshold option is not an integer value. ", e); } } else { divideThreshold = 0; } divideModels = new SortedDictionary <int, AtomicModel>(); if (Guide.GuideMode == ClassifierGuide_GuideMode.BATCH) { masterModel = new AtomicModel(-1, this); } else if (Guide.GuideMode == ClassifierGuide_GuideMode.CLASSIFY) { load(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.maltparser.core.feature.FeatureVector extract(org.maltparser.core.feature.FeatureVector featureVector) throws org.maltparser.core.exception.MaltChainedException public virtual FeatureVector extract(FeatureVector featureVector) { AtomicModel model = getAtomicModel((SingleFeatureValue)featureVector.FeatureModel.DivideFeatureFunction.FeatureValue); if (model == null) { return(featureVector); } return(model.extract(getModelFeatureVector(model, featureVector))); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.maltparser.core.feature.FeatureVector predictExtract(org.maltparser.core.feature.FeatureVector featureVector, org.maltparser.parser.history.action.SingleDecision decision) throws org.maltparser.core.exception.MaltChainedException public virtual FeatureVector predictExtract(FeatureVector featureVector, SingleDecision decision) { AtomicModel model = getAtomicModel((SingleFeatureValue)featureVector.FeatureModel.DivideFeatureFunction.FeatureValue); if (model == null) { return(null); } return(model.predictExtract(getModelFeatureVector(model, featureVector), decision)); }
private FeatureVector getModelFeatureVector(AtomicModel model, FeatureVector featureVector) { if (model.Index == -1) { return(featureVector); } else { return(featureVector.FeatureModel.getFeatureVector("/" + featureVector.SpecSubModel.SubModelName)); } }
//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)); }
/// <summary> /// Moves all instance from this atomic model into the destination atomic model and add the divide feature. /// This method is used by the feature divide model to sum up all model below a certain threshold. /// </summary> /// <param name="model"> the destination atomic model </param> /// <param name="divideFeature"> the divide feature </param> /// <param name="divideFeatureIndexVector"> the divide feature index vector </param> /// <exception cref="MaltChainedException"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void moveAllInstances(AtomicModel model, org.maltparser.core.feature.function.FeatureFunction divideFeature, java.util.ArrayList<int> divideFeatureIndexVector) throws org.maltparser.core.exception.MaltChainedException public virtual void moveAllInstances(AtomicModel model, FeatureFunction divideFeature, List <int> divideFeatureIndexVector) { if (method == null) { throw new GuideException("The learner cannot be found. "); } else if (model == null) { throw new GuideException("The guide model cannot be found. "); } else if (divideFeature == null) { throw new GuideException("The divide feature cannot be found. "); } else if (divideFeatureIndexVector == null) { throw new GuideException("The divide feature index vector cannot be found. "); } ((Modifiable)divideFeature).FeatureValue = index; method.moveAllInstances(model.Method, divideFeature, divideFeatureIndexVector); method.terminate(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void load() throws org.maltparser.core.exception.MaltChainedException protected internal virtual void load() { string dsmString = Guide.Configuration.getConfigFileEntryString(ModelName + ".dsm"); string[] lines = dsmString.Split("\n", true); Pattern tabPattern = Pattern.compile("\t"); // FeatureVector divideFeatureVector = featureVector.getFeatureModel().getFeatureVector("/" + featureVector.getSpecSubModel().getSubModelName()); for (int i = 0; i < lines.Length; i++) { string[] cols = tabPattern.split(lines[i]); if (cols.Length != 2) { throw new GuideException(""); } int code = -1; int freq = 0; try { code = int.Parse(cols[0]); freq = int.Parse(cols[1]); } catch (System.FormatException e) { throw new GuideException("Could not convert a string value into an integer value when loading the feature divide model settings (.dsm). ", e); } if (code == -1) { masterModel = new AtomicModel(-1, this); masterModel.Frequency = freq; } else if (divideModels != null) { divideModels[code] = new AtomicModel(code, this); divideModels[code].Frequency = freq; } Frequency = Frequency + freq; } }