dcg

Prolog DCG set_prolog_flag double_quotes source code directive location matters; documentation?

痴心易碎 提交于 2019-12-05 09:56:22
I learned the hard way that with SWI-Prolog the location for the Prolog directive set_prolog_flag matters in a source code file. The only documentation I found of value about loading source code files with directives was in Loading Prolog source files A directive is an instruction to the compiler. Directives are used to set (predicate) properties (see section 4.15), set flags (see set_prolog_flag/2) and load files (this section). Directives are terms of the form :- <term>. Is there documentation for SWI-Prolog that covers loading of source code that notes if a directive applies to the entire

Prolog - Palindrome Functor

情到浓时终转凉″ 提交于 2019-12-05 08:41:15
I am trying to write a predicate palindrome/1 in Prolog that is true if and only if its list input consists of a palindromic list. for example: ?- palindrome([1,2,3,4,5,4,3,2,1]). is true. Any ideas or solutions? A palindrome list is a list which reads the same backwards, so you can reverse the list to check whether it yields the same list: palindrome(L):- reverse(L, L). Looks that everybody is voting for a reverse/2 based solution. I guess you guys have a reverse/2 solution in mind that is O(n) of the given list. Something with an accumulator: reverse(X,Y) :- reverse(X,[],Y). reverse([],X,X).

How to convert prolog parse tree back to a logical sentence

天大地大妈咪最大 提交于 2019-12-04 07:24:35
I managed to build the parse tree for given sentence and here it is, for the sentence: "The man went home." T = s(np(det(the), n(man)), vp(v(went), np(n(home)))) 1) How to use phrase/2 on this? How to translate a sentence in a logical language using prolog? - is similar to what I need, but it's solution doesn't work on me. 2)I want to map this with grammar pattern and get the words tag. Det=the , N(Subject)=man , V=went , N(Object)=home Is there a way to map this tree with given set tree structures and identify the grammar. how can I use parse tree to identify Subject, verb, object, the

Prolog- translating English to C

那年仲夏 提交于 2019-12-04 05:06:55
问题 We have a relatively simple assignment that I understand in theory but I think I just don't quite understand Prolog's syntax enough to get that into code. Basically, we have a list of English notations that represent operations in C. They're stored as a list when they're passed to our Prolog program. For example: add 4 to 3 is [add, 4, to, 3] We need to write a function that takes that list an returns the equivalent. So if I called english2C([add,4,to,3], C). C = 4+3 It would bind C to the

Read input in prolog and print result

不羁的心 提交于 2019-12-03 23:05:24
问题 I am learning Prolog ideas and here is what I want to practice: I want to write a Prolog program that can work like this: ?- input([apple,is,fruit]). ?- input([chicken,is,meat]). ?- input([Is,apple,meat]). No, it is a fruit ?- input[(Is,chicken,meat]) Yes. And when I was trying to implement this program, I got some problem: (1) I used this code trying to read the input and distinguish between questions and assertions, but it fails: input([]). input([X|R]) :- X is 'Is', write('test code read

What are good starting points for someone interested in natural language processing? [closed]

天涯浪子 提交于 2019-12-03 00:02:00
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Question So I've recently came up with some new possible projects that would have to deal with deriving 'meaning' from text submitted

Prolog, error when querying a false statement

六月ゝ 毕业季﹏ 提交于 2019-12-02 20:26:36
问题 input :- read_line_to_codes(user_input, Input), string_to_atom(Input,Atoms), atomic_list_concat(Alist, ' ', Atoms), phrase(sentence(S), Alist), action(S). statement(Rule) --> [Noun, 'is', 'a', Object], { Rule =.. [Object, Noun]}. statement1(Rule) --> ['A', Noun, 'is', 'a', Object], { Rule =.. [Object, Noun]}. query(Fact) --> ['Is', Noun, 'a', Object], { Fact =.. [Object, Noun]}. sentence(statement(S)) --> statement(S). sentence(statement1(S))--> statement1(S). sentence(query(Q)) --> query(Q).

Prolog DCG with arguments

纵然是瞬间 提交于 2019-12-02 18:17:17
问题 I can't figure out how to work with DCGs using arguments. Suppose we want to use DCGs to represent parents and their children, we could then say: father --> [Peter]. mother --> [Isabel]. child --> [Guido]. child --> [Claudia]. verb --> [is]. relation --> [father, of]. relation --> [mothter, of]. s --> father, verb, relation, child. s --> mother, verb, relation, child. You can then query by: ?- s([Peter, is, father, of, Guido], []). Which returns true . How can I use arguments on the DCGs by

What are good starting points for someone interested in natural language processing? [closed]

Deadly 提交于 2019-12-02 13:48:24
Question So I've recently came up with some new possible projects that would have to deal with deriving 'meaning' from text submitted and generated by users. Natural language processing is the field that deals with these kinds of issues, and after some initial research I found the OpenNLP Hub and university collaborations like the attempto project . And stackoverflow has this . If anyone could link me to some good resources, from reseach papers and introductionary texts to apis, I'd be happier than a 6 year-old kid opening his christmas presents! Update Through one of your recommendations I've

Prolog DCG with arguments

≯℡__Kan透↙ 提交于 2019-12-02 10:56:00
I can't figure out how to work with DCGs using arguments. Suppose we want to use DCGs to represent parents and their children, we could then say: father --> [Peter]. mother --> [Isabel]. child --> [Guido]. child --> [Claudia]. verb --> [is]. relation --> [father, of]. relation --> [mothter, of]. s --> father, verb, relation, child. s --> mother, verb, relation, child. You can then query by: ?- s([Peter, is, father, of, Guido], []). Which returns true . How can I use arguments on the DCGs by saying perhaps father(name) . Adding the arguments is easy and I would not be surprised if you did it as