i construct clause after series of steps. instance, if verify condition assert part of clause. if "the pen red" obtain:
color(pen, red) if "the pen on table":
on(pen, table) if "the table blue":
color(table, blue) at end have get:
color(pen, red), on(pen, table), color(table,blue). i insert final clause in external file. how can do?
edit:
i insert text similar above , deduct these separate predicate:
first color(pen,red), second on(pen,table), third color(table,blue)
i obtain clause :
text(t1):- color(pen, red), on(pen, table), color(table,blue). and clause must inserted in file.
input: single predicate. output: 1 clause predicates.
i'd attack problem dcgs.
sentence(s) --> color_statement(s) ; on_statement(s). det --> [a]. det --> [the]. color_statement(color(noun, color)) --> det, [noun], [is], color(color). color(color) --> [color], { color(color) }. color(red). color(blue). on_statement(on(noun, place)) --> det, [noun], [is,on], det, [place]. this assuming have kind of tokenization in place, demo purposes, you'll find "works":
?- phrase(sentence(s), [the,pen,is,on,the,bookshelf]). s = on(pen, bookshelf). you no doubt need extend these rules purposes. can find tokenization stuff searching, , know kinds of nouns , modifiers want support, sketch of how proceed.
from here you're going create rule handle multiple statements.
clause([]) --> []. clause([s|rest]) --> sentence(s), ['.'], clause(rest). testing works so:
?- phrase(clause(s), [the,pen,is,on,the,bookshelf,'.',the,pen,is,red,'.']). s = [on(pen, bookshelf), color(pen, red)] so these clauses want. need predicate bring them together.
list_and([x,y], (x,y)). list_and([x|xs], (x,rest)) :- list_and(xs, rest). clause_for(name, tokens, predicate) :- phrase(clause(parts), tokens), list_and(parts, andsequence), predicate = (name :- andsequence). this want, need furnish name predicate:
?- clause_for(bob, [the,pen,is,on,the,bookshelf,'.',the,pen,is,red,'.'], p). p = (bob:-on(pen, bookshelf), color(pen, red)) hope helps!
Comments
Post a Comment