asami

Asami, the graph database https://github.com/threatgrid/asami
2021-03-05T00:00:42.081700Z

My fear with asserting more data is that it doesn’t halt the reasoning. From falsehood anything follows; so it’d be useful to terminate the reasoning rather than continue computing the closure over something inconsistent

2021-03-05T00:02:36.083100Z

I guess I could probably raise an exception by binding to a special predicate backed by a function that raises an exception

quoll 2021-03-05T00:02:46.083400Z

Well, that’s why I was thinking that an error predicate could be detected at line 125 in the engine, and thrown at that point

1👍
quoll 2021-03-05T00:03:08.084Z

Actually, I think I did this in Mulgara rules engine? :thinking_face:

2021-03-05T00:03:11.084100Z

oh sorry I missed that bit of the message

quoll 2021-03-05T00:03:33.084800Z

Anyway… if you’d like that, then put in a ticket. I’d be happy to look at doing it

quoll 2021-03-05T00:04:01.085600Z

Trying desperately to wrap up Asami 2.0.0-alpha right now. I’m just about there

quoll 2021-03-05T00:04:16.086100Z

So I’m not looking at anything else until next week 🙂

2021-03-05T00:04:40.086600Z

Yeah I think it would be useful; especially if it could capture the context (bindings) to explain the error

2021-03-05T00:05:20.086800Z

It’s ok non of this is urgent by any means… just noodling around 🙂

2021-03-05T09:10:17.088400Z

Looks like to implement eq-diff2 I’ll need to implement a ternary predicate:

2021-03-05T09:28:36.092200Z

I think something like this is the natural implementation (untested because naga currently supports unary/binary predicates).

ta:compare(L,X,Y) :- krule:inList(L,X),
                     rdf:rest(L,L2),
                     krule:inList(L2,Y).
Which would I think allow for usage something like this:
ta:error(eq-diff2) :- owl:AllDifferent(XXX),
                      owl:members(XXX,List),
                      ta:compare(List,XXX,ZZZ),
                      owl:sameAs(XXX,ZZZ).
:thinking_face: I can obviously represent ta:compare/3 as a list; but here I think I’m probably better just avoiding the issue and inlining the definition.

quoll 2021-03-05T16:07:36.094500Z

I’ve been looking at different syntaxes for rules, to make multi-arity predicates, lists, and entity structures more natural. It can all be translated into triple patterns, but the resulting rules are difficult for people to read and write

quoll 2021-03-05T16:11:27.096300Z

e.g. X is in a list: [… X …] X starts a list: [X …] X is at the end of a list: [… X] X is the third item in a list: [_ _ X …] X is the second last item in a list: [… X _]

quoll 2021-03-05T16:11:34.096500Z

Maybe

quoll 2021-03-05T16:12:10.097300Z

Actually, the Clojure way would be to ignore anything at the end of a matching pattern in a seq, so trailing dots would be redundant

2021-03-05T16:29:06.099600Z

yeah something clojurey makes sense for naga… If you were planning to support it in pabu, you’d do well to lift the list syntax from datalogs big daddy, prolog! 🙂 e.g. for recursively finding members in a list you’d write:

member(X,[X|_]).
member(X,[_|TAIL]) :- member(X,TAIL).

quoll 2021-03-05T16:30:46.100200Z

True

quoll 2021-03-05T16:31:14.100900Z

For Pabu, this makes sense. It was supposed to be a Datalog after all

quoll 2021-03-05T16:31:28.101300Z

But I have a need to create a new language that is based around entities

2021-03-05T16:37:01.104200Z

Yeah - I agree with this btw. Also I think not having some of these features prevents you from creating useful abstractions… i.e. I can’t reuse ta:compare, I have to inline it everywhere.

quoll 2021-03-05T16:38:59.105700Z

Something like:

{:type "CourseOfAction"
 :action "block"
 :observable O}
:-
{:type "sighting"
 :observables [... {:type T, :value V} ...]},
{:type "verdict"
 :disposition "Malicious"
 :observable {:db/id O, :type T, :value V}}
But this is a bit vague for now

quoll 2021-03-05T16:40:06.106700Z

That’s a pseudocode version of something we were looking at. It’s our private vocabulary for expressing some public data models, so I think it’s relatively safe to post as an example

quoll 2021-03-05T16:41:19.108300Z

Writing it in Datalog syntax is awful, since we’re having to express the data structures in triple patterns, and it’s necessary to know the syntax and structure for expressing entities. That’s more than users should need to know

quoll 2021-03-05T16:42:17.109100Z

Also, if I’m moving from Datalog, then I could use different syntax for variables. e.g. ?t instead of T

2021-03-05T16:52:27.114100Z

Ok, I can see how that might work… trying to bridge datalog and clojure syntaxes. On the other hand prolog syntax exists already — and could trivially express that too. Just bind a library of predicates for maps (prolog dicts), and lists. he says waving his hands furiously over all the details

2021-03-05T16:54:09.114700Z

😆 I guess I just miss working in Prolog!

quoll 2021-03-05T16:59:37.115400Z

All I need is a syntax for binding variables to parts of structures, but everything else is Datalog

quoll 2021-03-05T17:00:20.116300Z

It’s on the backburner for the moment, but I’ve also been trying to learn how Prolog engines are implemented, wondering if I can extend my Datalog implementation to take on more Prolog capabilities

2021-03-05T17:04:10.117400Z

yeah agreed… At some point though I wonder if you’ll ask yourself whether you really want to maintain two syntaxes

quoll 2021-03-05T17:04:59.118100Z

I don’t really maintain Pabu. It was something I knocked up quickly overnight 🙂

2021-03-05T17:05:24.118700Z

hehe well you have at least one user now 🙂

quoll 2021-03-05T17:05:38.119Z

I’ve updated it a couple of times, and I’m happy to do so. It’s pretty easy

2021-03-05T17:07:21.120800Z

yeah it’s very simple; but I like it — feels like prolog 🙂 However as I said I’m just noodling about, so if you were to drop it I could switch to the naga side… I probably should as that’s where most of the action is.

quoll 2021-03-05T17:10:07.121600Z

The source code for Naga is done with an unusual parser: Parsatron. It’s a parser combinator.

quoll 2021-03-05T17:10:25.122100Z

If I write a new parser I’ll probably use Instaparse

2021-03-05T17:10:26.122200Z

yeah I’ve seen

quoll 2021-03-05T17:10:38.122600Z

But Parsatron was fun to use

2021-03-05T17:10:47.122800Z

I’ve used Instaparse too and would recommend

quoll 2021-03-05T17:11:05.123300Z

Yes, it makes more sense

quoll 2021-03-05T17:11:30.124300Z

But Nate Young is a friend, and I liked his presentation at Strangeloop (2010, I think)

quoll 2021-03-05T17:12:42.125300Z

Ah, it was 2011

2021-03-05T17:13:01.125700Z

As a user my only gripe with pabu is that when the parse fails you don’t get an error… so it can be hard to distinguish syntax errors from semantic / data ones.

quoll 2021-03-05T17:13:22.126200Z

Yes, it was really hard to figure that part out

2021-03-05T17:13:24.126300Z

So Instaparse would probably make that better

2021-03-05T17:14:20.127300Z

IIRC Instaparse has a combinator layer too — though the EBNF stuff is magic. I’ve essentially pasted in EBNF from RFCs and only had to tweak a few things, and it mostly just works! It’s magical.

1💖
quoll 2021-03-05T17:14:41.128Z

Appropriate responses for poorly structured syntax is really tough. Asami struggles with that with queries

quoll 2021-03-05T17:15:16.128200Z

More accurately… I struggle with doing that

1
quoll 2021-03-05T17:17:22.128700Z

If your :find clause includes things that aren’t in the :where clause then it doesn’t fail. Instead, you get weird projections.

quoll 2021-03-05T17:17:37.128900Z

Which I can fix, but I don’t want to hit performance too significantly

2021-03-05T17:31:04.129500Z

👌 Awesome! Be sure to let me know when you have something going.

2021-03-05T17:33:45.129700Z

I still feel like what the prolog folk did 20, 30 maybe even 40 years ago, is beyond what many folk in databases etc consider to be the state of the art.

quoll 2021-03-05T17:34:23.129900Z

Well, Prolog isn’t Database oriented. I’d like to bridge that gap, if I can

quoll 2021-03-05T17:34:28.130100Z

but I need to understand it better

2021-03-05T17:35:22.130300Z

I think it’s closer than you might think

2021-03-05T17:35:37.130500Z

but not quite sure what you mean by not database oriented 🙂

quoll 2021-03-05T17:35:42.130700Z

From what I’ve seen… yes

quoll 2021-03-05T17:35:50.130900Z

But I still need to see more 🙂

2021-03-05T17:36:04.131100Z

It has extra-logical features… e.g. cut.

quoll 2021-03-05T17:36:46.131300Z

That’s process flow control. It would make for something different than Naga’s queue processing

2021-03-05T17:38:22.131500Z

(cut) … which is super useful, but can make reasoning about programs harder. Essentially there are two ways to read/reason about prolog programs. 1. purely declaratively. 2. mechanically. If you use cut, you blow away the declarative reasoning mode; and are forced to reason mechanically.

2021-03-05T17:39:23.131700Z

but you can use it to efficiently implement NAF for example.

2021-03-05T17:49:23.131900Z

Incidentally 20 years ago when I did a small amount of prolog, one of the fastest implementations was sicstus. Some colleagues considered its performance pretty legendary, though we could never justify the license fee. There are quite a few papers about it. Just seen this one which looks like it might be an interesting read: https://arxiv.org/pdf/1011.5640.pdf

quoll 2021-03-05T18:40:10.132200Z

Thank you for this!

2021-03-05T18:41:44.132700Z

You’re welcome 🙇 Yeah I assumed that was the book you had… I downloaded it too once — though I’ve only ever skimmed it 🙂

noprompt 2021-03-05T21:31:26.133Z

Not the WAM but also interesting: https://pllab.github.io/cs162-spring17/handouts/handout6-miniprolog-smallstep.pdf

2021-03-05T21:56:43.133200Z

Oo looks good thanks for sharing