Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void parseRules(Iterable<String> rules, SlowSynonymMap map, String mappingSep, String synSep, boolean expansion, TokenizerFactory tokFactory) throws java.io.IOException
        internal static void parseRules(IEnumerable <string> rules, SlowSynonymMap map, string mappingSep, string synSep, bool expansion, TokenizerFactory tokFactory)
        {
            int count = 0;

            foreach (string rule in rules)
            {
                // To use regexes, we need an expression that specifies an odd number of chars.
                // This can't really be done with string.split(), and since we need to
                // do unescaping at some point anyway, we wouldn't be saving any effort
                // by using regexes.

                IList <string> mapping = splitSmart(rule, mappingSep, false);

                IList <IList <string> > source;
                IList <IList <string> > target;

                if (mapping.Count > 2)
                {
                    throw new System.ArgumentException("Invalid Synonym Rule:" + rule);
                }
                else if (mapping.Count == 2)
                {
                    source = getSynList(mapping[0], synSep, tokFactory);
                    target = getSynList(mapping[1], synSep, tokFactory);
                }
                else
                {
                    source = getSynList(mapping[0], synSep, tokFactory);
                    if (expansion)
                    {
                        // expand to all arguments
                        target = source;
                    }
                    else
                    {
                        // reduce to first argument
                        target = new List <>(1);
                        target.Add(source[0]);
                    }
                }

                bool includeOrig = false;
                foreach (IList <string> fromToks in source)
                {
                    count++;
                    foreach (IList <string> toToks in target)
                    {
                        map.add(fromToks, SlowSynonymMap.makeTokens(toToks), includeOrig, true);
                    }
                }
            }
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: static void parseRules(Iterable<String> rules, SlowSynonymMap map, String mappingSep, String synSep, boolean expansion, TokenizerFactory tokFactory) throws java.io.IOException
        internal static void parseRules(IEnumerable<string> rules, SlowSynonymMap map, string mappingSep, string synSep, bool expansion, TokenizerFactory tokFactory)
        {
            int count = 0;
            foreach (string rule in rules)
            {
              // To use regexes, we need an expression that specifies an odd number of chars.
              // This can't really be done with string.split(), and since we need to
              // do unescaping at some point anyway, we wouldn't be saving any effort
              // by using regexes.

              IList<string> mapping = splitSmart(rule, mappingSep, false);

              IList<IList<string>> source;
              IList<IList<string>> target;

              if (mapping.Count > 2)
              {
            throw new System.ArgumentException("Invalid Synonym Rule:" + rule);
              }
              else if (mapping.Count == 2)
              {
            source = getSynList(mapping[0], synSep, tokFactory);
            target = getSynList(mapping[1], synSep, tokFactory);
              }
              else
              {
            source = getSynList(mapping[0], synSep, tokFactory);
            if (expansion)
            {
              // expand to all arguments
              target = source;
            }
            else
            {
              // reduce to first argument
              target = new List<>(1);
              target.Add(source[0]);
            }
              }

              bool includeOrig = false;
              foreach (IList<string> fromToks in source)
              {
            count++;
            foreach (IList<string> toToks in target)
            {
              map.add(fromToks, SlowSynonymMap.makeTokens(toToks), includeOrig, true);
            }
              }
            }
        }