changeset 1649:bb5d2b5370ac

add nonRuleStatments to Inference api. there's already a test in an eariler commit
author drewp@bigasterisk.com
date Fri, 17 Sep 2021 11:11:24 -0700
parents 3059f31b2dfa
children 2061df259224
files service/mqtt_to_rdf/inference.py
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/service/mqtt_to_rdf/inference.py	Fri Sep 17 11:10:18 2021 -0700
+++ b/service/mqtt_to_rdf/inference.py	Fri Sep 17 11:11:24 2021 -0700
@@ -10,7 +10,7 @@
 from typing import (Dict, Iterator, List, Optional, Sequence, Set, Tuple, Union, cast)
 
 from prometheus_client import Histogram, Summary
-from rdflib import RDF, BNode, Graph, Namespace
+from rdflib import RDF, BNode, Graph, Literal, Namespace
 from rdflib.graph import ConjunctiveGraph, ReadOnlyGraphAggregate
 from rdflib.term import Node, URIRef, Variable
 
@@ -405,7 +405,11 @@
         for stmt in g:
             if stmt[1] == LOG['implies']:
                 self.rules.append(Rule(stmt[0], stmt[2]))
-            # other stmts should go to a default working set?
+            else:
+                self._nonRuleStmts.append(stmt)
+
+    def nonRuleStatements(self) -> List[Triple]:
+        return self._nonRuleStmts
 
     @INFER_CALLS.time()
     def infer(self, graph: Graph):
@@ -417,8 +421,10 @@
         log.info(f'{INDENT*0} Begin inference of graph len={n} with rules len={len(self.rules)}:')
         startTime = time.time()
         stats: Dict[str, Union[int, float]] = defaultdict(lambda: 0)
+
         # everything that is true: the input graph, plus every rule conclusion we can make
         workingSet = Graph()
+        workingSet += self._nonRuleStmts
         workingSet += graph
 
         # just the statements that came from RHS's of rules that fired.