Exemple #1
0
        public static void run(PhraseTable g)
        {
            Console.Out.WriteLine("Updating MAI...");
            PhraseTable.PhraseNode currNode;

            String text = FileOperations.readText(path);
            String[] textConvos = Regex.Split(text, "\r\n\r\n\r\n");

            String question = textConvos[0];
            String answers = textConvos[1];
            String[] answersLines = Regex.Split(answers, "\r\n\r\n");

            currNode = g.add(question, Regex.Split(answersLines[0], "\r\n")[0], Regex.Split(answersLines[0], "\r\n")[1]);

            for (int i = 1; i < answersLines.Length; i++)
            {
                String[] s = Regex.Split(answersLines[i], "\r\n");

                PhraseTable.PhraseNode toAdd = new PhraseTable.PhraseNode(s[0], s[1]);
                currNode.add(toAdd);
                currNode = toAdd;

            }

            // Write to the graph file
            FileOperations.ObjectToFile(g, mai.resPath);
            Console.Out.WriteLine("Done!");
        }
Exemple #2
0
        public virtual void TestFindMatches()
        {
            string      text        = "Who is Col. Jibril Rajoub";
            PhraseTable phraseTable = new PhraseTable();

            phraseTable.caseInsensitive = true;
            phraseTable.AddPhrases(phrases);
            IList <PhraseTable.PhraseMatch> matched = phraseTable.FindMatches(text, 2, 5, true);

            NUnit.Framework.Assert.IsTrue(matched != null);
            NUnit.Framework.Assert.AreEqual(2, matched.Count);
        }
Exemple #3
0
 public StringSequenceAnnotationPattern(Type textKey, IDictionary <IList <string>, object> targets, bool ignoreCase)
 {
     this.textKey = textKey;
     phraseTable  = new PhraseTable(false, ignoreCase, false);
     foreach (IList <string> target in targets.Keys)
     {
         phraseTable.AddPhrase(target, null, targets[target]);
         if (maxNodes < 0 || target.Count > maxNodes)
         {
             maxNodes = target.Count;
         }
     }
 }
Exemple #4
0
 public StringSequenceAnnotationPattern(Type textKey, ICollection <IList <string> > targets, bool ignoreCase)
 {
     this.textKey = textKey;
     phraseTable  = new PhraseTable(false, ignoreCase, false);
     foreach (IList <string> target in targets)
     {
         phraseTable.AddPhrase(target);
         if (maxNodes < 0 || target.Count > maxNodes)
         {
             maxNodes = target.Count;
         }
     }
 }
Exemple #5
0
        public virtual void TestPhraseTable()
        {
            PhraseTable phraseTable = new PhraseTable();

            phraseTable.normalize       = true;
            phraseTable.caseInsensitive = true;
            phraseTable.AddPhrases(phrases);
            IList <PhraseTable.PhraseMatch> matched = phraseTable.FindAllMatches(testText);

            NUnit.Framework.Assert.IsTrue(matched != null);
            NUnit.Framework.Assert.AreEqual(12, matched.Count);
            // Test lookup
            PhraseTable.Phrase p = phraseTable.LookupNormalized("COL.");
            NUnit.Framework.Assert.AreEqual("Col.", p.GetText());
        }
Exemple #6
0
        public virtual void TestIterator()
        {
            PhraseTable phraseTable = new PhraseTable();

            phraseTable.caseInsensitive = true;
            phraseTable.AddPhrases(phrases);
            ICollection <string> origPhrases = new HashSet <string>();

            Sharpen.Collections.AddAll(origPhrases, phrases);
            ICollection <string>             iteratedPhrases = new HashSet <string>();
            IEnumerator <PhraseTable.Phrase> iterator        = phraseTable.Iterator();

            while (iterator.MoveNext())
            {
                iteratedPhrases.Add(iterator.Current.GetText());
            }
            ICollection <string> intersection        = CollectionUtils.Intersection(origPhrases, iteratedPhrases);
            ICollection <string> inOrigNotInIterated = CollectionUtils.Diff(origPhrases, intersection);

            NUnit.Framework.Assert.IsTrue("In original but not in iterated: " + inOrigNotInIterated, inOrigNotInIterated.IsEmpty());
            ICollection <string> inIteratedNotInOrig = CollectionUtils.Diff(iteratedPhrases, intersection);

            NUnit.Framework.Assert.IsTrue("In iterated but not in original: " + inIteratedNotInOrig, inIteratedNotInOrig.IsEmpty());
        }