Lucene.Net.Analysis.Synonym.WordnetSynonymParser.Parse C# (CSharp) Метод

Parse() публичный Метод

public Parse ( TextReader.TextReader @in ) : void
@in System.IO.TextReader.TextReader
Результат void
        public override void Parse(TextReader @in)
        {
            int lineNumber = 0;
            TextReader br = @in;
            try
            {
                string line = null;
                string lastSynSetID = "";
                CharsRef[] synset = new CharsRef[8];
                int synsetSize = 0;


                while ((line = br.ReadLine()) != null)
                {
                    lineNumber++;
                    string synSetID = line.Substring(2, 9);

                    if (!synSetID.Equals(lastSynSetID))
                    {
                        AddInternal(synset, synsetSize);
                        synsetSize = 0;
                    }

                    if (synset.Length <= synsetSize + 1)
                    {
                        CharsRef[] larger = new CharsRef[synset.Length * 2];
                        Array.Copy(synset, 0, larger, 0, synsetSize);
                        synset = larger;
                    }

                    synset[synsetSize] = ParseSynonym(line, synset[synsetSize]);
                    synsetSize++;
                    lastSynSetID = synSetID;
                }

                // final synset in the file
                AddInternal(synset, synsetSize);
            }
            catch (System.ArgumentException e)
            {
                throw new Exception("Invalid synonym rule at line " + lineNumber.ToString(), e);
            }
            finally
            {
                br.Dispose();
            }
        }

Usage Example

        public virtual void TestSynonyms()
        {
            WordnetSynonymParser parser = new WordnetSynonymParser(true, true, new MockAnalyzer(Random()));
            parser.Parse(new StringReader(synonymsFile));
            SynonymMap map = parser.Build();

            Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(this, map);

            /* all expansions */
            AssertAnalyzesTo(analyzer, "Lost in the woods", new string[] { "Lost", "in", "the", "woods", "wood", "forest" }, new int[] { 0, 5, 8, 12, 12, 12 }, new int[] { 4, 7, 11, 17, 17, 17 }, new int[] { 1, 1, 1, 1, 0, 0 });

            /* single quote */
            AssertAnalyzesTo(analyzer, "king", new string[] { "king", "baron" });

            /* multi words */
            AssertAnalyzesTo(analyzer, "king's evil", new string[] { "king's", "king's", "evil", "meany" });
        }
All Usage Examples Of Lucene.Net.Analysis.Synonym.WordnetSynonymParser::Parse