简体   繁体   English

n-ary是否可以预测Datomic(n!= 2)?

[英]Are n-ary predicates Datomic (n != 2) possible?

I try to match what I read about Datalog with the descriptions of Datomic. 我尝试将我读到的Datalog与Datomic的描述相匹配。 All predicats I see in Datomic are triples, ie [entity attribute value] or attribute(e,v) in a more prologian syntax. 我在Datomic中看到的所有谓词都是三元组,即[实体属性值]或属性(e,v)中的更多prologian语法。 Datalog on the other hand supports n-ary predicates like pred(a,b,c,d). 另一方面,Datalog支持像pred(a,b,c,d)这样的n-ary谓词。

How shall I match this? 我该如何匹配呢?

  1. Do I miss a feature of Datomic, ie does it have n-ary predicates, or can I model them somehow? 我是否会错过Datomic的一个功能,即它是否具有n-ary谓词,还是可以以某种方式对它们进行建模?
  2. Is Datomics Datalog a restricted version of what is usually called Datalog? Datomics Datalog是通常称为Datalog的限制版本吗?

The n-ary predicates in traditional Datalog are actually similar to tables in relational databases. 传统Datalog中的n-ary谓词实际上与关系数据库中的表类似。 So for example the following line would add information about a person in a traditional Datalog system: 因此,例如,以下行将添加有关传统Datalog系统中人员的信息:

assert Person("John", "Smith", "1985-01-01")

Notice that the only thing that tells you that the 3rd value is the date of birth is it's position in the predicate. 请注意,唯一告诉您第3个值是出生日期的是它在谓词中的位置。

Datomic does not use free-form predicates like this to store the data. Datomic不使用这样的自由形式谓词来存储数据。 It uses Datalog strictly on the query side. 它严格在查询端使用Datalog。 To represent something like our person above in Datomic you would need to create three attributes. 要在Datomic中表示类似我们上面的人,您需要创建三个属性。 You could call the attributes: :person/first-name , :person/last-name , :person/dob (note that :person/ is just part of the name, it doesn't actually create any kind of structure or table-like thing). 你可以调用属性:: :person/first-name:person/last-name:person/dob (注意:person/只是名称的一部分,它实际上并不创建任何类型的结构或表格 -喜欢的事)。

Each attribute needs to be installed using the transact function before you can use it. 需要先使用transact函数安装每个属性,然后才能使用它。 Here's an example of what you need to send to transact for :person/last-name 以下是您需要发送以进行交易的示例:person/last-name

[{:db/id #db/id[:db.part/db]
  :db/ident :person/last-name
  :db/valueType :db.type/string
  :db/cardinality :db.cardinality/one
  :db/fulltext true
  :db/doc "A person's last name"
  :db.install/_attribute :db.part/db}]

You can find more details in Datomic's documentation: http://docs.datomic.com/schema.html 您可以在Datomic的文档中找到更多详细信息: http ://docs.datomic.com/schema.html

Once you have the attributes you can add the same information we started with by transacting the following: 获得属性后,您可以通过交易以下内容添加我们开始使用的相同信息:

[{:db/id #db/id[:db.part/user]
:person/first-name "John"
:person/last-name "Smith"
:person/dob "1985-01-01"}]

So the short answer is: no Datomic doesn't do n-ary predicates on the input side but there's nothing you can represent in an n-ary predicate that can't be represented in Datomic. 所以简短的回答是:没有Datomic不会在输入端执行n-ary谓词,但是在无法在Datomic中表示的n-ary谓词中没有任何内容可以表示。 And the advantage is that now you have a named attribute instead of something that's only defined in terms of it's position in a predicate (that turns out to be very fragile in real-world systems: think about how to change schema for something like that). 而且好处是现在你有一个命名属性,而不是只根据它在谓词中的位置定义的东西(在现实世界的系统中结果非常脆弱:考虑如何更改类似的东西的模式) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM