Пример #1
0
class FragmentRequest(DeliveryRequest):
    def __init__(self):
        super(FragmentRequest, self).__init__()
        self.__pattern_graph = CGraph()
        self.__pattern_graph.bind('curator', CURATOR)
        try:
            prefixes = agora_client.prefixes
            for p in prefixes:
                self.__pattern_graph.bind(p, prefixes[p])
        except Exception, e:
            raise EnvironmentError(e.message)
Пример #2
0
 def __init__(self):
     from sdh.curator.actions.core import CURATOR, AMQP
     self._graph = CGraph()
     self._graph.bind('curator', CURATOR)
     self._graph.bind('amqp', AMQP)
     self._request_node = None
     self._fields = {}
Пример #3
0
class Request(object):
    def __init__(self):
        from sdh.curator.actions.core import CURATOR, AMQP
        self._graph = CGraph()
        self._graph.bind('curator', CURATOR)
        self._graph.bind('amqp', AMQP)
        self._request_node = None
        self._fields = {}

    def parse(self, message):
        log.debug('Parsing message...')
        try:
            self._graph.parse(StringIO.StringIO(message), format='turtle')
        except Exception, e:
            raise SyntaxError(e.message)

        self._extract_content()
Пример #4
0
 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'), {}
Пример #5
0
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
Пример #6
0
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