Prolog 计算实际唯一标识符 [英] Prolog Count The Unique Identifiers In Fact

查看:51
本文介绍了Prolog 计算实际唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有事实

研究(cse,plc).研究(cse,da).研究(它,se).研究(它,PLC).

其中 Studies(x,y) 表示分支 x 研究模块 y .现在我想定义规则来计算所有模块的数量.就像这里将是 3.that are (plc,da,se).PLZ HELP.

查询 CSE 下有多少科目的查询是什么.

解决方案

已经标记了 SWI-Prolog 你的问题,看看 library(聚合):

?-aggregate(count, Module, Branch^studies(Branch, Module), N).N = 3.

library(aggregate) 很强大,学习它真的很有收获...<​​/p>

We have facts

studies(cse, plc).
studies(cse, da). 
studies(it, se). 
studies(it, plc).  

where studies(x,y) means that branch x studies module y . Now I Want to define Rule To count number of modules in all. like here it will be 3.that are (plc,da,se).PLZ HELP.

What will be the query to find how many subjects studies under CSE.

解决方案

having tagged SWI-Prolog your question, take a look at library(aggregate):

?- aggregate(count, Module, Branch^studies(Branch, Module), N).
N = 3.

library(aggregate) is powerful, learning about it can be really rewarding...

这篇关于Prolog 计算实际唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆