图 DB 与 Prolog(或 miniKanren) [英] A graph DB vs a Prolog (or miniKanren)

查看:23
本文介绍了图 DB 与 Prolog(或 miniKanren)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在研究像 Neo4j 这样的图形数据库以及 Prolog 和 miniKanren 中的逻辑编程.根据我到目前为止所学到的,既可以指定事实和它们之间的关系,也可以查询结果系统以获取某些选择.所以,实际上我看不出它们之间有多大区别,因为它们都可以用来构建图形和查询它,但使用不同的语法.但是,它们以完全不同的软件形式呈现.

Recently I have been looking into graph databases like Neo4j and into logic programming in Prolog and miniKanren. From what I have learned so far, both allow specifying facts and relations between them, and also querying the resulting system for some selections. So, actually I cannot see much difference between them in that they both can be used to build a graph and query it, but using different syntax. However, they are presented as totally different kinds of software.

除了技术上,数据库可能会提出一种时空效率更高的存储技术,除了像迷你看人这样的微小逻辑内核更简单和可嵌入之外,图数据库和逻辑编程语言之间的实际区别是什么,如果它们都只是图数据库+查询API?

Except the technicality that databases maybe propose a more space-time effective storage technology, and except that tiny logic cores like miniKanren are simpler and embeddable, what is the actual difference between graph databases and logic programming languages, if they are both just a graph database + query API?

推荐答案

不,那些东西所体现的逻辑编程和neo4j是完全不同的.

No, logic programming as embodied by those things and neo4j are quite different.

在一个层面上,您是对的,它们在概念上都相当于图存储和图查询.但是对于逻辑编程,它只是概念上的图查询,不能保证它实际上是这样存储的(neo4j 就是这样).

On one level, you're right that they conceptually both amount to graph storage and graph query. But for logic programming, it's only conceptually graph query, there's no guarantee that it's actually stored that way (where with neo4j, it is).

其次,通过逻辑编程,您通常会尝试建立 horn 子句,以便您对大量数据进行推理.您可以将 horn 从句视为一个简单的规则,例如如果一个人是男性,并且是亲生孩子的直系祖先,则意味着该人是父亲".在带有 neo4j 的 cypher 中,您将描述您希望匹配的图形模式,从而生成数据,例如:

Second, with logic programming you're usually trying to establish horn clauses that allow you to reason through lots of data. You can think of a horn clause as a simple rule, like "If a person is male, and is the direct ancestor of a biological child, that implies that person is a father". In cypher with neo4j, you would describe a graph pattern you wish to match, that results in data, e.g.:

 MATCH (p:Person)-[:father*]->(maleAncestor:Person)
 RETURN maleAncestor

这告诉通过父亲关系遍历图,并返回男性祖先.在逻辑编程语言中,您不会这样做.您可以指定 ab 的父亲意味着 a 是男性,而 a 是其祖先b.对于所有有效的 a/b 配对,这将隐式和传递性地说明.那么你会问一个问题,谁是男性祖先"?然后编程环境将通过利用您的规则来回答这个问题.这将具有构建数据遍历的效果,这与我上面指定的密码非常相似,但是您理解数据和构建该遍历的方式完全不同.

This tells to traverse the graph by father relationships, and return male ancestors. In a logic programming language, you wouldn't do it this way. You might specify that a being a father of b means that a is male, and a is an ancestor of b. This would implicitly and transitively state that for all valid a/b pairings. Then you'd ask a question, "who are the male ancestors"? The programming environment would then answer that by exploiting your rules. That would have the effect of building a traversal through the data that's very similar to the cypher I specified above, but the way you go about understanding your data and building that traversal is totally different.

逻辑编程语言通常通过谓词解析工作.像 cypher 这样的图形查询语言通过模式匹配和显式路径指定的组合来工作.它们非常不同.

Logic programming languages usually work via predicate resolution. A graph query language like cypher works by a combination of pattern matching, and explicit path designation. They're very different.

这篇关于图 DB 与 Prolog(或 miniKanren)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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