datalog

How to represent pivot table (with extra data on it) in datomic?

 ̄綄美尐妖づ 提交于 2020-06-01 05:29:09
问题 I realise that we don't need ordinary pivot tables in datomic because we can just pick one side of the relationship and put a :db.cardinality/many attribute on there (being sure to model the relationship in one direction only). The next thing I encounter in converting from sql is a pivot table that also stores an attribute on the relationship, like: series_subscriptions user_id int series_id int expires_at timestamp I was wondering what the options are to model this in datomic. I notice there

setof/3 inside setof/3 not working, but why?

泪湿孤枕 提交于 2020-03-22 09:00:26
问题 Inspired by Find mutual element in different facts in swi-prolog I wanted to try my hand at "RDBMS operations in Prolog" (actually, this is more or less Datalog) Problem statement Given a database of "actors starring in movies": starsin(a,bob). starsin(c,bob). starsin(a,maria). starsin(b,maria). starsin(c,maria). starsin(a,george). starsin(b,george). starsin(c,george). starsin(d,george). And given set of movies, find those actors that starred in all the movies of said set. I first had an ugly

DLV list composition

纵饮孤独 提交于 2020-01-17 12:37:46
问题 I was wondering if there is a way in DLV for creating a list with the elements of all predicates that are true in a rule. For example, if I have the following predicates foo(a, b). foo(a, c). foo(a, e). foo(b, c). The result I am looking for should be new predicates where the first element is the first parameter of foo and the second parameter should contain a list with all the elements associated to the first parameter. Empirically: bar(a, [b,c,e]). bar(b, [c]). I know there is a way of

ununderstandable behavior subprocess.Popen(cmd,stdout) and os.system(cmd)

拟墨画扇 提交于 2020-01-06 09:03:29
问题 I use an external command inside a python script using firstly: subprocess.Popen(cmd, stdout=subprocess.PIPE) then i get the stdout. The problem is that the result of this external command when executing it inside the script is not the same if i execute it directly in the command line. I use then os.system(cmd) , but the same problem. Is this instructions in python use some buffers? How can i explain the difference between the two results (command line and inside the script). I'm using this

ununderstandable behavior subprocess.Popen(cmd,stdout) and os.system(cmd)

 ̄綄美尐妖づ 提交于 2020-01-06 09:02:35
问题 I use an external command inside a python script using firstly: subprocess.Popen(cmd, stdout=subprocess.PIPE) then i get the stdout. The problem is that the result of this external command when executing it inside the script is not the same if i execute it directly in the command line. I use then os.system(cmd) , but the same problem. Is this instructions in python use some buffers? How can i explain the difference between the two results (command line and inside the script). I'm using this

Datomic aggregates usage

风流意气都作罢 提交于 2019-12-24 14:13:16
问题 I want to find persons with minimal age with next query (d/q '[:find ?name (min ?age) :in [[?name ?age]]] [["John" 20] ["Bill" 25] ["Jack" 20] ["Steve" 28] ["Andrew" 30]]) But result is [["Andrew" 30] ["Bill" 25] ["Jack" 20] ["John" 20] ["Steve" 28]] How to do that? 回答1: Instead of chaining the queries together, you could use a subquery (query call from within the query instead of outside of it): (d/q '[:find ?name ?mage :in $ :where [(datomic.api/q '[:find (min ?age) :where [_ :age ?age]] $)

How to sort result in a Datalog query

喜欢而已 提交于 2019-12-20 12:36:37
问题 I am using datomic with play framework. Play is amazing and datomic is fast. So a good combination overall. Since, I am new to datomic (and datalog i.e. query language datomic uses), I am unable to sort my result ( like we do, order by in sql). For example. if my query is : q= [:find ?title :where [?e :movie/title ?title] [?e :movie/director "Dave Swag"] [?e :movie/year ?year] [(sort ?year)] //here I am trying to sort by year ] It should return titles of the movies whose director was Dave

Cyclic relation in Datalog using SMTLib for z3

帅比萌擦擦* 提交于 2019-12-13 10:36:07
问题 I would like to express this problem in the SMTLib Format and evaluate it using Z3. edge("som1","som3"). edge("som2","som4"). edge("som4","som1"). edge("som3","som4"). path(x,y) :- edge(x,y). % x and y are strings path(x,z) :- edge(x,y), path(y,z). :- path(x,y), path(y,x). %cyclic path. My question is how to write the rule (or query) which detect the existence of a cycle in the relation path (this rule in basic datalog : :- path(x,y), path(y,x) ). 回答1: The tutorial Levent Erkok pointed out

Datomic query performance improvements

懵懂的女人 提交于 2019-12-12 13:56:12
问题 I have a schema that looks similar to this in a Datomic database: ; --- tenant {:db/id #db/id[:db.part/db] :db/ident :tenant/guid :db/unique :db.unique/identity :db/valueType :db.type/string :db/cardinality :db.cardinality/one :db.install/_attribute :db.part/db} {:db/id #db/id[:db.part/db] :db/ident :tenant/name :db/valueType :db.type/string :db/cardinality :db.cardinality/one :db.install/_attribute :db.part/db} {:db/id #db/id[:db.part/db] :db/ident :tenant/taks :db/valueType :db.type/ref :db

How to sort result in a Datalog query

痞子三分冷 提交于 2019-12-03 06:56:52
I am using datomic with play framework. Play is amazing and datomic is fast. So a good combination overall. Since, I am new to datomic (and datalog i.e. query language datomic uses), I am unable to sort my result ( like we do, order by in sql). For example. if my query is : q= [:find ?title :where [?e :movie/title ?title] [?e :movie/director "Dave Swag"] [?e :movie/year ?year] [(sort ?year)] //here I am trying to sort by year ] It should return titles of the movies whose director was Dave Swag and result is ordered by year in which image was released. Thankyou :) If you want to sort your