Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Cheater(org.maltparser.parser.guide.instance.InstanceModel owner, System.Nullable<int> learnerMode) throws org.maltparser.core.exception.MaltChainedException
        public Cheater(InstanceModel owner, int?learnerMode)
        {
            Owner = owner;
            LearningMethodName = "cheater";
            LearnerMode        = learnerMode.Value;
            NumberOfInstances  = 0;
            verbosity          = Verbostity.SILENT;
            initSpecialParameters();

            if (learnerMode.Value == LearningMethod_Fields.BATCH)
            {
                if (!saveCheatAction)
                {
                    instanceOutput = new StreamWriter(getInstanceOutputStreamWriter(".ins"));
                }
                else
                {
                    try
                    {
                        if (!ReferenceEquals(cheaterFileName, null) && !cheaterFileName.Equals(""))
                        {
                            cheaterWriter = new StreamWriter(new FileStream(cheaterFileName, FileMode.Create, FileAccess.Write));
                        }
                    }
                    catch (Exception e)
                    {
                        throw new CheaterException("", e);
                    }
                }
            }
        }
Пример #2
0
        //	private int[] getCardinalities(FeatureVector featureVector) {
        //		int[] cardinalities = new int[featureVector.size()];
        //		int i = 0;
        //		for (FeatureFunction feature : featureVector) {
        //			cardinalities[i++] = feature.getFeatureValue().getCardinality();
        //		}
        //		return cardinalities;
        //	}
        //
        //	private void saveCardinalities(OutputStreamWriter osw, int[] cardinalities) throws MaltChainedException {
        //		final BufferedWriter out = new BufferedWriter(osw);
        //		try {
        //			for (int i = 0, n = cardinalities.length; i < n; i++) {
        //				out.write(Integer.toString(cardinalities[i]));
        //				if (i < n - 1) {
        //					out.write(',');
        //				}
        //			}
        //			out.write('\n');
        //			out.close();
        //		} catch (IOException e) {
        //			throw new CheaterException("", e);
        //		}
        //	}
        //
        //	private int[] loadCardinalities(InputStreamReader isr) throws MaltChainedException {
        //		int[] cardinalities = null;
        //		try {
        //			final BufferedReader in = new BufferedReader(isr);
        //			String line;
        //			if ((line = in.readLine()) != null) {
        //				String[] items = line.split(",");
        //				cardinalities = new int[items.length];
        //				for (int i = 0; i < items.length; i++) {
        //					cardinalities[i] = Integer.parseInt(items[i]);
        //				}
        //          }
        //			in.close();
        //		} catch (IOException e) {
        //			throw new CheaterException("", e);
        //		} catch (NumberFormatException e) {
        //			throw new CheaterException("", e);
        //		}
        //		return cardinalities;
        //	}

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void initSpecialParameters() throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual void initSpecialParameters()
        {
            if (Configuration.getOptionValue("singlemalt", "null_value") != null && Configuration.getOptionValue("singlemalt", "null_value").ToString().Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                excludeNullValues = true;
            }
            else
            {
                excludeNullValues = false;
            }
            saveCheatAction = ((bool?)Configuration.getOptionValue("cheater", "save_cheat_action")).Value;

            if (!Configuration.getOptionValue("cheater", "cheater_file").ToString().Equals(""))
            {
                cheaterFileName = Configuration.getOptionValue("cheater", "cheater_file").ToString();
            }
            if (Configuration.getOptionValue("liblinear", "verbosity") != null)
            {
                verbosity = Enum.Parse(typeof(Verbostity), Configuration.getOptionValue("cheater", "verbosity").ToString().ToUpper());
            }
        }
Пример #3
0
        /// <summary>
        /// Constructs a Lib learner.
        /// </summary>
        /// <param name="owner"> the guide model owner </param>
        /// <param name="learnerMode"> the mode of the learner BATCH or CLASSIFY </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Lib(org.maltparser.parser.guide.instance.InstanceModel owner, System.Nullable<int> learnerMode, String learningMethodName) throws org.maltparser.core.exception.MaltChainedException
        public Lib(InstanceModel owner, int?learnerMode, string learningMethodName)
        {
            this.owner       = owner;
            this.learnerMode = learnerMode.Value;
            name             = learningMethodName;
            if (Configuration.getOptionValue("lib", "verbosity") != null)
            {
                verbosity = Enum.Parse(typeof(Verbostity), Configuration.getOptionValue("lib", "verbosity").ToString().ToUpper());
            }
            else
            {
                verbosity = Verbostity.SILENT;
            }
            NumberOfInstances = 0;
            if (Configuration.getOptionValue("singlemalt", "null_value") != null && Configuration.getOptionValue("singlemalt", "null_value").ToString().Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                excludeNullValues = true;
            }
            else
            {
                excludeNullValues = false;
            }

            if (learnerMode.Value == LearningMethod_Fields.BATCH)
            {
                featureMap     = new FeatureMap();
                instanceOutput = new StreamWriter(getInstanceOutputStreamWriter(".ins"));
            }
            else if (learnerMode.Value == LearningMethod_Fields.CLASSIFY)
            {
                featureMap = (FeatureMap)getConfigFileEntryObject(".map");
            }
            else
            {
                featureMap = null;
            }
        }