示例#1
0
        static Word populateWords(string root)
        {
            if(words.ContainsKey(root) == false)
            {
                Word rootWord = new Word();
                words.Add(root, rootWord);
                rootWord.word = root;

                string rootDefinition = definitionsForWord(root);

                //rootWord.definition = rootDefinition;
                List<string> subDefinitionStrings = allSubDefinitionsFromDefinition(rootDefinition);

                rootWord.subDefinitions = new List<SubDefinition>();
                rootWord.appearsInDefinitionFor = new List<Word>();

                foreach(string subDefinitionString in subDefinitionStrings)
                {
                    SubDefinition subDefinition = new SubDefinition();
                    subDefinition.subDefinition = subDefinitionString;
                    List<string> nounStrings = allNounsFromDefinition(subDefinitionString);

                    rootWord.subDefinitions.Add(subDefinition);

                    subDefinition.nouns = new List<Word>();

                    foreach(string nounString in nounStrings)
                    {
                        Word noun = populateWords(nounString);
                        noun.appearsInDefinitionFor.Add(rootWord);
                        subDefinition.nouns.Add(noun);
                    }
                }

                return rootWord;
            }
            else
            {
                return words[root];
            }
        }
示例#2
0
        //goes through the definition and pulls out all the nouns and their parent subdefinitions
        //returns in the order of how rare the noun is, i.e. how little it appears in the
        //definitions of other words, (excluding the words that have already been used)
        static List<NounDefinitionPair> nounDefinitionPairsOrderedByRarity(Word noun, HashSet<string> usedNouns)
        {
            //we will get better time complexity if we return a unique list of nouns
            HashSet<string> uniqueSubNouns = new HashSet<string>();

            List<NounDefinitionPair> pairs = new List<NounDefinitionPair>();

            foreach (SubDefinition subDefinition in noun.subDefinitions)
            {
                foreach (Word subNoun in subDefinition.nouns)
                {
                    if (uniqueSubNouns.Contains(subNoun.word))
                    {
                        continue;
                    }

                    uniqueSubNouns.Add(subNoun.word);

                    NounDefinitionPair pair = new NounDefinitionPair();

                    pair.definition = subDefinition;
                    pair.noun = subNoun;
                    pairs.Add(pair);
                }
            }

            pairs = pairs.OrderBy(p => p.noun.numAppearsInDefinitionsForExcludingThese(usedNouns)).ToList();

            return pairs;
        }