- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前有一个包含几个人和一些关系谓词的小型 Prolog 数据库。例如:
female(anna).
female(susan).
male(john).
male(timmy).
siblings(anna, susan).
siblings(anna, john).
siblings(susan, john).
sibling(X, Y) :- siblings(X, Y) ; siblings(Y, X).
%X is brother of Y
brother(X, Y) :- male(X), sibling(X, Y).
question --> ip, verb, article, noun, pronoun, name.
noun(X, name).
brother(X, anna).
"the brother of anna is john"
最佳答案
从 DCG 调用 Prolog 谓词
常规方式:使用{}/1
使用非终结符 {}//1
从 DCG 中调用任意 Prolog 目标。
例如:
verb --> [V], { verb(V) }.
verb//1
.此 DCG 描述了一个由元素
V
组成的列表。使得
verb(V)
持有,其中
verb/1
是一个普通的 Prolog 谓词。
female(anna) --> [].
female(susan) --> [].
male(john) --> [].
male(timmy) --> [].
term_expansion/2
自动执行此类转换的规则。
{}/1
可能更可取,因为您已经拥有现有的 Prolog 事实和。但是在某些情况下,最好始终使用 DCG。
brother(X, susan)
相关联。 .您已经有一个非终结符
sentence//0
描述这样的句子。你只需要明确这些句子对应的目标。例如:
sentence_goal(noun(X, name)) --> ip, v, a, noun, p, name.
This is only used to illustrate the principle; I'm not claiming that this is already the full solution. The point is simply to show that you can reason about Prolog goals in exactly the same way as about all other terms.
You can then invoke the actual goals in two phases:
sentence_goal//1
call/1
or invoking it directly.For example:
?- phrase(sentence_goal(Goal), Sentence), Goal.
brother_of/2
等等。
write/1
)!相反,专注于描述
关系 在句子和目标之间,让 Prolog 顶层为您打印。
关于Prolog:从 DCG 生成查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36673733/
这个答案:Very basic dcg prolog syntax对我有一点帮助,但 [X] 只能得到下一个字符,我想要整个辣酱 Jade 米饼馅,继续阅读! 我正在使用 GNU Prolog 编写一
在此 site ,我找到了解释如何使用 DCG 构建右手上下文符号的部分 A → ε | a A Head, [T_1,...,T_n] --> Body. 有人帮助我通过示例找出这种方法并说明它解析
我知道 Prolog 程序员通常使用 DCG 而不是正则表达式来匹配字符串中的模式。在 Perl 中,可以这样写 if ( '... accd' =~ /a+b*c{2,4}d$/ ) { s
我在创建问答 Prolog 文件时遇到问题。我有一个包含位置的数据库,我已经可以得到问题并写出答案。但是有不同类型的对象,需要不同的前缀。所以我为前缀定义了 DCG。 answer(P,A) :- l
我有两个人的 DCG 句子,分别代表一个男性和一个女性。我想用“他”或“她”来指代前一句中提到的人。 假设我们有这些 DCG: father --> [Peter]. mother --> [Isab
假设我将“a-list”称为零个或多个“a”的列表: % as = [a,a,a] as --> []. as --> [a], as. 假设我想表示一个“b-list”,一个由零个或多个 a-lis
我有一个手动制定的 DCG 规则来选择惯用短语超过单个单词。 DCG规则如下: seq(cons(X,Y), I, O) :- noun(X, I, H), seq(Y, H, O), \+ noun
我正在玩 DCG,我有这段代码。这将显示 x 个 0 和 x 个 A。 y --> test(Count), as(Count). test(0) --> []. test(succ(0)) -->
你好,我是 Prolog 和 DGC 的新手。我想编写一个 DCG 来解析时间表达式,例如 10.20 am 或 12 oclock。我如何检查 10.20 am 对于 Olcock 是否是有效表达式
最近我一直在 Prolog 中使用 DCG,但我一直面临一些关于它究竟如何工作的问题。例如,我有这个小语法: :: | :: | | | :: 'a' | 'b' ... |'Z
我开始学习如何使用 DCG。我想知道花括号 {...} 的用途是什么?何时(何时不)需要它们?例如: read_lines --> { read_line_to_codes(current_inp
我正在尝试为一个有效号码指定一个 DCG,该号码将像这样使用: value(Number) --> valid_number(Number). 基本上检查一个指定的值是否是数字,(它也可能是一个变量,
假设我想编写一个自定义运算符,用于以重复的方式编写 DCG 规则。 例如,假设我有一个 DCG,ws使得: ws --> []. ws --> " ", ws. 匹配零个或多个空格。显然,如果我想在我
我在 SWI Prolog 中编写了一个程序来测试字符串是否是回文。 DCG 中的这个任务我能够弄清楚,而且非常简单。 palindrome --> [X], palindrome, [X]. pa
所以我正在使用 Definite Clause Grammars 在 SWI-Prolog 中为 Pascal 编写一个简单的解析器。 我不明白如何实现重复(2 个或更多)或可选地重复(1 个或更多)
我正在构建一个明确的从句语法来解析 20,000 条半自然文本。随着我的谓词数据库的大小增长(现在多达 1,200 条规则),解析一个字符串可能需要相当长的时间——特别是对于 DCG 当前无法解释的字
在我看来,应该能够使用字节列表上的 DCG 处理二进制数据。但是,要使其正常工作,必须使用按位运算,这意味着 is/2涉及,这意味着实例化顺序是一个问题,这可能会混淆使用 DCG 进行解析和生成。这里
我目前有一个包含几个人和一些关系谓词的小型 Prolog 数据库。例如: female(anna). female(susan). male(john). male(timmy). siblings(
我正在为查询引擎编写一个解析器。我的解析器 DCG 查询 不是确定性的。 我将以关系方式使用解析器来检查和综合查询。 解析器 DCG 不具有确定性是否合适? 在代码中: 如果我希望能够以两种方式使用
我需要使用 swi-prolog 中的规则拆分二氯戊烷这就是我尝试做的 stem--> [meth]|[eth]|[prop]|[but]|[pent]. suf --> [ane]|[ene]|[y
我是一名优秀的程序员,十分优秀!