annotate service/mqtt_to_rdf/inference_test.py @ 1692:2883da14847c

debugging and cleanup, as i looked for a bug
author drewp@bigasterisk.com
date Sat, 25 Sep 2021 22:20:00 -0700
parents aa35ae7a1acc
children 73abfd4cf5d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """
1664
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
4 import unittest
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
1594
e58bcfa66093 cleanups and a few fixed cases
drewp@bigasterisk.com
parents: 1593
diff changeset
7
1625
64f4fb8c233f mostly cleanup; scraps of the next rewrite; unskip tests that are ok now
drewp@bigasterisk.com
parents: 1624
diff changeset
8 from rdflib import ConjunctiveGraph, Graph, Literal, Namespace
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
9 from rdflib.parser import StringInputSource
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
10
1664
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
11 from inference import Inference
1600
89a50242cb5e cleanup internal names, imports
drewp@bigasterisk.com
parents: 1599
diff changeset
12 from rdflib_debug_patches import patchBnodeCounter, patchSlimReprs
1590
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
13
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
14 patchSlimReprs()
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
15 patchBnodeCounter()
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
16
1594
e58bcfa66093 cleanups and a few fixed cases
drewp@bigasterisk.com
parents: 1593
diff changeset
17 EX = Namespace('http://example.com/')
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
18 ROOM = Namespace('http://projects.bigasterisk.com/room/')
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
19
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
20
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
21 def N3(txt: str):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
22 g = ConjunctiveGraph()
1588
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
23 prefix = """
1646
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
24 @prefix : <http://projects.bigasterisk.com/room/> .
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
25 @prefix ex: <http://example.com/> .
1588
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
26 @prefix room: <http://projects.bigasterisk.com/room/> .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
27 @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
28 @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
29 """
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
30 g.parse(StringInputSource((prefix + txt).encode('utf8')), format='n3')
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
31 return g
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
32
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
33
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
34 def makeInferenceWithRules(n3):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
35 inf = Inference()
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
36 inf.setRules(N3(n3))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
37 return inf
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
38
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
39
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
40 class WithGraphEqual(unittest.TestCase):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
41
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
42 def assertGraphEqual(self, g: Graph, expected: Graph):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
43 stmts1 = list(g.triples((None, None, None)))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
44 stmts2 = list(expected.triples((None, None, None)))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
45 self.assertCountEqual(stmts1, stmts2)
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
46
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
47
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
48 class TestInferenceWithoutVars(WithGraphEqual):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
49
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
50 def testEmitNothing(self):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
51 inf = makeInferenceWithRules("")
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
52 implied = inf.infer(N3(":a :b :c ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
53 self.assertEqual(len(implied), 0)
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
54
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
55 def testSimple(self):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
56 inf = makeInferenceWithRules("{ :a :b :c . } => { :a :b :new . } .")
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
57 implied = inf.infer(N3(":a :b :c ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
58 self.assertGraphEqual(implied, N3(":a :b :new ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
59
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
60 def testTwoRounds(self):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
61 inf = makeInferenceWithRules("""
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
62 { :a :b :c . } => { :a :b :new1 . } .
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
63 { :a :b :new1 . } => { :a :b :new2 . } .
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
64 """)
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
65
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
66 implied = inf.infer(N3(":a :b :c ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
67 self.assertGraphEqual(implied, N3(":a :b :new1, :new2 ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
68
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
69
1646
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
70 class TestNonRuleStatements(WithGraphEqual):
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
71
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
72 def test(self):
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
73 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
74 self.assertCountEqual(inf.nonRuleStatements(), [(ROOM.d, ROOM.e, ROOM.f)])
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
75
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
76
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
77 class TestInferenceWithVars(WithGraphEqual):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
78
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
79 def testVarInSubject(self):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
80 inf = makeInferenceWithRules("{ ?x :b :c . } => { :new :stmt ?x } .")
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
81 implied = inf.infer(N3(":a :b :c ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
82 self.assertGraphEqual(implied, N3(":new :stmt :a ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
83
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
84 def testVarInObject(self):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
85 inf = makeInferenceWithRules("{ :a :b ?x . } => { :new :stmt ?x } .")
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
86 implied = inf.infer(N3(":a :b :c ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
87 self.assertGraphEqual(implied, N3(":new :stmt :c ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
88
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
89 def testVarMatchesTwice(self):
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
90 inf = makeInferenceWithRules("{ :a :b ?x . } => { :new :stmt ?x } .")
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
91 implied = inf.infer(N3(":a :b :c, :d ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
92 self.assertGraphEqual(implied, N3(":new :stmt :c, :d ."))
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
93
1588
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
94 def testTwoRulesApplyIndependently(self):
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
95 inf = makeInferenceWithRules("""
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
96 { :a :b ?x . } => { :new :stmt ?x . } .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
97 { :d :e ?y . } => { :new :stmt2 ?y . } .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
98 """)
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
99 implied = inf.infer(N3(":a :b :c ."))
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
100 self.assertGraphEqual(implied, N3("""
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
101 :new :stmt :c .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
102 """))
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
103 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
104 self.assertGraphEqual(implied, N3("""
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
105 :new :stmt :c .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
106 :new :stmt2 :f .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
107 """))
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 def testOneRuleActivatesAnother(self):
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
110 inf = makeInferenceWithRules("""
1588
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
111 { :a :b ?x . } => { :new :stmt ?x . } .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
112 { ?y :stmt ?z . } => { :new :stmt2 ?y . } .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
113 """)
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
114 implied = inf.infer(N3(":a :b :c ."))
1588
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
115 self.assertGraphEqual(implied, N3("""
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
116 :new :stmt :c .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
117 :new :stmt2 :new .
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
118 """))
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 def testRuleMatchesStaticStatement(self):
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
121 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
122 implied = inf.infer(N3(":a :b :c ."))
0757fafbfdab WIP inferencer - partial var and function support
drewp@bigasterisk.com
parents: 1587
diff changeset
123 self.assertGraphEqual(implied, N3(":new :stmt :c ."))
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
124
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
125
1672
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
126 class TestVarLinksTwoStatements(WithGraphEqual):
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
127
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
128 def setUp(self):
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
129 self.inf = makeInferenceWithRules("{ :a :b ?x . :d :e ?x } => { :new :stmt ?x } .")
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
130
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
131 def testOnlyOneStatementPresent(self):
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
132 implied = self.inf.infer(N3(":a :b :c ."))
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
133 self.assertGraphEqual(implied, N3(""))
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
134
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
135 def testObjectsConflict(self):
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
136 implied = self.inf.infer(N3(":a :b :c . :d :e :f ."))
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
137 self.assertGraphEqual(implied, N3(""))
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
138
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
139 def testObjectsAgree(self):
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
140 implied = self.inf.infer(N3(":a :b :c . :d :e :c ."))
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
141 self.assertGraphEqual(implied, N3(":new :stmt :c ."))
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
142
23beadd3e83a split a test
drewp@bigasterisk.com
parents: 1666
diff changeset
143
1589
5c1055be3c36 WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents: 1588
diff changeset
144 class TestBnodeMatching(WithGraphEqual):
1590
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
145
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
146 def testRuleBnodeBindsToInputBnode(self):
1589
5c1055be3c36 WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents: 1588
diff changeset
147 inf = makeInferenceWithRules("{ [ :a :b ] . } => { :new :stmt :here } .")
5c1055be3c36 WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents: 1588
diff changeset
148 implied = inf.infer(N3("[ :a :b ] ."))
5c1055be3c36 WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents: 1588
diff changeset
149 self.assertGraphEqual(implied, N3(":new :stmt :here ."))
5c1055be3c36 WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents: 1588
diff changeset
150
1590
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
151 def testRuleVarBindsToInputBNode(self):
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
152 inf = makeInferenceWithRules("{ ?z :a :b . } => { :new :stmt :here } .")
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
153 implied = inf.infer(N3("[] :a :b ."))
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
154 self.assertGraphEqual(implied, N3(":new :stmt :here ."))
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
155
1646
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
156
1664
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
157 class TestBnodeAliasingSetup(WithGraphEqual):
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
158
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
159 def setUp(self):
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
160 self.inf = makeInferenceWithRules("""
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
161 {
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
162 ?var0 :a ?x; :b ?y .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
163 } => {
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
164 :xVar :value ?x .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
165 :yVar :value ?y .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
166 } .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
167 """)
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
168
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
169 def assertResult(self, actual):
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
170 self.assertGraphEqual(actual, N3("""
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
171 :xVar :value :x0, :x1 .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
172 :yVar :value :y0, :y1 .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
173 """))
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
174
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
175 def testMatchesDistinctStatements(self):
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
176 implied = self.inf.infer(N3("""
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
177 :stmt0 :a :x0; :b :y0 .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
178 :stmt1 :a :x1; :b :y1 .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
179 """))
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
180 self.assertResult(implied)
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
181
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
182 def testMatchesDistinctBnodes(self):
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
183 implied = self.inf.infer(N3("""
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
184 [ :a :x0; :b :y0 ] .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
185 [ :a :x1; :b :y1 ] .
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
186 """))
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
187 self.assertResult(implied)
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
188
1673
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
189 def testProdCase(self):
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
190 inf = makeInferenceWithRules('''
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
191 {
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
192 :AirQualitySensor :nameRemap [
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
193 :sensorName ?sensorName;
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
194 :measurementName ?measurement
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
195 ] .
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
196 } => {
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
197 :a :b ?sensorName.
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
198 :d :e ?measurement.
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
199 } .
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
200 ''')
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
201 implied = inf.infer(
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
202 N3('''
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
203 :AirQualitySensor :nameRemap
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
204 [:sensorName "bme280_pressure"; :measurementName "pressure"],
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
205 [:sensorName "bme280_temperature"; :measurementName "temperature"] .
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
206 '''))
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
207
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
208 self.assertGraphEqual(implied, N3('''
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
209 :a :b "bme280_pressure", "bme280_temperature" .
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
210 :d :e "pressure", "temperature" .
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
211 '''))
80f4e741ca4f redo RHS bnode processing
drewp@bigasterisk.com
parents: 1672
diff changeset
212
1664
1a7c1261302c logic fix- some bindings were being returned 2+; some 0 times
drewp@bigasterisk.com
parents: 1662
diff changeset
213
1631
2c85a4f5dd9c big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents: 1627
diff changeset
214 class TestBnodeGenerating(WithGraphEqual):
1590
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
215
1631
2c85a4f5dd9c big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents: 1627
diff changeset
216 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
217 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
218 implied = inf.infer(N3("[ :a :b ] ."))
1646
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
219 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
220 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
221 self.assertNotEqual(ruleNode, stmt0Node)
1590
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
222
1631
2c85a4f5dd9c big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents: 1627
diff changeset
223 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
224 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
225 implied = inf.infer(N3("[ :a :b, :e ] ."))
1646
af136cf6dd26 make namespaces in tests less confusing
drewp@bigasterisk.com
parents: 1640
diff changeset
226 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
227 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
228 stmt1Node = list(implied)[1][0]
1590
327202020892 WIP inference- getting into more degenerate test cases
drewp@bigasterisk.com
parents: 1589
diff changeset
229
1631
2c85a4f5dd9c big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents: 1627
diff changeset
230 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
231 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
232 self.assertNotEqual(stmt0Node, stmt1Node)
1612
272f78d4671a mark skipped tests. move applyRule into Rule. minor cleanups.
drewp@bigasterisk.com
parents: 1609
diff changeset
233
1589
5c1055be3c36 WIP more debugging, working towards bnode-matching support
drewp@bigasterisk.com
parents: 1588
diff changeset
234
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
235 class TestSelfFulfillingRule(WithGraphEqual):
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
236
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
237 def test1(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
238 inf = makeInferenceWithRules("{ } => { :new :stmt :x } .")
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
239 self.assertGraphEqual(inf.infer(N3("")), N3(":new :stmt :x ."))
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
240 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
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 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
243 # 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
244 # 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
245
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
246 # @unittest.skip("too hard for now")
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
247 # def test3(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
248 # inf = makeInferenceWithRules("{ :a :b :c . :a :b ?x . } => { :new :stmt ?x } .")
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
249 # self.assertGraphEqual(inf.infer(N3("")), N3(":new :stmt :c ."))
1594
e58bcfa66093 cleanups and a few fixed cases
drewp@bigasterisk.com
parents: 1593
diff changeset
250
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
251
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
252 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
253
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
254 def testBoolFilter(self):
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
255 inf = makeInferenceWithRules("{ :a :b ?x . ?x math:greaterThan 5 } => { :new :stmt ?x } .")
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
256 self.assertGraphEqual(inf.infer(N3(":a :b 3 .")), N3(""))
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
257 self.assertGraphEqual(inf.infer(N3(":a :b 5 .")), N3(""))
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
258 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
259
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
260 def testNonFiringMathRule(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
261 inf = makeInferenceWithRules("{ :a :b ?x . (?x 1) math:sum ?y } => { :new :stmt ?y } .")
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
262 self.assertGraphEqual(inf.infer(N3("")), N3(""))
1587
9a3a18c494f9 WIP new inferencer. no vars yet.
drewp@bigasterisk.com
parents:
diff changeset
263
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
264 def testStatementGeneratingRule(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
265 inf = makeInferenceWithRules("{ :a :b ?x . (?x) math:sum ?y } => { :new :stmt ?y } .")
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
266 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
267
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
268 def test2Operands(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
269 inf = makeInferenceWithRules("{ :a :b ?x . (?x 1) math:sum ?y } => { :new :stmt ?y } .")
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
270 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
271
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
272 def test3Operands(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
273 inf = makeInferenceWithRules("{ :a :b ?x . (2 ?x 2) math:sum ?y } => { :new :stmt ?y } .")
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
274 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
275
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
276 # def test0Operands(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
277 # inf = makeInferenceWithRules("{ :a :b ?x . () math:sum ?y } => { :new :stmt ?y } .")
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
278 # 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
279
2c85a4f5dd9c big rewrite of infer() using statements not variables as the things to iterate over
drewp@bigasterisk.com
parents: 1627
diff changeset
280
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
281 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
282
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
283 def testAsFarenheit(self):
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
284 inf = makeInferenceWithRules("{ :a :b ?x . ?x room:asFarenheit ?f } => { :new :stmt ?f } .")
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
285 self.assertGraphEqual(inf.infer(N3(":a :b 12 .")), N3(":new :stmt 53.6 ."))
1594
e58bcfa66093 cleanups and a few fixed cases
drewp@bigasterisk.com
parents: 1593
diff changeset
286
1662
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
287 def testChildResource(self):
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
288 inf = makeInferenceWithRules("{ :a :b ?x . (:c ?x) room:childResource ?y .} => { :new :stmt ?y } .")
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
289 self.assertGraphEqual(inf.infer(N3(':a :b "foo" .')), N3(":new :stmt <http://projects.bigasterisk.com/room/c/foo> ."))
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
290
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
291 def testChildResourceSegmentQuoting(self):
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
292 inf = makeInferenceWithRules("{ :a :b ?x . (:c ?x) room:childResource ?y .} => { :new :stmt ?y } .")
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
293 self.assertGraphEqual(inf.infer(N3(':a :b "b / w -> #." .')),
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
294 N3(":new :stmt <http://projects.bigasterisk.com/room/c/b%20%2F%20w%20-%3E%20%23.> ."))
7a61113fd17d new childResource function for making new URIs
drewp@bigasterisk.com
parents: 1660
diff changeset
295
1594
e58bcfa66093 cleanups and a few fixed cases
drewp@bigasterisk.com
parents: 1593
diff changeset
296
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
297 class TestUseCases(WithGraphEqual):
1599
abbf0eb0e640 fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents: 1595
diff changeset
298
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
299 def testSimpleTopic(self):
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
300 inf = makeInferenceWithRules('''
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
301 { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } .
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
302 { ?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
303
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
304 {
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
305 ?msg a :MqttMessage ;
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
306 :topic :foo;
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
307 :onlineTerm ?onlineness . } => {
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
308 :frontDoorLockStatus :connectedStatus ?onlineness .
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
309 } .
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
310 ''')
1599
abbf0eb0e640 fix a bug with a slightly moer complicated set of rules
drewp@bigasterisk.com
parents: 1595
diff changeset
311
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
312 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic :foo .'))
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
313 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
314
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
315 def testTopicIsList(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
316 inf = makeInferenceWithRules('''
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
317 { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
318 { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } .
1606
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
319
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
320 {
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
321 ?msg a :MqttMessage ;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
322 :topic ( "frontdoorlock" "status" );
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
323 :onlineTerm ?onlineness . } => {
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
324 :frontDoorLockStatus :connectedStatus ?onlineness .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
325 } .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
326 ''')
1606
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
327
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
328 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic ( "frontdoorlock" "status" ) .'))
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
329 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
330
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
331 def testPerformance0(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
332 inf = makeInferenceWithRules('''
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
333 {
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
334 ?msg a :MqttMessage;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
335 :topic :topic1;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
336 :bodyFloat ?valueC .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
337 ?valueC math:greaterThan -999 .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
338 ?valueC room:asFarenheit ?valueF .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
339 } => {
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
340 :airQualityIndoorTemperature :temperatureF ?valueF .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
341 } .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
342 ''')
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
343 out = inf.infer(
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
344 N3('''
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
345 <urn:uuid:c6e1d92c-0ee1-11ec-bdbd-2a42c4691e9a> a :MqttMessage ;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
346 :body "23.9" ;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
347 :bodyFloat 2.39e+01 ;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
348 :topic :topic1 .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
349 '''))
1634
ba59cfc3c747 hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents: 1633
diff changeset
350
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
351 vlit = cast(Literal, out.value(ROOM['airQualityIndoorTemperature'], ROOM['temperatureF']))
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
352 valueF = cast(Decimal, vlit.toPython())
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
353 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
354
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
355 def testPerformance1(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
356 inf = makeInferenceWithRules('''
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
357 {
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
358 ?msg a :MqttMessage;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
359 :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" );
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
360 :bodyFloat ?valueC .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
361 ?valueC math:greaterThan -999 .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
362 ?valueC room:asFarenheit ?valueF .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
363 } => {
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
364 :airQualityIndoorTemperature :temperatureF ?valueF .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
365 } .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
366 ''')
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
367 out = inf.infer(
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
368 N3('''
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
369 <urn:uuid:c6e1d92c-0ee1-11ec-bdbd-2a42c4691e9a> a :MqttMessage ;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
370 :body "23.9" ;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
371 :bodyFloat 2.39e+01 ;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
372 :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ) .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
373 '''))
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
374 vlit = cast(Literal, out.value(ROOM['airQualityIndoorTemperature'], ROOM['temperatureF']))
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
375 valueF = cast(Decimal, vlit.toPython())
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
376 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
377
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
378 def testEmitBnodes(self):
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
379 inf = makeInferenceWithRules('''
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
380 { ?s a :AirQualitySensor; :label ?name . } => {
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
381 [ a :MqttStatementSource;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
382 :mqttTopic (?name "sensor" "bme280_temperature" "state") ] .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
383 } .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
384 ''')
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
385 out = inf.infer(N3('''
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
386 :airQualityOutdoor a :AirQualitySensor; :label "air_quality_outdoor" .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
387 '''))
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
388 out.bind('', ROOM)
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
389 out.bind('ex', EX)
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
390 self.assertEqual(
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
391 out.serialize(format='n3'), b'''\
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
392 @prefix : <http://projects.bigasterisk.com/room/> .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
393 @prefix ex: <http://example.com/> .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
394 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
395 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
396 @prefix xml: <http://www.w3.org/XML/1998/namespace> .
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
397 @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
398
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
399 [] a :MqttStatementSource ;
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
400 :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
401
1660
31f7dab6a60b function evaluation uses Chunk lists now and runs fast. Only a few edge cases still broken
drewp@bigasterisk.com
parents: 1659
diff changeset
402 ''')
1627
ea559a846714 some shuffling, i don't know- i'm about to rewrite again
drewp@bigasterisk.com
parents: 1625
diff changeset
403
1677
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
404 def testRemap(self):
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
405 inf = makeInferenceWithRules('''
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
406 {
1692
2883da14847c debugging and cleanup, as i looked for a bug
drewp@bigasterisk.com
parents: 1677
diff changeset
407 ?sensor a :AirQualitySensor; :label ?name .
2883da14847c debugging and cleanup, as i looked for a bug
drewp@bigasterisk.com
parents: 1677
diff changeset
408 (:mqttSource ?name) :childResource ?base .
1677
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
409 } => {
1692
2883da14847c debugging and cleanup, as i looked for a bug
drewp@bigasterisk.com
parents: 1677
diff changeset
410 ?sensor :statementSourceBase ?base .
1677
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
411 } .
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
412 ''')
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
413 out = inf.infer(N3('''
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
414 :airQualityIndoor a :AirQualitySensor; :label "air_quality_indoor" .
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
415 :airQualityOutdoor a :AirQualitySensor; :label "air_quality_outdoor" .
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
416 '''))
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
417 self.assertGraphEqual(out, N3('''
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
418 :airQualityIndoor :statementSourceBase <http://projects.bigasterisk.com/room/mqttSource/air_quality_indoor> .
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
419 :airQualityOutdoor :statementSourceBase <http://projects.bigasterisk.com/room/mqttSource/air_quality_outdoor> .
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
420 '''))
aa35ae7a1acc add new bug test (no fix yet)
drewp@bigasterisk.com
parents: 1673
diff changeset
421
1606
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
422
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
423 class TestListPerformance(WithGraphEqual):
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
424
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
425 def testList1(self):
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
426 inf = makeInferenceWithRules("{ :a :b (:e0) . } => { :new :stmt :here } .")
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
427 implied = inf.infer(N3(":a :b (:e0) ."))
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
428 self.assertGraphEqual(implied, N3(":new :stmt :here ."))
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
429
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
430 def testList2(self):
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
431 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
432 implied = inf.infer(N3(":a :b (:e0 :e1) ."))
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
433 self.assertGraphEqual(implied, N3(":new :stmt :here ."))
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
434
1634
ba59cfc3c747 hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents: 1633
diff changeset
435 def testList3(self):
ba59cfc3c747 hack math:sum in there. Test suite is passing except some slow performers
drewp@bigasterisk.com
parents: 1633
diff changeset
436 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
437 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
438 self.assertGraphEqual(implied, N3(":new :stmt :here ."))
1606
6cf39d43fd40 realign tests, turn off slow ones for now
drewp@bigasterisk.com
parents: 1605
diff changeset
439
1657
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
440 # def testList4(self):
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
441 # inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2 :e3) . } => { :new :stmt :here } .")
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
442 # implied = inf.infer(N3(":a :b (:e0 :e1 :e2 :e3) ."))
274bb6c04627 update currently-working tests
drewp@bigasterisk.com
parents: 1651
diff changeset
443 # self.assertGraphEqual(implied, N3(":new :stmt :here ."))