Exemple #1
0
 private void MakeWordOfShortInput(ModuleUKS2 UKS, List <Thing> phrase, List <Thing> words)
 {
     if (phrase.Count < maxPhonemesPerWord)
     {
         if (UKS.ReferenceMatch(phrase, words) == null)
         {
             UKS.AddThing("w" + wordCount++, UKS.Labeled("Word"), null, phrase.ToArray());
         }
     }
 }
Exemple #2
0
        //this searches the current input stream to see if any known words match
        //then it builds a list of all possible phrases which can be made from known words and leaves unknown phonemes in place
        //this addresses the problem of words which incorporate other words and word splits which may be ambiguous;
        // Ann, Can, Cant
        private void FindPossibleWords(ModuleUKS2 UKS, List <Thing> phrase)
        {
            possiblePhrases.Clear();
            List <Thing> words         = UKS.GetChildren(UKS.Labeled("Word"));
            List <Thing> inputPhrase   = CopyList(phrase);
            List <Thing> possibleWords = new List <Thing>();

            //find all possible words then see if combinations can fill the phrase?
            for (int i = 0; i < inputPhrase.Count; i++)
            {
                //the order here is important as it interacts with the next loop
                for (int j = inputPhrase.Count - i; j > 0; j--)
                {
                    List <Thing> phonemeSequence = inputPhrase.GetRange(i, j);
                    Thing        foundWord       = UKS.ReferenceMatch(phonemeSequence, words);
                    if (foundWord != null)
                    {
                        if (!possibleWords.Contains(foundWord))
                        {
                            possibleWords.Add(foundWord);
                        }
                    }
                }
            }

            //replace a sequence of phonemes in the phrase with a word
            //failures are words we found which can't be put in phrase in combiination with others
            //that's why we end up with multiple candidate phrases
            List <Thing> failures = new List <Thing>();

            possibleWords = possibleWords.OrderByDescending(x => x.References.Count).ToList();
            foreach (Thing word in possibleWords)
            {
                if (!ReplaceWordInPhrase(inputPhrase, word))
                {
                    failures.Add(word);
                }
            }
            possiblePhrases.Add(inputPhrase);
            foreach (Thing word in failures)
            {
                inputPhrase = CopyList(phrase);
                ReplaceWordInPhrase(inputPhrase, word);
                foreach (Thing word1 in possibleWords)
                {
                    ReplaceWordInPhrase(inputPhrase, word1);
                }
                possiblePhrases.Add(inputPhrase);
            }
        }
Exemple #3
0
        private Thing AddPhrase(ModuleUKS2 UKS, List <Thing> bestPhrase)
        {
            //see if the phrase already exists and add it if not
            Thing phraseFound = UKS.ReferenceMatch(bestPhrase, UKS.GetChildren(UKS.Labeled("Phrase")));

            if (phraseFound == null)// && bestPhrase.Count > 1)
            {
                phraseFound = UKS.AddThing("ph" + phraseCount++, UKS.Labeled("Phrase"), null, bestPhrase.ToArray());
            }
            foreach (Thing t in bestPhrase)
            {
                t.useCount++;
            }
            if (phraseFound != null)
            {
                phraseFound.useCount++;
            }
            return(phraseFound);
        }
Exemple #4
0
 private void ExtendWordsWithSinglePhonemes(ModuleUKS2 UKS, List <Thing> bestPhrase, List <Thing> words)
 {
     //if the phrase contains any single phonemes, append/prepend them to adjascent words
     for (int i = 0; i < bestPhrase.Count; i++)
     {
         if (bestPhrase[i].Parents[0] == UKS.Labeled("Phoneme"))
         {
             bool preceeding = false;
             bool following  = false;
             if (i == 0 || bestPhrase[i - 1].Parents[0] == UKS.Labeled("Word"))
             {
                 preceeding = true;
             }
             if (i == bestPhrase.Count - 1 || bestPhrase[i + 1].Parents[0] == UKS.Labeled("Word"))
             {
                 following = true;
             }
             if (preceeding && following)
             {
                 //create new word merged with preceeding word
                 Thing newWordExtended  = null;
                 Thing newWordPrepended = null;
                 if (i != 0)
                 {
                     Thing        baseWord = bestPhrase[i - 1];
                     List <Thing> newRefs  = new List <Thing>();
                     foreach (Link l in baseWord.References)
                     {
                         newRefs.Add(l.T);
                     }
                     newRefs.Add(bestPhrase[i]);
                     Thing t = UKS.ReferenceMatch(newRefs, words);
                     if (t == null)
                     {
                         newWordExtended = UKS.AddThing("w" + wordCount++, UKS.Labeled("Word"), null, newRefs.ToArray());
                     }
                 }
                 //create new word merged with following word
                 if (i != bestPhrase.Count - 1)
                 {
                     Thing        baseWord = bestPhrase[i + 1];
                     List <Thing> newRefs  = new List <Thing>();
                     newRefs.Add(bestPhrase[i]);
                     foreach (Link l in baseWord.References)
                     {
                         newRefs.Add(l.T);
                     }
                     Thing t = UKS.ReferenceMatch(newRefs, words);
                     if (t == null)
                     {
                         newWordPrepended = UKS.AddThing("w" + wordCount++, UKS.Labeled("Word"), null, newRefs.ToArray());
                     }
                 }
                 if (newWordExtended != null)
                 {
                     bestPhrase.RemoveRange(i - 1, 2);
                     bestPhrase.Insert(i - 1, newWordExtended);
                 }
                 else if (newWordPrepended != null)
                 {
                     bestPhrase.RemoveRange(i, 2);
                     bestPhrase.Insert(i, newWordPrepended);
                 }
             }
         }
     }
 }