Natural Language Processing
![]() Currently I've only implemented a chart parser that can create multiple parse trees from ambiguous sentences. The algorithm for the chart parser can be found in chapter 23 of "Artificial Intelligence: A Modern Approach (AIMA)" by Stuart Russell and Peter Norvig. I extended it so the different parse trees can be used separately. What was implemented:
Remarks
Sample use
void PrintParseTrees(CNLPParseForest &ParseForest)
{
for (int Index=0; Index<ParseForest.GetParseTreeCount(); Index++)
{
CNLPParseTree *ParseTree = ParseForest.GetParseTree(Index);
printf("%s\n\n", ParseTree->ToString().GetBuffer());
}
}
void Parse(void)
{
CNLPModel Model;
CNLPParseForest ParseForest;
// load a grammar
Model.AddGrammarRules("resources/grammar_english_thoughtreasure.txt");
// load a lexicon
Model.AddLexicalEntries("resources/lexicon_english_nouns.txt", "Noun");
Model.AddLexicalEntries("resources/lexicon_english_articles.txt", "Article");
Model.AddLexicalEntries("resources/lexicon_english_pronouns.txt", "Pronoun");
Model.AddLexicalEntries("resources/lexicon_english_verbs.txt", "Verb");
Model.AddLexicalEntries("resources/lexicon_english_adverbs.txt", "Adverb");
Model.AddLexicalEntries("resources/lexicon_english_adjectives.txt", "Adjective");
Model.AddLexicalEntries("resources/lexicon_english_determiners.txt", "Det");
Model.AddLexicalEntries("resources/lexicon_english_conjunctions.txt", "Conjunction");
// parse sentences and create and print the parse trees
Model.Parse("I feel a breeze.", ParseForest);
PrintParseTrees(ParseForest);
Model.Parse("fall leaves fall and spring leaves spring.", ParseForest);
PrintParseTrees(ParseForest);
Model.Parse("I think therefore I am.", ParseForest);
PrintParseTrees(ParseForest);
}
Links
|