Example #1
0
        /**
         * 命中的所有特征函数输出之和
         * @param feature
         * @param y
         * @return
         */
        private int apply_f_sharp(Feature feature, int y)
        {
            int sum = 0;

            for (int i = 0; i < functions.Count; i++)
            {
                FeatureFunction function = functions[i];
                sum += function.apply(feature, y);
            }
            return(sum);
        }
Example #2
0
        /// <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();
        }
Example #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void moveAllInstances(org.maltparser.ml.LearningMethod method, org.maltparser.core.feature.function.FeatureFunction divideFeature, java.util.ArrayList<int> divideFeatureIndexVector) throws org.maltparser.core.exception.MaltChainedException
        public virtual void moveAllInstances(LearningMethod method, FeatureFunction divideFeature, List <int> divideFeatureIndexVector)
        {
            if (method == null)
            {
                throw new LibException("The learning method cannot be found. ");
            }
            else if (divideFeature == null)
            {
                throw new LibException("The divide feature cannot be found. ");
            }

            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.BufferedReader in = new java.io.BufferedReader(getInstanceInputStreamReader(".ins"));
                StreamReader @in = new StreamReader(getInstanceInputStreamReader(".ins"));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.BufferedWriter out = method.getInstanceWriter();
                StreamWriter @out = method.InstanceWriter;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StringBuilder sb = new StringBuilder(6);
                StringBuilder sb = new StringBuilder(6);
                int           l  = @in.Read();
                char          c;
                int           j = 0;

                while (true)
                {
                    if (l == -1)
                    {
                        sb.Length = 0;
                        break;
                    }
                    c = (char)l;
                    l = @in.Read();
                    if (c == '\t')
                    {
                        if (divideFeatureIndexVector.Contains(j - 1))
                        {
                            @out.Write(Convert.ToString(((SingleFeatureValue)divideFeature.FeatureValue).IndexCode));
                            @out.BaseStream.WriteByte('\t');
                        }
                        @out.Write(sb.ToString());
                        j++;
                        @out.BaseStream.WriteByte('\t');
                        sb.Length = 0;
                    }
                    else if (c == '\n')
                    {
                        @out.Write(sb.ToString());
                        if (divideFeatureIndexVector.Contains(j - 1))
                        {
                            @out.BaseStream.WriteByte('\t');
                            @out.Write(Convert.ToString(((SingleFeatureValue)divideFeature.FeatureValue).IndexCode));
                        }
                        @out.BaseStream.WriteByte('\n');
                        sb.Length = 0;
                        method.increaseNumberOfInstances();
                        decreaseNumberOfInstances();
                        j = 0;
                    }
                    else
                    {
                        sb.Append(c);
                    }
                }
                @in.Close();
                getFile(".ins").delete();
                @out.Flush();
            }
            catch (SecurityException e)
            {
                throw new LibException("The learner cannot remove the instance file. ", e);
            }
            catch (NullReferenceException e)
            {
                throw new LibException("The instance file cannot be found. ", e);
            }
            catch (FileNotFoundException e)
            {
                throw new LibException("The instance file cannot be found. ", e);
            }
            catch (IOException e)
            {
                throw new LibException("The learner read from the instance file. ", e);
            }
        }
Example #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void moveAllInstances(org.maltparser.ml.LearningMethod method, org.maltparser.core.feature.function.FeatureFunction divideFeature, java.util.ArrayList<int> divideFeatureIndexVector) throws org.maltparser.core.exception.MaltChainedException
        public virtual void moveAllInstances(LearningMethod method, FeatureFunction divideFeature, List <int> divideFeatureIndexVector)
        {
        }
Example #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public FeatureModel(org.maltparser.core.feature.spec.SpecificationModel _specModel, FeatureRegistry _registry, org.maltparser.core.feature.system.FeatureEngine _engine, String dataSplitColumn, String dataSplitStructure) throws org.maltparser.core.exception.MaltChainedException
        public FeatureModel(SpecificationModel _specModel, FeatureRegistry _registry, FeatureEngine _engine, string dataSplitColumn, string dataSplitStructure)
        {
            specModel            = _specModel;
            registry             = _registry;
            featureEngine        = _engine;
            addressFunctionCache = new List <AddressFunction>();
            featureFunctionCache = new List <FeatureFunction>();
            FeatureVector tmpMainFeatureVector = null;

            foreach (SpecificationSubModel subModel in specModel)
            {
                FeatureVector fv = new FeatureVector(this, subModel);
                if (tmpMainFeatureVector == null)
                {
                    if (subModel.SubModelName.Equals("MAIN"))
                    {
                        tmpMainFeatureVector = fv;
                    }
                    else
                    {
                        tmpMainFeatureVector = fv;
                        put(subModel.SubModelName, fv);
                    }
                }
                else
                {
                    put(subModel.SubModelName, fv);
                }
            }
            mainFeatureVector = tmpMainFeatureVector;
            if (!ReferenceEquals(dataSplitColumn, null) && dataSplitColumn.Length > 0 && !ReferenceEquals(dataSplitStructure, null) && dataSplitStructure.Length > 0)
            {
//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("InputColumn(");
                sb.Append(dataSplitColumn);
                sb.Append(", ");
                sb.Append(dataSplitStructure);
                sb.Append(')');
                divideFeatureFunction = identifyFeature(sb.ToString());
                //			this.divideFeatureIndexVectorMap = new HashMap<String,ArrayList<Integer>>();
                divideFeatureIndexVector = new List <int>();

                for (int i = 0; i < mainFeatureVector.Count; i++)
                {
                    if (mainFeatureVector[i].Equals(divideFeatureFunction))
                    {
                        divideFeatureIndexVector.Add(i);
                    }
                }
                foreach (SpecificationSubModel subModel in specModel)
                {
                    FeatureVector featureVector = get(subModel.SubModelName);
                    if (featureVector == null)
                    {
                        featureVector = mainFeatureVector;
                    }
                    string divideKeyName = "/" + subModel.SubModelName;
                    //				divideFeatureIndexVectorMap.put(divideKeyName, divideFeatureIndexVector);

                    FeatureVector divideFeatureVector = (FeatureVector)featureVector.clone();
                    foreach (int?i in divideFeatureIndexVector)
                    {
                        divideFeatureVector.Remove(divideFeatureVector[i]);
                    }
                    put(divideKeyName, divideFeatureVector);
                }
            }
            else
            {
                divideFeatureFunction = null;
                //			this.divideFeatureIndexVectorMap = null;
                divideFeatureIndexVector = null;
            }
        }