def _build_reply_templates(): """ :return: Accept and Failure message templates """ accepted = CGraph() failure = CGraph() response_node = BNode() agent_node = BNode() accepted.add((response_node, RDF.type, STOA.Root)) accepted.add((response_node, RDF.type, STOA.Accepted)) accepted.add((agent_node, RDF.type, FOAF.Agent)) accepted.add((response_node, STOA.responseNumber, Literal("0", datatype=XSD.unsignedLong))) accepted.add((response_node, STOA.submittedBy, agent_node)) accepted.add( (agent_node, STOA.agentId, LIT_AGENT_ID)) accepted.bind('types', TYPES) accepted.bind('stoa', STOA) accepted.bind('foaf', FOAF) for triple in accepted: failure.add(triple) failure.set((response_node, RDF.type, STOA.Failure)) for (prefix, ns) in accepted.namespaces(): failure.bind(prefix, ns) return accepted, failure
def build_reply(template, reply_to, comment=None): """ :param template: A specific message template graph :param reply_to: Recipient Agent UUID :param comment: Optional comment :return: The reply graph """ reply_graph = CGraph() root_node = None for (s, p, o) in template: if o == STOA.Root: root_node = s else: reply_graph.add((s, p, o)) reply_graph.add((root_node, STOA.responseTo, Literal(reply_to, datatype=TYPES.UUID))) reply_graph.set((root_node, STOA.submittedOn, Literal(datetime.now()))) reply_graph.set((root_node, STOA.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