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