Esempio n. 1
0
        private static void ProcessSystemVerbs(ILanguage language)
        {
            Assembly           commandsAssembly = Assembly.GetAssembly(typeof(CommandParameterAttribute));
            IEnumerable <Type> loadedCommands   = commandsAssembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(ICommand)));

            foreach (Type comm in loadedCommands)
            {
                IEnumerable <string> commandVerbs = comm.GetCustomAttributes <CommandKeywordAttribute>().Where(att => !att.PreventBecomingAVerb).Select(att => att.Keyword);

                foreach (string verb in commandVerbs)
                {
                    Dictata newVerb = new Dictata()
                    {
                        Name        = verb,
                        Determinant = false,
                        Feminine    = false,
                        Plural      = false,
                        Positional  = LexicalPosition.None,
                        Perspective = NarrativePerspective.None,
                        Possessive  = false,
                        Tense       = LexicalTense.Present,
                        Semantics   = new HashSet <string>()
                        {
                            "system_command"
                        },
                        WordType = LexicalType.Verb,
                        Language = language
                    };

                    LexicalProcessor.VerifyLexeme(newVerb.GetLexeme());
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Put it in the cache
        /// </summary>
        /// <returns>success status</returns>
        public override bool PersistToCache()
        {
            try
            {
                LexicalContext collectiveContext = new LexicalContext(null)
                {
                    Determinant = true,
                    Perspective = NarrativePerspective.ThirdPerson,
                    Plural      = false,
                    Position    = LexicalPosition.None,
                    Tense       = LexicalTense.Present
                };

                List <IDictata> dictatas = new List <IDictata>
                {
                    new Dictata(new Lexica(LexicalType.ProperNoun, GrammaticalType.Subject, Name, collectiveContext))
                };
                dictatas.AddRange(Descriptives.Select(desc => desc.Event.GetDictata()));

                foreach (IDictata dictata in dictatas)
                {
                    LexicalProcessor.VerifyLexeme(dictata.GetLexeme());
                }

                TemplateCache.Add(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex, LogChannels.SystemWarnings);
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            TextReader       reader = Console.In;
            LexicalProcessor lexer  = null;

            try
            {
                if (args.Length > 0)
                {
                    if (args[0].ToLowerInvariant().Equals("-h"))
                    {
                        PrintUsage();
                    }
                    reader = new StreamReader(args[0]);
                }

                lexer = new LexicalProcessor(reader);
                while (lexer.Read())
                {
                    LexicalToken token = lexer.Current;
                    buffer.Text(ConsoleColor.DarkYellow, String.Format("[{0}]", GetEnumName(token.Type)));

                    if (!String.IsNullOrEmpty(token.Value))
                    {
                        buffer.Text(" ")
                        .Text(ConsoleColor.DarkGray, "\'")
                        .Text(token.Value)
                        .Text(ConsoleColor.DarkGray, "\'");
                    }

                    if (token.Tag != null)
                    {
                        buffer.Text(" ")
                        .Text(ConsoleColor.DarkGray, "\'")
                        .Text(token.Tag.ToString())
                        .Text(ConsoleColor.DarkGray, "\'");
                    }

                    buffer.Line();
                }
            }
            catch (Exception ex) {
                Exception e = ex;
                while (e != null)
                {
                    buffer.Error(String.Format("sharplex: {0} ({1})", e.Message, e.GetType().Name));
                    e = ex.InnerException;
                }

                if (lexer != null)
                {
                    buffer.Error(String.Format("\t at line {0}, column {1}", lexer.Line, lexer.Column));
                }

                Environment.Exit(Math.Min(-ex.GetHashCode(), -1));
            }
        }
Esempio n. 4
0
        public Lexica(LexicalType type, GrammaticalType role, string phrase, IEntity origin, IEntity observer)
        {
            Type   = type;
            Phrase = phrase;
            Role   = role;

            Modifiers = new HashSet <ILexica>();

            LexicalProcessor.VerifyLexeme(this);
            Context = BuildContext(origin, observer);
        }
Esempio n. 5
0
        public Lexica(LexicalType type, GrammaticalType role, string phrase, LexicalContext context)
        {
            Type   = type;
            Phrase = phrase;
            Role   = role;

            Modifiers = new HashSet <ILexica>();

            LexicalProcessor.VerifyLexeme(this);
            Context = context.Clone();
        }
Esempio n. 6
0
        private bool DeepLex()
        {
            FillLanguages();

            foreach (IDictata dict in WordForms)
            {
                LexicalProcessor.GetSynSet(dict);
            }

            //We've been mapped, set it and save the state
            IsSynMapped = true;
            PersistToCache();
            SystemSave();

            //We return false to break the loop
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Map the synnet of this word
        /// </summary>
        public bool MapSynNet()
        {
            //Not a whole lot of point here
            if (IsSynMapped)
            {
                return(true);
            }

            foreach (IDictata dict in WordForms)
            {
                LexicalProcessor.GetSynSet(dict);
            }

            //We've been mapped, set it and save the state
            IsSynMapped = true;
            PersistToCache();
            SystemSave();

            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// Generate a new dictata from this
        /// </summary>
        /// <returns></returns>
        public IDictata GenerateDictata()
        {
            if (string.IsNullOrWhiteSpace(Phrase))
            {
                return(null);
            }

            Dictata dict = new Dictata(this);

            Lexeme lex = new Lexeme()
            {
                Name     = Phrase,
                Language = dict.Language
            };

            lex.AddNewForm(dict);

            LexicalProcessor.VerifyLexeme(lex);

            return(dict);
        }
Esempio n. 9
0
        private void EnsureDictionary()
        {
            if (!string.IsNullOrWhiteSpace(BaseWords.ArticleDeterminant))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.ArticleDeterminant,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.ArticleDeterminant,
                            Determinant = true,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Article,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.ArticleNonDeterminant))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.ArticleNonDeterminant,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.ArticleNonDeterminant,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Article,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.Conjunction))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.Conjunction,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.Conjunction,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Conjunction,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounFirstPersonPossessive))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.NeutralPronounFirstPersonPossessive,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.NeutralPronounFirstPersonPossessive,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.FirstPerson,
                            Possessive  = true,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Pronoun,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounFirstPersonSingular))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.NeutralPronounFirstPersonSingular,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.NeutralPronounFirstPersonSingular,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.FirstPerson,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Pronoun,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounSecondPersonPlural))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.NeutralPronounSecondPersonPlural,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.NeutralPronounSecondPersonPlural,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = true,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.SecondPerson,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Pronoun,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounSecondPersonPossessive))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.NeutralPronounSecondPersonPossessive,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.NeutralPronounSecondPersonPossessive,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.SecondPerson,
                            Possessive  = true,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Pronoun,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounSecondPersonSingular))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.NeutralPronounSecondPersonSingular,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.NeutralPronounSecondPersonSingular,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.SecondPerson,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Pronoun,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.VerbExistentialPlural))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.VerbExistentialPlural,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.VerbExistentialPlural,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = true,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Semantics   = new HashSet <string>()
                            {
                                "existential"
                            },
                            Tense    = LexicalTense.Present,
                            WordType = LexicalType.Verb,
                            Language = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.VerbExistentialSingular))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.VerbExistentialSingular,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.VerbExistentialSingular,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.None,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Semantics   = new HashSet <string>()
                            {
                                "existential"
                            },
                            Tense    = LexicalTense.Present,
                            WordType = LexicalType.Verb,
                            Language = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionAround))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.PrepositionAround,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.PrepositionAround,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.Around,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            WordType    = LexicalType.Preposition,
                            Tense       = LexicalTense.None,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionAttached))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.PrepositionAttached,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.PrepositionAttached,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.Attached,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Preposition,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionFar))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.PrepositionFar,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.PrepositionFar,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.Far,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Preposition,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionInside))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.PrepositionInside,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.PrepositionInside,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.InsideOf,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Preposition,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionNear))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.PrepositionNear,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.PrepositionNear,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.Near,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Preposition,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionOn))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.PrepositionOn,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.PrepositionOn,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.On,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Preposition,
                            Language    = this
                        }
                    }
                });
            }

            if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionOf))
            {
                LexicalProcessor.VerifyLexeme(new Lexeme()
                {
                    Name      = BaseWords.PrepositionOf,
                    Language  = this,
                    WordForms = new IDictata[] {
                        new Dictata()
                        {
                            Name        = BaseWords.PrepositionOf,
                            Determinant = false,
                            Feminine    = false,
                            Plural      = false,
                            Positional  = LexicalPosition.PartOf,
                            Perspective = NarrativePerspective.None,
                            Possessive  = false,
                            Tense       = LexicalTense.None,
                            WordType    = LexicalType.Preposition,
                            Language    = this
                        }
                    }
                });
            }
        }
Esempio n. 10
0
        public static void PreloadSupportingEntities()
        {
            //Load the "config" data first
            ConfigData.LoadEverythingToCache();

            LexicalProcessor.LoadWordnet();

            IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld));

            //We dont move forward without a global config
            if (globalConfig == null)
            {
                globalConfig = new GlobalConfig();

                globalConfig.SystemSave();
            }

            if (globalConfig.BaseLanguage == null)
            {
                ILanguage baseLanguage = ConfigDataCache.GetAll <ILanguage>().FirstOrDefault();

                if (baseLanguage == null)
                {
                    LoggingUtility.Log("There are no valid languages. Generating new base language.", LogChannels.SystemErrors, true);

                    baseLanguage = new Language()
                    {
                        Name = "English",
                        GoogleLanguageCode     = "en-us",
                        AntecendentPunctuation = true,
                        PrecedentPunctuation   = false,
                        Gendered = false,
                        UIOnly   = true
                    };

                    baseLanguage.SystemSave();
                }

                globalConfig.BaseLanguage = baseLanguage;
                globalConfig.SystemSave();
            }

            //Ensure we have base words for the language every time
            globalConfig.BaseLanguage.SystemSave();

            //Hoover up all the verbs from commands that someone might have coded
            ProcessSystemVerbs(globalConfig.BaseLanguage);

            IGossipConfig   gossipConfig = ConfigDataCache.Get <IGossipConfig>(new ConfigDataCacheKey(typeof(IGossipConfig), "GossipSettings", ConfigDataType.GameWorld));
            HttpApplication instance     = HttpContext.Current.ApplicationInstance;
            Assembly        asm          = instance.GetType().BaseType.Assembly;
            Version         v            = asm.GetName().Version;

            //We dont move forward without a global config
            if (gossipConfig == null)
            {
                gossipConfig = new GossipConfig
                {
                    ClientName = "Warrens: White Sands"
                };
            }

            //Update version
            gossipConfig.Version = string.Format(CultureInfo.InvariantCulture, @"{0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision);
            gossipConfig.SystemSave();

            //Load structural data next
            Templates.LoadEverythingToCache();

            HotBackup hotBack = new HotBackup();

            //Our live data restore failed, reload the entire world from backing data
            if (!hotBack.RestoreLiveBackup())
            {
                hotBack.NewWorldFallback();
            }

            if (gossipConfig.GossipActive)
            {
                Func <Member[]> playerList = () => LiveCache.GetAll <IPlayer>()
                                             .Where(player => player.Descriptor != null && player.Template <IPlayerTemplate>().Account.Config.GossipSubscriber)
                                             .Select(player => new Member()
                {
                    Name           = player.AccountHandle,
                    WriteTo        = (message) => player.WriteTo(new string[] { message }),
                    BlockedMembers = player.Template <IPlayerTemplate>().Account.Config.Acquaintences.Where(acq => !acq.IsFriend).Select(acq => acq.PersonHandle),
                    Friends        = player.Template <IPlayerTemplate>().Account.Config.Acquaintences.Where(acq => acq.IsFriend).Select(acq => acq.PersonHandle)
                }).ToArray();

                void exceptionLogger(Exception ex) => LoggingUtility.LogError(ex);
                void activityLogger(string message) => LoggingUtility.Log(message, LogChannels.GossipServer);

                GossipClient gossipServer = new GossipClient(gossipConfig, exceptionLogger, activityLogger, playerList);

                Task.Run(() => gossipServer.Launch());

                LiveCache.Add(gossipServer, "GossipWebClient");
            }

            Func <bool> backupFunction            = hotBack.WriteLiveBackup;
            Func <bool> backingDataBackupFunction = Templates.WriteFullBackup;

            //every 30 minutes after half an hour
            Processor.StartSingeltonChainedLoop("HotBackup", 30 * 60, 30 * 60, -1, backupFunction);

            //every 2 hours after 1 hour
            Processor.StartSingeltonChainedLoop("BackingDataFullBackup", 60 * 60, 120 * 60, -1, backingDataBackupFunction);
        }
Esempio n. 11
0
        /*
         * TODO: Wow this is inefficient, maybe clean up how many loops we do
         */
        private IEnumerable <IDictata> ParseAction(IList <Tuple <string, bool> > words, bool push, IDictata lastSubject)
        {
            /*
             * I kick the can
             * kick the can
             * kicks the can
             * kick the red can
             * kick the large red can
             */
            List <IDictata> returnList = new List <IDictata>();

            Dictionary <string, IDictata> brandedWords = BrandWords(words);

            IDictata currentVerb = null;

            //Find unknown nouns potentially with conjunctions
            foreach ((KeyValuePair <string, IDictata> value, int i)item in brandedWords.Where(ctx => ctx.Value == null).Select((value, i) => (value, i)).OrderByDescending(keypair => keypair.i))
            {
                KeyValuePair <string, IDictata> value = item.value;
                int index = item.i;

                if (index < brandedWords.Count() - 1 && index > 0)
                {
                    IDictata wordAfter  = brandedWords.ElementAt(index + 1).Value;
                    IDictata wordBefore = brandedWords.ElementAt(index - 1).Value;

                    if (wordBefore != null && wordBefore.WordType == LexicalType.Adverb && wordAfter != null && wordAfter.WordType == LexicalType.Verb)
                    {
                        brandedWords[value.Key] = new Dictata()
                        {
                            Name = value.Key, WordType = LexicalType.Adverb
                        };
                        continue;
                    }

                    if ((wordBefore != null && (wordBefore.WordType == LexicalType.Adjective) || wordBefore.WordType == LexicalType.Article) &&
                        (wordAfter != null && (wordAfter.WordType == LexicalType.Noun) || wordAfter.WordType == LexicalType.ProperNoun))
                    {
                        brandedWords[value.Key] = new Dictata()
                        {
                            Name = value.Key, WordType = LexicalType.Adjective
                        };
                        continue;
                    }

                    continue;
                }

                if (index < brandedWords.Count() - 1)
                {
                    IDictata wordAfter = brandedWords.ElementAt(index + 1).Value;

                    if (wordAfter != null && wordAfter.WordType == LexicalType.Noun)
                    {
                        brandedWords[value.Key] = new Dictata()
                        {
                            Name = value.Key, WordType = LexicalType.Adjective
                        };
                        continue;
                    }

                    if (wordAfter != null && wordAfter.WordType == LexicalType.Verb)
                    {
                        brandedWords[value.Key] = new Dictata()
                        {
                            Name = value.Key, WordType = LexicalType.Adverb
                        };
                        continue;
                    }
                }

                if (index > 0)
                {
                    IDictata wordBefore = brandedWords.ElementAt(index - 1).Value;

                    if (wordBefore != null && (wordBefore.WordType == LexicalType.Article || wordBefore.WordType == LexicalType.Adjective))
                    {
                        brandedWords[value.Key] = new Dictata()
                        {
                            Name = value.Key, WordType = LexicalType.Noun
                        };
                        continue;
                    }

                    if (wordBefore != null && wordBefore.WordType == LexicalType.Adverb)
                    {
                        brandedWords[value.Key] = new Dictata()
                        {
                            Name = value.Key, WordType = LexicalType.Verb
                        };
                        continue;
                    }
                }
            }

            //No verb?
            if (!brandedWords.Any(ctx => ctx.Value != null && ctx.Value.WordType == LexicalType.Verb))
            {
                string verbWord = brandedWords.First(ctx => ctx.Value == null).Key;

                currentVerb = new Dictata()
                {
                    Name = verbWord, WordType = LexicalType.Verb
                };
                brandedWords[verbWord] = currentVerb;
            }
            else
            {
                currentVerb = brandedWords.FirstOrDefault(ctx => ctx.Value != null && ctx.Value.WordType == LexicalType.Verb).Value;
            }

            //We might have nouns already
            if (!brandedWords.Any(ctx => ctx.Value == null || (ctx.Value != null &&
                                                               (ctx.Value.WordType == LexicalType.Noun || ctx.Value.WordType == LexicalType.ProperNoun))))
            {
                bool lastSubjectReplaced = false;
                if (lastSubject != null)
                {
                    List <string> keyList = new List <string>();
                    foreach (KeyValuePair <string, IDictata> word in brandedWords.Where(ctx => ctx.Value != null && ctx.Value.WordType == LexicalType.Pronoun))
                    {
                        keyList.Add(word.Key);
                        lastSubjectReplaced = true;
                    }

                    foreach (string key in keyList)
                    {
                        brandedWords[key] = (IDictata)lastSubject.Clone();
                    }
                }

                if (!lastSubjectReplaced)
                {
                    string targetWord = string.Empty;

                    //No valid nouns to make the target? Pick the last one
                    if (!brandedWords.Any(ctx => ctx.Value == null))
                    {
                        targetWord = brandedWords.LastOrDefault().Key;
                    }
                    else
                    {
                        targetWord = brandedWords.LastOrDefault(ctx => ctx.Value == null).Key;
                    }

                    brandedWords[targetWord] = new Dictata()
                    {
                        Name = targetWord, WordType = LexicalType.Noun
                    };
                }
            }

            List <IDictata> descriptors = new List <IDictata>();

            foreach ((KeyValuePair <string, IDictata> value, int i)item in brandedWords.Where(ctx => ctx.Value == null).Select((value, i) => (value, i)))
            {
                KeyValuePair <string, IDictata> value = item.value;
                int index = item.i;

                LexicalType wordType = LexicalType.Adjective;
                if (index == brandedWords.Count() - 1)
                {
                    IDictata wordAfter = brandedWords.ElementAt(index + 1).Value;

                    if (wordAfter != null)
                    {
                        if (wordAfter.WordType == LexicalType.Verb)
                        {
                            wordType = LexicalType.Adverb;
                        }

                        if (wordAfter.WordType == LexicalType.Pronoun)
                        {
                            wordType = LexicalType.Article;
                        }
                    }
                }

                descriptors.Add(new Dictata()
                {
                    Name = value.Key, WordType = wordType
                });
            }

            //Add the nonadjectives and the adjectives
            returnList.AddRange(brandedWords.Where(bws => bws.Value != null).Select(bws => bws.Value));
            returnList.AddRange(descriptors.Select(desc => desc));

            if (push)
            {
                foreach (IDictata item in returnList)
                {
                    LexicalProcessor.VerifyLexeme(item.GetLexeme());
                }
            }

            return(returnList);
        }
Esempio n. 12
0
        private void EnsureDictionary()
        {
            Lexeme collective = new Lexeme()
            {
                Name      = Collective,
                WordForms = new IDictata[] {
                    new Dictata()
                    {
                        Name        = Collective,
                        Determinant = false,
                        Feminine    = Feminine,
                        Plural      = true,
                        Positional  = LexicalPosition.None,
                        Perspective = NarrativePerspective.None,
                        Possessive  = false,
                        Tense       = LexicalTense.None,
                        Semantics   = new HashSet <string>()
                        {
                            "gender"
                        },
                        WordType = LexicalType.Pronoun
                    }
                }
            };

            Lexeme possessive = new Lexeme()
            {
                Name      = Possessive,
                WordForms = new IDictata[] {
                    new Dictata()
                    {
                        Name        = Possessive,
                        Determinant = false,
                        Feminine    = Feminine,
                        Plural      = false,
                        Positional  = LexicalPosition.None,
                        Perspective = NarrativePerspective.None,
                        Possessive  = true,
                        Tense       = LexicalTense.None,
                        Semantics   = new HashSet <string>()
                        {
                            "gender"
                        },
                        WordType = LexicalType.Pronoun
                    }
                }
            };

            Lexeme baseWord = new Lexeme()
            {
                Name      = Base,
                WordForms = new IDictata[] {
                    new Dictata()
                    {
                        Name        = Base,
                        Determinant = false,
                        Feminine    = Feminine,
                        Plural      = false,
                        Positional  = LexicalPosition.None,
                        Perspective = NarrativePerspective.None,
                        Possessive  = false,
                        Tense       = LexicalTense.None,
                        Semantics   = new HashSet <string>()
                        {
                            "gender"
                        },
                        WordType = LexicalType.Pronoun
                    }
                }
            };

            Lexeme adult = new Lexeme()
            {
                Name      = Adult,
                WordForms = new IDictata[] {
                    new Dictata()
                    {
                        Name        = Adult,
                        Determinant = false,
                        Feminine    = Feminine,
                        Plural      = false,
                        Positional  = LexicalPosition.None,
                        Perspective = NarrativePerspective.None,
                        Semantics   = new HashSet <string>()
                        {
                            "adult", "gender"
                        },
                        Possessive = false,
                        Tense      = LexicalTense.None,
                        WordType   = LexicalType.Noun
                    }
                }
            };

            Lexeme child = new Lexeme()
            {
                Name      = Child,
                WordForms = new IDictata[] {
                    new Dictata()
                    {
                        Name        = Child,
                        Determinant = false,
                        Feminine    = Feminine,
                        Plural      = false,
                        Positional  = LexicalPosition.None,
                        Perspective = NarrativePerspective.None,
                        Semantics   = new HashSet <string>()
                        {
                            "child", "gender"
                        },
                        Possessive = false,
                        Tense      = LexicalTense.None,
                        WordType   = LexicalType.Noun
                    }
                }
            };

            LexicalProcessor.VerifyLexeme(child);
            LexicalProcessor.VerifyLexeme(adult);
            LexicalProcessor.VerifyLexeme(baseWord);
            LexicalProcessor.VerifyLexeme(possessive);
            LexicalProcessor.VerifyLexeme(collective);
        }