Suppose you get in input a description of a graph, something like "A is near B" and you want to update your knowledge base.
Using Prolog I've decided to use this solution:
:- dynamic edge/2.
store(Desc):- Desc=[A,is,near,B],
assert(edge(A,B)),
write(A-B).
store(Desc):- Desc=[A,is,near,B,that,is,near,C],
write(A-B),nl,
write(B-C),
assert(edge(A,B)),
assert(edge(B,C)).
I'd like to extend the parsing to potential infinite sentences, like: '1 is near 2 that is near 3 that is near 4 etc', so what I'd like to do is something like (Idea expressed in pseudocode-like-notation):
procedure store(Sentence)
begin
foreach 'X is near Y' in Sentence assert edge(X,Y).
foreach 'X that is near Y' in Sentence assert edge(X,Y).
end
How can I achieve this in Prolog?
extract_edges(Sentence, Edges)first instead of working directly with the database. It would be easier to implement and easier to trace / debug also. - Tudor Berariu