def process_graph(self, inputGraph): instances = self.getInstances(inputGraph) results = [] for i in instances: print "Processing", i.identifier, self output_nanopub = Nanopublication() o = output_nanopub.assertion.resource( i.identifier) # OutputClass(i.identifier) error = False try: result = self.process_nanopub(i, o, output_nanopub) except Exception as e: output_nanopub.add( (output_nanopub.assertion.identifier, self.app.NS.sioc.content, rdflib.Literal(str(e)))) logging.exception( "Error processing resource %s in nanopub %s" % (i.identifier, inputGraph.identifier)) error = True print "Output Graph", output_nanopub.identifier, len( output_nanopub) for new_np in self.app.nanopub_manager.prepare( rdflib.ConjunctiveGraph(store=output_nanopub.store)): if len(new_np.assertion) == 0 and not error: continue self.explain(new_np, i, o) new_np.add((new_np.identifier, sio.isAbout, i.identifier)) #print new_np.serialize(format="trig") if not self.dry_run: self.app.nanopub_manager.publish(new_np) results.append(new_np) return results
def run(self, input_file, file_format="trig", was_revision_of=None): if was_revision_of is not None: wasRevisionOf = set(flask.current_app.db.objects(predicate=np.hasAssertion, subject=rdflib.URIRef(was_revision_of))) if len(wasRevisionOf) == 0: print "Could not find active nanopublication to revise:", was_revision_of return was_revision_of = wasRevisionOf g = rdflib.ConjunctiveGraph(identifier=rdflib.BNode().skolemize(), store="Sleepycat") graph_tempdir = tempfile.mkdtemp() g.store.open(graph_tempdir, True) #g = rdflib.ConjunctiveGraph(identifier=rdflib.BNode().skolemize()) g1 = g.parse(location=input_file, format=file_format, publicID=flask.current_app.NS.local) if len(list(g.subjects(rdflib.RDF.type, np.Nanopublication))) == 0: print "Could not find existing nanopublications.", len(g1), len(g) new_np = Nanopublication(store=g1.store) new_np.add((new_np.identifier, rdflib.RDF.type, np.Nanopublication)) new_np.add((new_np.identifier, np.hasAssertion, g1.identifier)) new_np.add((g1.identifier, rdflib.RDF.type, np.Assertion)) nanopub_prepare_graph = rdflib.ConjunctiveGraph(store="Sleepycat") nanopub_prepare_graph_tempdir = tempfile.mkdtemp() nanopub_prepare_graph.store.open(nanopub_prepare_graph_tempdir, True) nanopubs = [] for npub in flask.current_app.nanopub_manager.prepare(g, store=nanopub_prepare_graph.store): if was_revision_of is not None: for r in was_revision_of: print "Marking as revision of", r npub.pubinfo.add((npub.assertion.identifier, flask.current_app.NS.prov.wasRevisionOf, r)) print 'Prepared', npub.identifier nanopubs.append(npub) flask.current_app.nanopub_manager.publish(*nanopubs) print "Published", npub.identifier
def run(self, input_file, file_format="trig", was_revision_of=None): if was_revision_of is not None: wasRevisionOf = set(flask.current_app.db.objects(predicate=np.hasAssertion, subject=rdflib.URIRef(was_revision_of))) if len(wasRevisionOf) == 0: print "Could not find active nanopublication to revise:", was_revision_of return was_revision_of = wasRevisionOf g = rdflib.ConjunctiveGraph(identifier=rdflib.BNode().skolemize()) g1 = g.parse(location=input_file, format=file_format) if len(list(g1.subjects(rdflib.RDF.type, np.Nanopublication))) == 0: new_np = Nanopublication(store=g1.store) new_np.add((new_np.identifier, rdflib.RDF.type, np.Nanopublication)) new_np.add((new_np.identifier, np.hasAssertion, g1.identifier)) new_np.add((g1.identifier, rdflib.RDF.type, np.Assertion)) for npub in flask.current_app.nanopub_manager.prepare(g): if was_revision_of is not None: for r in was_revision_of: print "Marking as revision of", r npub.pubinfo.add((npub.assertion.identifier, flask.current_app.NS.prov.wasRevisionOf, r)) flask.current_app.nanopub_manager.publish(npub) print "Published", npub.identifier