Esempio n. 1
0
        /// <summary>
        /// Verify the dictionary has this word already
        /// </summary>
        /// <param name="lexica">lexica to check</param>
        public static void VerifyLexeme(ILexica lexica)
        {
            if (lexica == null || string.IsNullOrWhiteSpace(lexica.Phrase) || lexica.Phrase.IsNumeric())
            {
                //we dont want numbers getting in the dict, thats bananas
                return;
            }

            VerifyLexeme(lexica.GetDictata().GetLexeme());
        }
Esempio n. 2
0
        /// <summary>
        /// Does this lexica match the rule
        /// </summary>
        /// <param name="word">The lex</param>
        /// <returns>if it matches</returns>
        public bool Matches(ILexica lex)
        {
            string[] fromBegins = FromBeginsWith.Split('|', StringSplitOptions.RemoveEmptyEntries);
            string[] fromEnds   = FromEndsWith.Split('|', StringSplitOptions.RemoveEmptyEntries);

            return((fromBegins.Count() == 0 || fromBegins.Any(bw => lex.Phrase.StartsWith(bw))) &&
                   (fromEnds.Count() == 0 || fromEnds.Any(bw => lex.Phrase.EndsWith(bw))) &&
                   (Tense == LexicalTense.None || lex.Context.Tense == Tense) &&
                   (Perspective == NarrativePerspective.None || lex.Context.Perspective == Perspective) &&
                   (!WhenPlural || lex.Context.Plural) &&
                   (!WhenPossessive || lex.Context.Possessive) &&
                   (SpecificWord == null || SpecificWord.Equals(lex.GetDictata())) &&
                   (SpecificWord != null || ((FromRole == GrammaticalType.None || FromRole == lex.Role) && (FromType == LexicalType.None || FromType == lex.Type))));
        }
Esempio n. 3
0
        /// <summary>
        /// Verify the dictionary has this word already
        /// </summary>
        /// <param name="lexica">lexica to check</param>
        public static void VerifyLexeme(ILexica lexica)
        {
            if (string.IsNullOrWhiteSpace(lexica.Phrase) || lexica.Phrase.IsNumeric())
            {
                //we dont want numbers getting in the dict, thats bananas
                return;
            }

            //Experiment: make new everything
            if (VerifyLexeme(lexica.GetDictata().GetLexeme()) != null)
            {
                //make a new one
                lexica.GenerateDictata();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Unpack the lexica
        /// </summary>
        public IEnumerable <ISensoryEvent> Unpack()
        {
            List <Tuple <ISensoryEvent, int> > wordList = new List <Tuple <ISensoryEvent, int> >();

            //Subject
            foreach (Tuple <ISensoryEvent, short> lex in Subject.OrderBy(pair => pair.Item2))
            {
                IEnumerable <ILexica> lexes = lex.Item1.Event.Unpack(lex.Item1.SensoryType, lex.Item1.Strength);

                int i = (lex.Item2 * 100) + -10000;
                foreach (ILexica subLex in lexes)
                {
                    wordList.Add(new Tuple <ISensoryEvent, int>(new SensoryEvent(subLex, lex.Item1.Strength, lex.Item1.SensoryType), i++));
                }
            }

            //Predicate
            foreach (Tuple <ISensoryEvent, short> lex in Predicate.OrderBy(pair => pair.Item2))
            {
                IEnumerable <ILexica> lexes = lex.Item1.Event.Unpack(lex.Item1.SensoryType, lex.Item1.Strength);

                int i = (lex.Item2 + 1) * 100;
                foreach (ILexica subLex in lexes)
                {
                    wordList.Add(new Tuple <ISensoryEvent, int>(new SensoryEvent(subLex, lex.Item1.Strength, lex.Item1.SensoryType), i++));
                }
            }

            //Modifiers
            foreach (Tuple <ISensoryEvent, short> lex in Modifiers.OrderBy(pair => pair.Item2))
            {
                IEnumerable <ILexica> lexes = lex.Item1.Event.Unpack(lex.Item1.SensoryType, lex.Item1.Strength);

                int i = (lex.Item2 * 100) + 10000;
                foreach (ILexica subLex in lexes)
                {
                    wordList.Add(new Tuple <ISensoryEvent, int>(new SensoryEvent(subLex, lex.Item1.Strength, lex.Item1.SensoryType), i++));
                }
            }

            //Transformational word pair rules
            foreach (IDictataTransformationRule rule in Language.TransformationRules.Where(rul => rul.TransformedWord != null && wordList.Any(pair => rul.Origin.Equals(pair.Item1.Event.GetDictata()))))
            {
                string[] beginsWith = rule.BeginsWith.Split('|', StringSplitOptions.RemoveEmptyEntries);
                string[] endsWith   = rule.EndsWith.Split('|', StringSplitOptions.RemoveEmptyEntries);

                foreach (Tuple <ISensoryEvent, int> lexPair in wordList.Where(pair => rule.Origin.Equals(pair.Item1.Event.GetDictata())))
                {
                    ILexica lex = lexPair.Item1.Event;
                    Tuple <ISensoryEvent, int> nextEvent = wordList.OrderBy(word => word.Item2).FirstOrDefault(word => word.Item2 > lexPair.Item2);

                    if (nextEvent == null)
                    {
                        continue;
                    }

                    ILexica nextLex = nextEvent.Item1.Event;
                    if ((rule.SpecificFollowing == null || nextLex.GetDictata().Equals(rule.SpecificFollowing)) &&
                        (beginsWith.Count() == 0 || beginsWith.Any(bw => nextLex.Phrase.StartsWith(bw))) &&
                        (endsWith.Count() == 0 || endsWith.Any(ew => nextLex.Phrase.EndsWith(ew))))
                    {
                        lex.Phrase = rule.TransformedWord.Name;
                    }
                }
            }

            return(wordList.OrderBy(words => words.Item2).Select(words => words.Item1));
        }