Skip to content

Commit

Permalink
Add complete paper examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pseifer committed Aug 26, 2021
1 parent 03f7c80 commit 54595f2
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 34 deletions.
3 changes: 3 additions & 0 deletions paper-example/example1.progs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE employeeShape [:employee] {
:person
};
3 changes: 3 additions & 0 deletions paper-example/example1_fixed.progs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE employeeShape [:employee] {
:employee
};
3 changes: 3 additions & 0 deletions paper-example/example4.progs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE s1 [:employee] {
>= 1 :colleagueOf.:person
};
3 changes: 3 additions & 0 deletions paper-example/example4_fixed.progs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE s1 [:employee] {
>= 1 :colleagueOf.:employee
};
8 changes: 8 additions & 0 deletions paper-example/example5.progs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
NODE s1 [BOTTOM] {
>= 1 :colleagueOf.:person
};

NODE s2 [name = "Gareth Keenan"] {
>= 2 role.string &
s1
};
4 changes: 4 additions & 0 deletions paper-example/example6.progs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EDGE s3 [:worksFor] {
<< :person &
>= 1 since . = 2020
};
4 changes: 4 additions & 0 deletions paper-example/example6_fixed.progs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EDGE s3 [:worksFor] {
<< :employee &
(>= 1 since . = 2020 | >= 1 since . = 1970)
};
6 changes: 3 additions & 3 deletions paper-example/graph.lp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edge(102, 203, 101).
% Define labels for nodes and edges.

label(100, person).
label(102, person).
label(100, employee).
label(102, employee).
label(101, company).
Expand All @@ -27,6 +26,7 @@ property(100, name, string("Tim Canterbury")).
property(100, age, integer(30)).
property(101, name, string("Wernham Hogg")).
property(102, name, string("Gareth Keenan")).
property(102, role, string("sales")).
property(102, role, string("team leader")).
property(203, since, integer(2020)).
property(200, since, integer(1970)).
property(200, since, integer(2007)).
property(200, since, integer(1970)).
7 changes: 0 additions & 7 deletions paper-example/shapes.progs

This file was deleted.

3 changes: 0 additions & 3 deletions paper-example/shapes1.progs

This file was deleted.

3 changes: 0 additions & 3 deletions paper-example/shapes2.progs

This file was deleted.

2 changes: 1 addition & 1 deletion progs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Basic setup.

ap = argparse.ArgumentParser(prog='ProGS',
description='Run validation on property graphs. For basic validation use \'validate\' mode.',
description='Run validation on property graphs. For standard validation use \'validate\' mode.',
epilog='Philipp Seifer @ https://github.com/softlang/progs')
ap.version = '0.1'
ap.add_argument('-v', action='version')
Expand Down
12 changes: 10 additions & 2 deletions src/grammar.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ edgeshape : "EDGE" shape "[" edgetarget "]" "{" edgeconstraint "}" ";"
nodetarget : ":" label
| NUMBER -> nid
| "BOTTOM" -> bot
| property -> property
| property "=" value -> propvalue
| property -> propertytarget

?nodeconstraint : nodeconstraint_or
?nodeconstraint_or : [nodeconstraint_or "|"] nodeconstraint_and
Expand Down Expand Up @@ -33,11 +34,13 @@ path : ":" label

predicate : "string" -> string
| "int" -> int
| "=" value -> eqvalue

edgetarget : ":" label
| NUMBER -> eid
| "BOTTOM" -> bot
| property -> property
| property "=" value -> propvalue
| property -> propertytarget

?edgeconstraint : edgeconstraint_or
?edgeconstraint_or : [edgeconstraint_or "|"] edgeconstraint_and
Expand All @@ -54,6 +57,9 @@ edgeconstraint_basic : "TOP" -> top
| ">>" nodeconstraint_basic -> right
| "(" edgeconstraint ")"

?value : "\"" STRING "\"" -> stringvalue
| NUMBER -> intvalue

comp : "<=" -> le
| ">=" -> ge
| ">" -> gr
Expand All @@ -68,6 +74,8 @@ labelref : WORD
WORD : LCASE_LETTER CHAR+
CHAR : LETTER | DIGIT | "_"
NUMBER : DIGIT+
SCHAR : CHAR | WS
STRING : SCHAR+

COMMENT : "%" /(.)*/ NEWLINE

Expand Down
34 changes: 21 additions & 13 deletions src/progs.lp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% -- Data Model --
% -- data model --

node(X) :- edge(X,_,_).
node(X) :- edge(_,_,X).
Expand All @@ -7,7 +7,7 @@ edge(X) :- edge(_,X,_).
labels(L) :- label(_, L).
properties(P) :- property(_, P, _).

% -- Utility --
% -- utility --

min(yes,yes,yes).
min(yes,no,no).
Expand All @@ -19,17 +19,19 @@ min(maybe,maybe,maybe).
min(no,maybe,no).
min(maybe,no,no).

% -- Core --
% -- core --

nodeshape(S) :- nodeshape(S,_,_).
edgeshape(S) :- edgeshape(S,_,_).

targetN(N,S) :- nodeshape(S,_,label(L)), label(N,L).
targetN(N,S) :- nodeshape(S,_,hasProperty(K)), property(N,K,_).
targetN(N,S) :- nodeshape(S,_,hasPropertyValue(K,V)), property(N,K,V).
targetN(N,S) :- nodeshape(S,_,node(N)).

targetE(E,S) :- edgeshape(S,_,label(L)), label(E,L).
targetE(E,S) :- edgeshape(S,_,hasProperty(K)), property(E,K,_).
targetE(E,S) :- edgeshape(S,_,hasPropertyValue(K,V), property(E,K,V)).
targetE(E,S) :- edgeshape(S,_,edge(E)).

:- targetN(N,S), not assignN(N,S,yes).
Expand Down Expand Up @@ -89,11 +91,15 @@ satisfiesN(N, negate(C), yes) :- node(N), constraint(negate(C)),
satisfiesN(N,C,no).
satisfiesN(N, negate(C), no) :- node(N), constraint(negate(C)),
satisfiesN(N,C,yes).
satisfiesN(N, negate(C), maybe) :- node(N), constraint(negate(C)),
satisfiesN(N, C, maybe).

satisfiesE(E, negate(C), yes) :- edge(E), constraint(negate(C)),
satisfiesE(E,C,no).
satisfiesE(E, negate(C), no) :- edge(E), constraint(negate(C)),
satisfiesE(E,C,yes).
satisfiesE(E, negate(C), maybe) :- edge(E), constraint(negate(C)),
satisfiesE(E, C, maybe).

% -- and --

Expand Down Expand Up @@ -127,7 +133,9 @@ countNC(N,P,NC,C) :- node(N), path(P), constraint(NC),
countNoNC(N,P,NC,C) :- node(N), path(P), constraint(NC),
#count { Y: path(N,Y,P), satisfiesN(Y,NC,no) } = C.

% -- compare -- TODO
% -- compare --

% not yet supported

% -- greaterEqE --

Expand Down Expand Up @@ -164,17 +172,17 @@ satisfiesE(E,countProp(K,isString,I),no) :- edge(E), constraint(countProp(K,isSt
satisfiesE(E,countProp(K,isInteger,I),yes) :- edge(E), constraint(countProp(K,isInteger,I)), #count { V: property(E,K,integer(V)) } >= I.
satisfiesE(E,countProp(K,isInteger,I),no) :- edge(E), constraint(countProp(K,isInteger,I)), #count { V: property(E,K,integer(V)) } < I.

satisfiesN(N,countProp(K,equals(R),I),yes) :- node(N), constraint(countProp(K,equals(R),I)), #count { V: property(N,K,integer(V)), V == R } >= I.
satisfiesN(N,countProp(K,equals(R),I),no) :- node(N), constraint(countProp(K,equals(R),I)), #count { V: property(N,K,integer(V)), V == R } < I.
satisfiesN(N,countProp(K,equals(R),I),yes) :- node(N), constraint(countProp(K,equals(R),I)), #count { V: property(N,K,string(V)), V == R } >= I.
satisfiesN(N,countProp(K,equals(R),I),no) :- node(N), constraint(countProp(K,equals(R),I)), #count { V: property(N,K,string(V)), V == R } < I.
% -

satisfiesN(N,countProp(K,eq(R),I),yes) :- node(N), constraint(countProp(K,eq(R),I)), #count { V: property(N,K,V), V == R } >= I.
satisfiesN(N,countProp(K,eq(R),I),no) :- node(N), constraint(countProp(K,eq(R),I)), #count { V: property(N,K,V), V == R } < I.

satisfiesE(E,countProp(K,eq(R),I),yes) :- edge(E), constraint(countProp(K,eq(R),I)), #count { V: property(E,K,V), V == R } >= I.
satisfiesE(E,countProp(K,eq(R),I),no) :- edge(E), constraint(countProp(K,eq(R),I)), #count { V: property(E,K,V), V == R } < I.

satisfiesE(E,countProp(K,equals(R),I),yes) :- edge(E), constraint(countProp(K,equals(R),I)), #count { V: property(E,K,integer(V)), V == R } >= I.
satisfiesE(E,countProp(K,equals(R),I),no) :- edge(E), constraint(countProp(K,equals(R),I)), #count { V: property(E,K,integer(V)), V == R } < I.
satisfiesE(E,countProp(K,equals(R),I),yes) :- edge(E), constraint(countProp(K,equals(R),I)), #count { V: property(E,K,string(V)), V == R } >= I.
satisfiesE(E,countProp(K,equals(R),I),no) :- edge(E), constraint(countProp(K,equals(R),I)), #count { V: property(E,K,string(V)), V == R } < I.
% -- compareValues --

% -- compareValues -- TODO
% not yet supported

% -- equals --

Expand Down
22 changes: 20 additions & 2 deletions src/shapeTranspiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ def nid(self, n):
def bot(self, b):
return 'bottom'

def property(self, k):
def propertytarget(self, k):
return "hasProperty({})".format(k[0])

def propvalue(sekf, kv):
return "hasPropertyValue({},{})".format(kv[0], kv[1])

def shaperef(self, s):
c = 'shapeRef({})'.format(s[0])
constraint_store.add(c)
Expand Down Expand Up @@ -71,7 +74,13 @@ def nodeconstraint_and(self, items):
return c

def nodeconstraint_or(self, items):
c = 'negate(and(negate({}),negate({})))'.format(items[0],items[1])
c1 = 'negate({})'.format(items[0])
c2 = 'negate({})'.format(items[1])
c3 = 'and({},{})'.format(c1,c2)
c = 'negate({})'.format(c3)
constraint_store.add(c1)
constraint_store.add(c2)
constraint_store.add(c3)
constraint_store.add(c)
return c

Expand Down Expand Up @@ -171,12 +180,21 @@ def countprop(self, p):
constraint_store.add(c)
return c

def eqvalue(self, v):
return "eq({})".format(v[0])

def string(self, s):
return "isString"

def stringvalue(self, s):
return "string(\"{}\")".format(s[0])

def int(self, s):
return "isInteger"

def intvalue(self, i):
return "integer({})".format(i[0])

def compare(self, ps):
c = 'compare({},{})'.format(ps[0],ps[1])
constraint_store.add(c)
Expand Down

0 comments on commit 54595f2

Please sign in to comment.