-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix adjacency constraint in term mode
- Loading branch information
1 parent
ea7a05e
commit 0bd0e8a
Showing
9 changed files
with
240 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
post.disableInvokeMake() | ||
|
||
lString = LabelSettings(LabelType.String, LabelRelation.Specialisation) | ||
lTerm = LabelSettings(LabelType.Term, LabelRelation.Specialisation) | ||
|
||
Graph.fromDFS("[Q]({a}[A])({b}[B])({a}[C])({b}[C])({c}[C])({c}[C])") | ||
ruleTemplate = """rule [ | ||
ruleID "{}" | ||
left [ node [ id 0 label "Q" ] ] | ||
right [ node [ id 0 label "Q({})" ] ] | ||
constrainAdj [ | ||
id 0 op "{}" | ||
count {} | ||
{} | ||
] | ||
]""" | ||
ops = {'lt': '<', 'leq': '<=', 'eq': '=', 'geq': '>=', 'gt': '>'} | ||
def evalOp(a, op, b): | ||
if op == '<': return a < b | ||
if op == '<=': return a <= b | ||
if op == '=': return a == b | ||
if op == '>=': return a >= b | ||
if op == '>': return a > b | ||
assert False | ||
nodeLabels = { | ||
'': '', | ||
'A': 'nodeLabels [ label "A" ]', | ||
'B': 'nodeLabels [ label "B" label "B" ]', # make sure duplicates don't do anything | ||
'C': 'nodeLabels [ label "C" ]', | ||
'AB': 'nodeLabels [ label "A" label "B" ]', | ||
'AC': 'nodeLabels [ label "A" label "C" ]', | ||
'BC': 'nodeLabels [ label "B" label "C" ]', | ||
'ABC': 'nodeLabels [ label "A" label "B" label "C" ]', | ||
} | ||
edgeLabels = { | ||
'': '', | ||
'a': 'edgeLabels [ label "a" ]', | ||
'b': 'edgeLabels [ label "b" label "b" ]', | ||
'c': 'edgeLabels [ label "c" ]', | ||
'ab': 'edgeLabels [ label "a" label "b" ]', | ||
'ac': 'edgeLabels [ label "a" label "c" ]', | ||
'bc': 'edgeLabels [ label "b" label "c" ]', | ||
'abc': 'edgeLabels [ label "a" label "b" label "c" ]', | ||
} | ||
for count in range(10): | ||
for opName, op in ops.items(): | ||
for nlName, nl in nodeLabels.items(): | ||
for elName, el in edgeLabels.items(): | ||
name = ','.join([opName, str(count), f"V{nlName}", f"E{elName}"]) | ||
labels = f"{nl}\n{el}\n" | ||
Rule.fromGMLString(ruleTemplate.format(name, name, op, count, labels)) | ||
|
||
err = False | ||
|
||
def doDG(name, lSettings): | ||
print(name + "\n" + "="*50) | ||
dg = DG(graphDatabase=inputGraphs, labelSettings=lSettings) | ||
dg.build().execute(addSubset(inputGraphs) >> inputRules) | ||
found = set() | ||
for vDG in dg.vertices: | ||
g = vDG.graph | ||
try: | ||
v = next(a for a in g.vertices if a.stringLabel.startswith("Q(")) | ||
except StopIteration: | ||
continue | ||
l = v.stringLabel | ||
l = l[2:-1] | ||
op, count, nl, el = l.split(',') | ||
op, count, nl, el = ops[op], int(count), nl.strip()[1:], el.strip()[1:] | ||
candCount = 0 | ||
for e in v.incidentEdges: | ||
if len(el) != 0 and e.stringLabel not in el: | ||
continue | ||
u = e.target | ||
if len(nl) != 0 and e.target.stringLabel not in nl: | ||
continue | ||
candCount += 1 | ||
if(not evalOp(candCount, op, count)): | ||
print(f"Error: '{nl}' '{el}' = {candConut} {op} {count}") | ||
err = True | ||
|
||
doDG("String", lString) | ||
doDG("Term", lTerm) | ||
|
||
if err: | ||
assert False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
post.disableInvokeMake() | ||
|
||
lTerm = LabelSettings(LabelType.Term, LabelRelation.Specialisation) | ||
|
||
# test that multiple different matches of constraints don't increase the count | ||
|
||
Graph.fromDFS("[Q]({a}[A])({b}[B])") | ||
ruleTemplate = """rule [ | ||
ruleID "{}" | ||
left [ node [ id 0 label "Q" ] ] | ||
right [ node [ id 0 label "Q({})" ] ] | ||
constrainAdj [ | ||
id 0 op "{}" | ||
count {} | ||
{} | ||
] | ||
]""" | ||
ops = {'lt': '<', 'leq': '<=', 'eq': '=', 'geq': '>=', 'gt': '>'} | ||
def evalOp(a, op, b): | ||
if op == '<': return a < b | ||
if op == '<=': return a <= b | ||
if op == '=': return a == b | ||
if op == '>=': return a >= b | ||
if op == '>': return a > b | ||
assert False | ||
nodeLabels = { | ||
'': '', | ||
'A': 'nodeLabels [ label "_A" ]', | ||
'AA': 'nodeLabels [ label "_A" label "_A" ]', | ||
'AB': 'nodeLabels [ label "_A" label "_B" ]', | ||
} | ||
edgeLabels = { | ||
'': '', | ||
'a': 'edgeLabels [ label "_a" ]', | ||
'aa': 'edgeLabels [ label "_a" label "_a" ]', | ||
'ab': 'edgeLabels [ label "_a" label "_b" ]', | ||
} | ||
valid = set() | ||
for count in range(0, 4): | ||
for opName, op in ops.items(): | ||
for nlName, nl in nodeLabels.items(): | ||
for elName, el in edgeLabels.items(): | ||
if evalOp(2, op, count): | ||
valid.add((nlName, elName, op, count)) | ||
name = ','.join([opName, str(count), f"V{nlName}", f"E{elName}"]) | ||
labels = f"{nl}\n{el}\n" | ||
Rule.fromGMLString(ruleTemplate.format(name, name, op, count, labels)) | ||
|
||
|
||
dg = DG(graphDatabase=inputGraphs, labelSettings=lTerm) | ||
dg.build().execute(addSubset(inputGraphs) >> inputRules) | ||
dg.print() | ||
found = set() | ||
for vDG in dg.vertices: | ||
g = vDG.graph | ||
try: | ||
v = next(a for a in g.vertices if a.stringLabel.startswith("Q(")) | ||
except StopIteration: | ||
continue | ||
l = v.stringLabel | ||
l = l[2:-1] | ||
op, count, nl, el = l.split(',') | ||
op, count, nl, el = ops[op], int(count), nl.strip()[1:], el.strip()[1:] | ||
found.add((nl, el, op, count)) | ||
err = False | ||
for e in sorted(found): | ||
if e not in valid: | ||
print("Invalid:", e) | ||
err = True | ||
for e in sorted(valid): | ||
if e not in found: | ||
print("Missing valid:", e) | ||
err = True | ||
if err: | ||
assert False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
post.disableInvokeMake() | ||
|
||
# check that the node and edge label unifications must happen at the same time | ||
Graph.fromDFS("[_x]{_x}[C]") | ||
Rule.fromGMLString("""rule [ | ||
left [ node [ id 0 label "C" ] ] | ||
right [ node [ id 0 label "U" ] ] | ||
constrainAdj [ | ||
id 0 | ||
nodeLabels [ label "a" ] | ||
edgeLabels [ label "b" ] | ||
op "=" count 1 | ||
] | ||
]""") | ||
dg = DG(graphDatabase=inputGraphs, | ||
labelSettings=LabelSettings(LabelType.Term, LabelRelation.Specialisation)) | ||
dg.build().execute(addSubset(inputGraphs) >> inputRules) | ||
assert dg.numEdges == 0, f"|E| = {dg.numEdges}" |
Oops, something went wrong.