示例#1
0
        public override NLGElement BuildElement()
        {
            PartOfSpeechBuilder[] orderedPartsOfSpeech = GetElementsOfTypeInSubtree <PartOfSpeechBuilder>()
                                                         .OrderBy(child => child)
                                                         .ToArray();
            StringBuilder stringValue = new StringBuilder();

            for (int childIndex = 0; childIndex < orderedPartsOfSpeech.Length - 1; childIndex++)
            {
                AddPartOfSpeech(orderedPartsOfSpeech[childIndex]);
                stringValue.Append(" ");
            }
            AddPartOfSpeech(orderedPartsOfSpeech.Last());
            NominalModifier.val = stringValue.ToString();
            return(NominalModifier);

            void AddPartOfSpeech(PartOfSpeechBuilder partOfSpeech)
            {
                if (partOfSpeech is WordElementBuilder)
                {
                    WordElementBuilder eachWord = (WordElementBuilder)partOfSpeech;
                    stringValue.Append(eachWord.BuildWord().Base);
                }
            }
        }
示例#2
0
 private void SetWhWord(WordElementBuilder whWordBuilder)
 {
     if (WhWord != null)
     {
         throw new InvalidOperationException("Can't add multiple Wh words to a WhAdverbPhraseBuilder");
     }
     else
     {
         WhWord = whWordBuilder;
     }
 }
 /// <summary>Set <paramref name="complementizer"/> as the ONLY complementizer of the subordinate clause we're going to build.</summary>
 /// <remarks>If we already have a complementizer and try to add another one, throw an exception.  Visibility is not private because the
 /// Complementizer can be set by a Wh word phrase during its Configuration.</remarks>
 internal void SetComplementizer(WordElementBuilder complementizer)
 {
     if (Complementizers.Count() == 0)
     {
         AddChildWithRole(complementizer, ChildRole.Complementizer);
     }
     else
     {
         throw new InvalidOperationException("Can't add multiple coordinators to a subordinate clause");
     }
 }
示例#4
0
 public override void Consolidate()
 {
     if (WhWord != null)
     {
         if (Parent is SubordinateClauseBuilder subordinateClause)
         {
             subordinateClause.SetComplementizer(WhWord);
             WhWord = null;
         }
     }
     if (Children.Count() == 0) Become(null);
     else BecomeNounPhrase();
 }
示例#5
0
        /// <summary>Based on a bunch of weird irregular rules of mostly phonology, decide whether this indefinite article should be "a" or "an"</summary>
        /// <param name="followingWordBuilder">The word that comes after this article</param>
        private static string AppropriateIndefiniteArticleToPrecede(WordElementBuilder followingWordBuilder)
        {
            if (followingWordBuilder == null)
            {
                return("a");
            }
            else
            {
                string followingWord = followingWordBuilder.SelectWord();

                var lowercaseWord = followingWord.ToLower();
                foreach (string anword in new string[] { "euler", "heir", "honest", "hono" })
                {
                    if (lowercaseWord.StartsWith(anword))
                    {
                        return("an");
                    }
                }

                if (lowercaseWord.StartsWith("hour") && !lowercaseWord.StartsWith("houri"))
                {
                    return("an");
                }

                if (lowercaseWord.StartsWith("one ") || lowercaseWord.StartsWith("one-"))
                {
                    return("a");
                }

                var char_list = new char[] { 'a', 'e', 'd', 'h', 'i', 'l', 'm', 'n', 'o', 'r', 's', 'x' };
                if (lowercaseWord.Length == 1)
                {
                    if (lowercaseWord.IndexOfAny(char_list) == 0)
                    {
                        return("an");
                    }
                    else
                    {
                        return("a");
                    }
                }

                if (Regex.Match(followingWord, "(?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z]").Success)
                {
                    return("an");
                }

                foreach (string regex in new string[] { "^e[uw]", "^onc?e\b", "^uni([^nmd]|mo)", "^u[bcfhjkqrst][aeiou]" })
                {
                    if (Regex.IsMatch(lowercaseWord, regex))
                    {
                        return("a");
                    }
                }

                if (Regex.IsMatch(followingWord, "^U[NK][AIEO]"))
                {
                    return("a");
                }
                else if (followingWord == followingWord.ToUpper())
                {
                    if (lowercaseWord.IndexOfAny(char_list) == 0)
                    {
                        return("an");
                    }
                    else
                    {
                        return("a");
                    }
                }

                if (lowercaseWord.IndexOfAny(new char[] { 'a', 'e', 'i', 'o', 'u' }) == 0)
                {
                    return("an");
                }

                if (Regex.IsMatch(lowercaseWord, "^y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt)"))
                {
                    return("an");
                }

                return("a");
            }
        }