def build_reply(template, reply_to, comment=None): reply_graph = CGraph() root_node = None for (s, p, o) in template: reply_graph.add((s, p, o)) if p == RDF.type: root_node = s reply_graph.add((root_node, CURATOR.responseTo, Literal(reply_to, datatype=TYPES.UUID))) reply_graph.set((root_node, CURATOR.submittedOn, Literal(datetime.now()))) reply_graph.set((root_node, CURATOR.messageId, Literal(str(uuid.uuid4()), datatype=TYPES.UUID))) if comment is not None: reply_graph.set((root_node, RDFS.comment, Literal(comment, datatype=XSD.string))) for (prefix, ns) in template.namespaces(): reply_graph.bind(prefix, ns) return reply_graph
def _build(self): log.debug('Building a response to request number {}'.format(self._request_id)) graph = CGraph() resp_node = BNode('#response') graph.add((resp_node, RDF.type, CURATOR.EnrichmentResponse)) graph.add((resp_node, CURATOR.messageId, Literal(str(uuid.uuid4()), datatype=TYPES.UUID))) graph.add((resp_node, CURATOR.responseTo, Literal(self.sink.message_id, datatype=TYPES.UUID))) graph.add((resp_node, CURATOR.responseNumber, Literal("1", datatype=XSD.unsignedLong))) graph.add((resp_node, CURATOR.targetResource, self.sink.enrichment_data.target)) graph.add((resp_node, CURATOR.submittedOn, Literal(datetime.now()))) curator_node = BNode('#curator') graph.add((resp_node, CURATOR.submittedBy, curator_node)) graph.add((curator_node, RDF.type, FOAF.Agent)) graph.add((curator_node, CURATOR.agentId, CURATOR_UUID)) addition_node = BNode('#addition') graph.add((resp_node, CURATOR.additionTarget, addition_node)) graph.add((addition_node, RDF.type, CURATOR.Variable)) for link, v in self.sink.enrichment_data.links: trs = self.graph().triples((self.sink.enrichment_data.target, link, None)) for (_, _, o) in trs: graph.add((addition_node, link, o)) yield graph.serialize(format='turtle'), {}
def _build_reply_templates(): accepted = CGraph() failure = CGraph() response_node = BNode() curator_node = BNode() accepted.add((response_node, RDF.type, CURATOR.Accepted)) accepted.add((curator_node, RDF.type, FOAF.Agent)) accepted.add((response_node, CURATOR.responseNumber, Literal("0", datatype=XSD.unsignedLong))) accepted.add((response_node, CURATOR.submittedBy, curator_node)) accepted.add((response_node, CURATOR.submittedBy, curator_node)) accepted.add( (curator_node, CURATOR.agentId, CURATOR_UUID)) accepted.bind('types', TYPES) accepted.bind('curator', CURATOR) accepted.bind('foaf', FOAF) for triple in accepted: failure.add(triple) failure.set((response_node, RDF.type, CURATOR.Failure)) for (prefix, ns) in accepted.namespaces(): failure.bind(prefix, ns) return accepted, failure