English 中文(简体)
Prolog 中的 DCG( 限定条款语法)
原标题:DCG(Definite clause grammar) in Prolog

我试图在质询中做一个 DCG, 这样我就可以根据一些前提做出一个句子。 我有两部分信息 = 物体的属性 (“ 查尔斯是男人 ” ), 物体之间的关系 ( “ 查尔斯是威廉的父亲 ” ) 。

任务就是创建像这样的句子

[charles,is,a,man]
[camilla,is,a,woman]
[camilla,is,the,wife,of,charles]
[charles,is,the,father,of,william]
[charles,is,the,husband,of,camilla]

我可以创建一个简单的DCG, 它可以产生句子, 但我可以如何执行关系 使主题(Charles, camilla, charles) 对应的上游部分( 男性, 女性)?

问题回答

您可以将DCG 规则与Prolog 方案前置规则合并如下:

rpn --> [RPN], {rpn(RPN)}.   /* relative pronoun */
rpn(that).
rpn(which).
rpn(who).

例如,J.R.Fisher的辅导

zdanie --> person, " ", iss, " ", animal, ".".

 man --> "adam" or "john".
women --> "eve" or "travolta".
iss --> "is".
animal --> "dog" or "cat" or "bird".

sentence(Z) :-
   phrase(zdanie, [I|R]),
   code_type(I, to_lower(J)),
   atom_codes(Z, [0  , J|R]).

诸如此类。





相关问题
Reserved keywords in Objective-C?

At the CocoaHeads Öresund meeting yesterday, peylow had constructed a great ObjC quiz. The competition was intense and three people were left with the same score when the final question was to be ...

ANTLR grammar license [closed]

I m planning to make an implementation of Lua for the DLR, and i would like to use the listed Lua 5.1 grammar here. However i can t see a license that it was released under, so can someone please ...

Does anyone recognise this unfamiliar notation?

I have a question from a test in a Programming Languages class that is confusing me. Give a context-free grammar to generate the following language L = { aibjck | 0 <= i <= j <= i + k } I ...

Question about building a symbol table with a yacc parser

If my yacc parser encounters the following code: int foo(int a, int b) should it add int a and int b as attributes of foo? The way I have it now, it enters a and b as separate table entries.

Tips on Using Bison --graph=[file] on Linux

Recently (about a month ago) I was trying to introduce new constructs to my company s in-house extension language, and struggling with a couple of reduce-reduce errors. While I eventually solved this ...

Yacc program not recognizing function declaration

I think my program should be able to recognize the following as a function declaration: int fn(int i) { int n; return; } but it doesn t. Here s the relevant part of my yacc file: program : ...

Grammars, Scala Parsing Combinators and Orderless Sets

I m writing an application that will take in various "command" strings. I ve been looking at the Scala combinator library to tokenize the commands. I find in a lot of cases I want to say: "These ...

What s the matter with this Grammar?

grammar Test; IDHEAD: ( a .. z | A .. Z | _ ); IDTAIL: (IDHEAD | 0 .. 9 ); ID: (IDHEAD IDTAIL*); fragment TYPE: ( text | number | bool ); define: define ID as TYPE; The problem ...

热门标签