Mercurial > code > home > repos > homeauto
diff service/reasoning/inference.py @ 756:f3f667769aef
python 3! and some types and cleanups
Ignore-this: 3453a547ee745fa83668f36956c835cd
author | drewp@bigasterisk.com |
---|---|
date | Fri, 14 Feb 2020 00:07:23 -0800 |
parents | e03696277b32 |
children | c8562ace4917 |
line wrap: on
line diff
--- a/service/reasoning/inference.py Thu Feb 13 23:00:06 2020 -0800 +++ b/service/reasoning/inference.py Fri Feb 14 00:07:23 2020 -0800 @@ -7,7 +7,7 @@ from rdflib.Graph import Graph except ImportError: from rdflib import Graph - + from rdflib import Namespace from rdflib.parser import StringInputSource @@ -15,7 +15,7 @@ from FuXi.Rete import ReteNetwork from FuXi.Rete.RuleStore import N3RuleStore -from greplin import scales +from greplin import scales STATS = scales.collection('/web', scales.PmfStat('readRules')) @@ -32,7 +32,7 @@ # of my rules. This serialize/parse version is very slow (400ms), # but it only runs when the file changes. plainGraph = Graph() - plainGraph.parse(StringInputSource(n3), format='n3') # for inference + plainGraph.parse(StringInputSource(n3.encode('utf8')), format='n3') # for inference escapeOutputStatements(plainGraph, outputPatterns=outputPatterns) expandedN3 = plainGraph.serialize(format='n3') @@ -60,7 +60,7 @@ ruleStore = N3RuleStore() _loadAndEscape(ruleStore, rulesN3, outputPatterns) log.debug('%s rules' % len(ruleStore.rules)) - + _rulesCache = key + (rulesN3, ruleStore) return rulesN3, ruleStore @@ -76,7 +76,7 @@ with _dontChangeRulesStore(rules): network = ReteNetwork(rules, inferredTarget=target) network.feedFactsToAdd(tokenSet) - + return target @contextlib.contextmanager @@ -84,11 +84,11 @@ if not hasattr(rules, '_stashOriginalRules'): rules._stashOriginalRules = rules.rules[:] yield - for k in rules.formulae.keys(): + for k in list(rules.formulae.keys()): if not k.startswith('_:Formula'): del rules.formulae[k] rules.rules = rules._stashOriginalRules[:] - + import time, logging log = logging.getLogger() def logTime(func):