Commits

Anonymous committed f483639

make fuxi module a bit smarter about which inferred statements it adds to which graphs

Comments (0)

Files changed (1)

ordf/handler/fuxi.py

 
         ### we don't reason on changesets, so make a list of changesets we have
         changesets = []
+        facts = []
         for ctx in store.contexts():
-            for statement in ctx.triples((ctx.identifier, RDF.type, CS.ChangeSet)):
+            if ctx.exists((ctx.identifier, RDF.type, CS.ChangeSet)):
 		log.debug("skip %s" % ctx.identifier)
-                changesets.append(ctx.identifier)
-                break
+                changesets.append(ctx)
+            else:
+                facts.append(ctx)
 
         ### feed data to the reasoner
-        for ctx in store.contexts():
-            if ctx.identifier in changesets:
-                continue
-            log.debug("facts %s" % ctx.identifier)
-            self.network.feedFactsToAdd(generateTokenSet(ctx))
+        for fact_graph in facts:
+            log.debug("facts %s" % fact_graph.identifier)
+            self.network.feedFactsToAdd(generateTokenSet(fact_graph))
+
+        #log.debug("inferred\n%s" % inferredFacts.serialize(format="n3"))
 
         ### construct the change context
         change_ctx = self.handler.context(getuser(), "FuXi machine reasoning")
-        for ctx in store.contexts():
-            if ctx.identifier in changesets:
-                ### if a previous changeset, just preserve it in the change context
-                ### store
-                copy = Graph(store=change_ctx.store, identifier=ctx.identifier)
-                for statement in ctx.triples((None, None, None)):
-                    copy.add(statement)
-            else:
-                ### otherwise, add the relevant inferred facts
-                ### this is a naive way of figuring out which inferred
-                ### facts are relevant
-                copy = Graph(identifier=ctx.identifier)
-                copy += ctx
-                copy += inferredFacts.bnc((ctx.identifier, None, None))
-                change_ctx.add(copy)
+        for cs in changesets:
+            ### for previous changeset, just preserve it in the change context
+            ### store
+            copy = Graph(store=change_ctx.store, identifier=ctx.identifier)
+            for statement in ctx.triples((None, None, None)):
+                copy.add(statement)
+
+        for fact_graph in facts:
+            ### add the relevant inferred facts
+            ### this is a naive way of figuring out which inferred
+            ### facts are relevant
+            copy = Graph(identifier=ctx.identifier)
+            copy += fact_graph
+            for subj in fact_graph.distinct_subjects():
+                copy += inferredFacts.bnc((subj, None, None))
+            change_ctx.add(copy)
 
         ### save the changes
         ### this doesn't loop back through this function because