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