Mercurial > code > home > repos > homeauto
annotate service/mqtt_to_rdf/inference_test.py @ 1634:ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
author | drewp@bigasterisk.com |
---|---|
date | Sun, 12 Sep 2021 23:48:43 -0700 |
parents | 6107603ed455 |
children | 4bb6f593ebf3 |
rev | line source |
---|---|
1588
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
1 """ |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
2 also see https://github.com/w3c/N3/tree/master/tests/N3Tests |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
3 """ |
1609
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
4 from collections import defaultdict |
1606
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
5 from decimal import Decimal |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
6 from typing import cast |
1587 | 7 import unittest |
1594 | 8 |
1625
64f4fb8c233f
mostly cleanup; scraps of the next rewrite; unskip tests that are ok now
drewp@bigasterisk.com
parents:
1624
diff
changeset
|
9 from rdflib import ConjunctiveGraph, Graph, Literal, Namespace |
1609
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
10 from rdflib.graph import ReadOnlyGraphAggregate |
1587 | 11 from rdflib.parser import StringInputSource |
12 | |
1609
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
13 from inference import Inference, Lhs |
1600 | 14 from rdflib_debug_patches import patchBnodeCounter, patchSlimReprs |
1590
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
15 |
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
16 patchSlimReprs() |
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
17 patchBnodeCounter() |
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
18 |
1594 | 19 EX = Namespace('http://example.com/') |
1587 | 20 ROOM = Namespace('http://projects.bigasterisk.com/room/') |
21 | |
22 | |
23 def N3(txt: str): | |
24 g = ConjunctiveGraph() | |
1588
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
25 prefix = """ |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
26 @prefix : <http://example.com/> . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
27 @prefix room: <http://projects.bigasterisk.com/room/> . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
28 @prefix math: <http://www.w3.org/2000/10/swap/math#> . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
29 """ |
1587 | 30 g.parse(StringInputSource((prefix + txt).encode('utf8')), format='n3') |
31 return g | |
32 | |
33 | |
34 def makeInferenceWithRules(n3): | |
35 inf = Inference() | |
36 inf.setRules(N3(n3)) | |
37 return inf | |
38 | |
39 | |
40 class WithGraphEqual(unittest.TestCase): | |
41 | |
42 def assertGraphEqual(self, g: Graph, expected: Graph): | |
43 stmts1 = list(g.triples((None, None, None))) | |
44 stmts2 = list(expected.triples((None, None, None))) | |
45 self.assertCountEqual(stmts1, stmts2) | |
46 | |
47 | |
48 class TestInferenceWithoutVars(WithGraphEqual): | |
49 | |
50 def testEmitNothing(self): | |
51 inf = makeInferenceWithRules("") | |
52 implied = inf.infer(N3(":a :b :c .")) | |
53 self.assertEqual(len(implied), 0) | |
54 | |
55 def testSimple(self): | |
56 inf = makeInferenceWithRules("{ :a :b :c . } => { :a :b :new . } .") | |
57 implied = inf.infer(N3(":a :b :c .")) | |
58 self.assertGraphEqual(implied, N3(":a :b :new .")) | |
59 | |
60 def testTwoRounds(self): | |
61 inf = makeInferenceWithRules(""" | |
62 { :a :b :c . } => { :a :b :new1 . } . | |
63 { :a :b :new1 . } => { :a :b :new2 . } . | |
64 """) | |
65 | |
66 implied = inf.infer(N3(":a :b :c .")) | |
67 self.assertGraphEqual(implied, N3(":a :b :new1, :new2 .")) | |
68 | |
69 | |
70 class TestInferenceWithVars(WithGraphEqual): | |
71 | |
72 def testVarInSubject(self): | |
73 inf = makeInferenceWithRules("{ ?x :b :c . } => { :new :stmt ?x } .") | |
74 implied = inf.infer(N3(":a :b :c .")) | |
75 self.assertGraphEqual(implied, N3(":new :stmt :a .")) | |
76 | |
77 def testVarInObject(self): | |
78 inf = makeInferenceWithRules("{ :a :b ?x . } => { :new :stmt ?x } .") | |
79 implied = inf.infer(N3(":a :b :c .")) | |
80 self.assertGraphEqual(implied, N3(":new :stmt :c .")) | |
81 | |
82 def testVarMatchesTwice(self): | |
83 inf = makeInferenceWithRules("{ :a :b ?x . } => { :new :stmt ?x } .") | |
84 implied = inf.infer(N3(":a :b :c, :d .")) | |
85 self.assertGraphEqual(implied, N3(":new :stmt :c, :d .")) | |
86 | |
1588
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
87 def testTwoRulesApplyIndependently(self): |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
88 inf = makeInferenceWithRules(""" |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
89 { :a :b ?x . } => { :new :stmt ?x . } . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
90 { :d :e ?y . } => { :new :stmt2 ?y . } . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
91 """) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
92 implied = inf.infer(N3(":a :b :c .")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
93 self.assertGraphEqual(implied, N3(""" |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
94 :new :stmt :c . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
95 """)) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
96 implied = inf.infer(N3(":a :b :c . :d :e :f .")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
97 self.assertGraphEqual(implied, N3(""" |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
98 :new :stmt :c . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
99 :new :stmt2 :f . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
100 """)) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
101 |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
102 def testOneRuleActivatesAnother(self): |
1587 | 103 inf = makeInferenceWithRules(""" |
1588
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
104 { :a :b ?x . } => { :new :stmt ?x . } . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
105 { ?y :stmt ?z . } => { :new :stmt2 ?y . } . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
106 """) |
1587 | 107 implied = inf.infer(N3(":a :b :c .")) |
1588
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
108 self.assertGraphEqual(implied, N3(""" |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
109 :new :stmt :c . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
110 :new :stmt2 :new . |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
111 """)) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
112 |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
113 def testVarLinksTwoStatements(self): |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
114 inf = makeInferenceWithRules("{ :a :b ?x . :d :e ?x } => { :new :stmt ?x } .") |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
115 implied = inf.infer(N3(":a :b :c .")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
116 self.assertGraphEqual(implied, N3("")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
117 implied = inf.infer(N3(":a :b :c . :d :e :f .")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
118 self.assertGraphEqual(implied, N3("")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
119 implied = inf.infer(N3(":a :b :c . :d :e :c .")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
120 self.assertGraphEqual(implied, N3(":new :stmt :c .")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
121 |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
122 def testRuleMatchesStaticStatement(self): |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
123 inf = makeInferenceWithRules("{ :a :b ?x . :a :b :c . } => { :new :stmt ?x } .") |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
124 implied = inf.infer(N3(":a :b :c .")) |
0757fafbfdab
WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents:
1587
diff
changeset
|
125 self.assertGraphEqual(implied, N3(":new :stmt :c .")) |
1587 | 126 |
127 | |
1589
5c1055be3c36
WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents:
1588
diff
changeset
|
128 class TestBnodeMatching(WithGraphEqual): |
1590
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
129 |
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
130 def testRuleBnodeBindsToInputBnode(self): |
1589
5c1055be3c36
WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents:
1588
diff
changeset
|
131 inf = makeInferenceWithRules("{ [ :a :b ] . } => { :new :stmt :here } .") |
5c1055be3c36
WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents:
1588
diff
changeset
|
132 implied = inf.infer(N3("[ :a :b ] .")) |
5c1055be3c36
WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents:
1588
diff
changeset
|
133 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
5c1055be3c36
WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents:
1588
diff
changeset
|
134 |
1590
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
135 def testRuleVarBindsToInputBNode(self): |
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
136 inf = makeInferenceWithRules("{ ?z :a :b . } => { :new :stmt :here } .") |
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
137 implied = inf.infer(N3("[] :a :b .")) |
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
138 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
139 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
140 class TestBnodeGenerating(WithGraphEqual): |
1590
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
141 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
142 def testRuleBnodeMakesNewBnode(self): |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
143 inf = makeInferenceWithRules("{ [ :a :b ] . } => { [ :c :d ] } .") |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
144 implied = inf.infer(N3("[ :a :b ] .")) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
145 ruleNode = list(inf.rules[0].rhsGraph)[0] |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
146 stmt0Node = list(implied)[0][0] |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
147 self.assertNotEqual(ruleNode, stmt0Node) |
1590
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
148 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
149 def testRuleBnodeMakesNewBnodesEachTime(self): |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
150 inf = makeInferenceWithRules("{ [ :a ?x ] . } => { [ :c :d ] } .") |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
151 implied = inf.infer(N3("[ :a :b, :e ] .")) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
152 ruleNode = list(inf.rules[0].rhsGraph)[0] |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
153 stmt0Node = list(implied)[0][0] |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
154 stmt1Node = list(implied)[1][0] |
1590
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
155 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
156 self.assertNotEqual(ruleNode, stmt0Node) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
157 self.assertNotEqual(ruleNode, stmt1Node) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
158 self.assertNotEqual(stmt0Node, stmt1Node) |
1612
272f78d4671a
mark skipped tests. move applyRule into Rule. minor cleanups.
drewp@bigasterisk.com
parents:
1609
diff
changeset
|
159 |
1589
5c1055be3c36
WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents:
1588
diff
changeset
|
160 |
1633
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
161 class TestSelfFulfillingRule(WithGraphEqual): |
1587 | 162 |
1633
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
163 def test1(self): |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
164 inf = makeInferenceWithRules("{ } => { :new :stmt :x } .") |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
165 self.assertGraphEqual(inf.infer(N3("")), N3(":new :stmt :x .")) |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
166 self.assertGraphEqual(inf.infer(N3(":any :any :any .")), N3(":new :stmt :x .")) |
1593
b0df43d5494c
big rewrite- more classes, smaller methods, more typesafe, all current tests passing
drewp@bigasterisk.com
parents:
1590
diff
changeset
|
167 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
168 def test2(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
169 inf = makeInferenceWithRules("{ (2) math:sum ?x } => { :new :stmt ?x } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
170 self.assertGraphEqual(inf.infer(N3("")), N3(":new :stmt 2 .")) |
1590
327202020892
WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents:
1589
diff
changeset
|
171 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
172 # @unittest.skip("too hard for now") |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
173 # def test3(self): |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
174 # inf = makeInferenceWithRules("{ :a :b :c . :a :b ?x . } => { :new :stmt ?x } .") |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
175 # self.assertGraphEqual(inf.infer(N3("")), N3(":new :stmt :c .")) |
1594 | 176 |
1587 | 177 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
178 class TestInferenceWithMathFunctions(WithGraphEqual): |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
179 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
180 def testBoolFilter(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
181 inf = makeInferenceWithRules("{ :a :b ?x . ?x math:greaterThan 5 } => { :new :stmt ?x } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
182 self.assertGraphEqual(inf.infer(N3(":a :b 3 .")), N3("")) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
183 self.assertGraphEqual(inf.infer(N3(":a :b 5 .")), N3("")) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
184 self.assertGraphEqual(inf.infer(N3(":a :b 6 .")), N3(":new :stmt 6 .")) |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
185 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
186 def testNonFiringMathRule(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
187 inf = makeInferenceWithRules("{ :a :b ?x . (?x 1) math:sum ?y } => { :new :stmt ?y } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
188 self.assertGraphEqual(inf.infer(N3("")), N3("")) |
1587 | 189 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
190 def testStatementGeneratingRule(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
191 inf = makeInferenceWithRules("{ :a :b ?x . (?x) math:sum ?y } => { :new :stmt ?y } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
192 self.assertGraphEqual(inf.infer(N3(":a :b 3 .")), N3(":new :stmt 3 .")) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
193 |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
194 def test2Operands(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
195 inf = makeInferenceWithRules("{ :a :b ?x . (?x 1) math:sum ?y } => { :new :stmt ?y } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
196 self.assertGraphEqual(inf.infer(N3(":a :b 3 .")), N3(":new :stmt 4 .")) |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
197 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
198 def test3Operands(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
199 inf = makeInferenceWithRules("{ :a :b ?x . (2 ?x 2) math:sum ?y } => { :new :stmt ?y } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
200 self.assertGraphEqual(inf.infer(N3(":a :b 2 .")), N3(":new :stmt 6 .")) |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
201 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
202 def test0Operands(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
203 inf = makeInferenceWithRules("{ :a :b ?x . () math:sum ?y } => { :new :stmt ?y } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
204 self.assertGraphEqual(inf.infer(N3(":a :b 2 .")), N3(":new :stmt 0 .")) |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
205 |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
206 |
1633
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
207 class TestInferenceWithCustomFunctions(WithGraphEqual): |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
208 |
1633
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
209 def testAsFarenheit(self): |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
210 inf = makeInferenceWithRules("{ :a :b ?x . ?x room:asFarenheit ?f } => { :new :stmt ?f } .") |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
211 self.assertGraphEqual(inf.infer(N3(":a :b 12 .")), N3(":new :stmt 53.6 .")) |
1594 | 212 |
213 | |
1599
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
214 class TestUseCases(WithGraphEqual): |
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
215 |
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
216 def testSimpleTopic(self): |
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
217 inf = makeInferenceWithRules(''' |
1606
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
218 { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } . |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
219 { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } . |
1599
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
220 |
1606
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
221 { |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
222 ?msg a :MqttMessage ; |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
223 :topic :foo; |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
224 :onlineTerm ?onlineness . } => { |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
225 :frontDoorLockStatus :connectedStatus ?onlineness . |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
226 } . |
1599
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
227 ''') |
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
228 |
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
229 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic :foo .')) |
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
230 self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out) |
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
231 |
1633
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
232 # def testTopicIsList(self): |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
233 # inf = makeInferenceWithRules(''' |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
234 # { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } . |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
235 # { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } . |
1606
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
236 |
1633
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
237 # { |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
238 # ?msg a :MqttMessage ; |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
239 # :topic ( "frontdoorlock" "status" ); |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
240 # :onlineTerm ?onlineness . } => { |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
241 # :frontDoorLockStatus :connectedStatus ?onlineness . |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
242 # } . |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
243 # ''') |
1606
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
244 |
1633
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
245 # out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic ( "frontdoorlock" "status" ) .')) |
6107603ed455
fix farenheit rule case, fix some others that depend on rings order, but this breaks some performance because of itertools.perm
drewp@bigasterisk.com
parents:
1631
diff
changeset
|
246 # self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out) |
1606
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
247 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
248 def testPerformance0(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
249 inf = makeInferenceWithRules(''' |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
250 { |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
251 ?msg a :MqttMessage; |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
252 :topic :topic1; |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
253 :bodyFloat ?valueC . |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
254 ?valueC math:greaterThan -999 . |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
255 ?valueC room:asFarenheit ?valueF . |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
256 } => { |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
257 :airQualityIndoorTemperature :temperatureF ?valueF . |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
258 } . |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
259 ''') |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
260 out = inf.infer( |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
261 N3(''' |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
262 <urn:uuid:c6e1d92c-0ee1-11ec-bdbd-2a42c4691e9a> a :MqttMessage ; |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
263 :body "23.9" ; |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
264 :bodyFloat 2.39e+01 ; |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
265 :topic :topic1 . |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
266 ''')) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
267 |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
268 vlit = cast(Literal, out.value(EX['airQualityIndoorTemperature'], EX['temperatureF'])) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
269 valueF = cast(Decimal, vlit.toPython()) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
270 self.assertAlmostEqual(float(valueF), 75.02) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
271 |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
272 # def testPerformance1(self): |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
273 # inf = makeInferenceWithRules(''' |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
274 # { |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
275 # ?msg a :MqttMessage; |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
276 # :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ); |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
277 # :bodyFloat ?valueC . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
278 # ?valueC math:greaterThan -999 . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
279 # ?valueC room:asFarenheit ?valueF . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
280 # } => { |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
281 # :airQualityIndoorTemperature :temperatureF ?valueF . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
282 # } . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
283 # ''') |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
284 # out = inf.infer( |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
285 # N3(''' |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
286 # <urn:uuid:c6e1d92c-0ee1-11ec-bdbd-2a42c4691e9a> a :MqttMessage ; |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
287 # :body "23.9" ; |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
288 # :bodyFloat 2.39e+01 ; |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
289 # :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ) . |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
290 # ''')) |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
291 # vlit = cast(Literal, out.value(EX['airQualityIndoorTemperature'], EX['temperatureF'])) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
292 # valueF = cast(Decimal, vlit.toPython()) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
293 # self.assertAlmostEqual(float(valueF), 75.02) |
1599
abbf0eb0e640
fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents:
1595
diff
changeset
|
294 |
1627
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
295 def testEmitBnodes(self): |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
296 inf = makeInferenceWithRules(''' |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
297 { ?s a :AirQualitySensor; :label ?name . } => { |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
298 [ a :MqttStatementSource; |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
299 :mqttTopic (?name "sensor" "bme280_temperature" "state") ] . |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
300 } . |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
301 ''') |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
302 out = inf.infer(N3(''' |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
303 :airQualityOutdoor a :AirQualitySensor; :label "air_quality_outdoor" . |
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
304 ''')) |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
305 self.assertEqual(out.serialize(format='n3'), b'''@prefix ns1: <http://example.com/> . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
306 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
307 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
308 @prefix xml: <http://www.w3.org/XML/1998/namespace> . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
309 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . |
1627
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
310 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
311 [] a ns1:MqttStatementSource ; |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
312 ns1:mqttTopic ( "air_quality_outdoor" "sensor" "bme280_temperature" "state" ) . |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
313 |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
314 ''') |
1627
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
315 |
1606
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
316 |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
317 class TestListPerformance(WithGraphEqual): |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
318 |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
319 def testList1(self): |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
320 inf = makeInferenceWithRules("{ :a :b (:e0) . } => { :new :stmt :here } .") |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
321 implied = inf.infer(N3(":a :b (:e0) .")) |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
322 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
323 |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
324 def testList2(self): |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
325 inf = makeInferenceWithRules("{ :a :b (:e0 :e1) . } => { :new :stmt :here } .") |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
326 implied = inf.infer(N3(":a :b (:e0 :e1) .")) |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
327 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
328 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
329 def testList3(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
330 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2) . } => { :new :stmt :here } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
331 implied = inf.infer(N3(":a :b (:e0 :e1 :e2) .")) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
332 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
1606
6cf39d43fd40
realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents:
1605
diff
changeset
|
333 |
1634
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
334 def testList4(self): |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
335 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2 :e3) . } => { :new :stmt :here } .") |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
336 implied = inf.infer(N3(":a :b (:e0 :e1 :e2 :e3) .")) |
ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents:
1633
diff
changeset
|
337 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
1609
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
338 |
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
339 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
340 # def fakeStats(): |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
341 # return defaultdict(lambda: 0) |
1609
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
342 |
1627
ea559a846714
some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents:
1625
diff
changeset
|
343 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
344 # class TestLhsFindCandidateBindings(WithGraphEqual): |
1609
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
345 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
346 # def testBnodeMatchesStmt(self): |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
347 # l = Lhs(N3("[] :a :b .")) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
348 # ws = ReadOnlyGraphAggregate([N3("[] :a :b .")]) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
349 # cands = list(l.findCandidateBindings(ws, fakeStats())) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
350 # self.assertEqual(len(cands), 1) |
1609
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
351 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
352 # def testVarMatchesStmt(self): |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
353 # l = Lhs(N3("?x :a :b .")) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
354 # ws = ReadOnlyGraphAggregate([N3("[] :a :b .")]) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
355 # cands = list(l.findCandidateBindings(ws, fakeStats())) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
356 # self.assertEqual(len(cands), 1) |
1609
34f2817320cc
new tests for a smaller part of the inner loop
drewp@bigasterisk.com
parents:
1606
diff
changeset
|
357 |
1631
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
358 # def testListsOnlyMatchEachOther(self): |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
359 # l = Lhs(N3(":a :b (:e0 :e1) .")) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
360 # ws = ReadOnlyGraphAggregate([N3(":a :b (:e0 :e1) .")]) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
361 # stats = fakeStats() |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
362 # cands = list(l.findCandidateBindings(ws, stats)) |
2c85a4f5dd9c
big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents:
1627
diff
changeset
|
363 # self.assertLess(stats['permCountFailingVerify'], 20) |