I have some problems with a list structure in swi-prolog.
rlTopic([
[
[noun], % find match for this
[
[
grammar([noun],1), % use one of this
grammar([det,noun],1)
],
[
noun(fox,1), % fill one of the grammars
det(the,1), % with these words
noun(cat,1)
]
]
],
[
[det,adj,noun],
[
[
grammar([verb,adj],1), % use one of this
grammar([det,noun],1)
],
[
det(the,1), % fill one of the grammars
adj(quick,1), % with these words
noun(cat,1),
verb(ran,1)
]
]
],
....
I try to find a match (from input) with the [noun]
. After this, get one of the grammars in the next level and match them with the words. Finding the grammars works fine right now, but I have problems to insert the words to the grammar.
My code right now:
get_keyword(KeyList, [KeyList,_]).
get_response(RespList, [_, RespList]).
find_grammar([Grammars,Words],AtomGrammar):-
is_list(Grammars),
find_grammar(Grammars,AtomGrammar),!;
AtomGrammar = Grammars.
find_grammar(_,_).
find_match(Input, [FirstRecord|RestDatabase], ListOfResponse):-
get_keyword(Keyword, FirstRecord),
Keyword == Input, get_response(ListOfResponse, FirstRecord), !;
find_match(Input, RestDatabase, ListOfResponse).
find_match(_, [_], _).
test(Input):-
rlTopic(ListOfRecord),
find_match(Input, ListOfRecord, ListOfResponse),
find_grammar(ListOfResponse,G).
For the input test([det,adj,noun])
, the output should one of the grammars filled with the words, like run quick
.
Thanks in advance!