Mercurial > code > home > repos > homeauto
diff service/mqtt_to_rdf/lhs_evaluation.py @ 1634:ba59cfc3c747
hack math:sum in there. Test suite is passing except some slow performers
author | drewp@bigasterisk.com |
---|---|
date | Sun, 12 Sep 2021 23:48:43 -0700 |
parents | b21885181e35 |
children | 3252bdc284bc |
line wrap: on
line diff
--- a/service/mqtt_to_rdf/lhs_evaluation.py Sun Sep 12 21:48:36 2021 -0700 +++ b/service/mqtt_to_rdf/lhs_evaluation.py Sun Sep 12 23:48:43 2021 -0700 @@ -36,7 +36,7 @@ @staticmethod def findEvals(graph: Graph) -> Iterator['Evaluation']: for stmt in graph.triples((None, MATH['sum'], None)): - operands, operandsStmts = _parseList(graph, stmt[0]) + operands, operandsStmts = parseList(graph, stmt[0]) yield Evaluation(operands, stmt, operandsStmts) for stmt in graph.triples((None, MATH['greaterThan'], None)): @@ -98,17 +98,22 @@ return val -def _parseList(graph, subj) -> Tuple[List[Node], Set[Triple]]: +def parseList(graph, subj) -> Tuple[List[Node], Set[Triple]]: """"Do like Collection(g, subj) but also return all the triples that are involved in the list""" out = [] used = set() cur = subj while cur != RDF.nil: - out.append(graph.value(cur, RDF.first)) + elem = graph.value(cur, RDF.first) + if elem is None: + raise ValueError('bad list') + out.append(elem) used.add((cur, RDF.first, out[-1])) next = graph.value(cur, RDF.rest) + if next is None: + raise ValueError('bad list') used.add((cur, RDF.rest, next)) cur = next