# HG changeset patch # User drewp@bigasterisk.com # Date 1631902284 25200 # Node ID bb5d2b5370ac817146d0b1f20d7181def7c6370a # Parent 3059f31b2dfad26411dd825dfa0df9e98c7fb241 add nonRuleStatments to Inference api. there's already a test in an eariler commit diff -r 3059f31b2dfa -r bb5d2b5370ac service/mqtt_to_rdf/inference.py --- 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.