def deleteGraphs(self, wrapper): graphNames = wrapper.getGraphName() if type(graphNames) is str: # abstract wrapper returns one graph name ThreadedTriplestoreAdapter.getOrMake(graphNames).deleteGraph(graphNames) else: for graphName in graphNames: # composed abstract wrapper returns set with graph names ThreadedTriplestoreAdapter.getOrMake(graphName).deleteGraph(graphName)
def updateAverageQuality(self): job = self.getAvgQualities() graphs = self.createGraph(job) # save graph if self.rm.args.triplestore: ThreadedTriplestoreAdapter.getOrMake("citypulse/avgquality").deleteGraph("citypulse/avgquality") for graph in graphs: ThreadedTriplestoreAdapter.getOrMake("citypulse/avgquality").addGraph(graph)
def annotateEvent(self, event): """ Annotates the event and saves the graph in the triple store :param event: :return: returns the annotated graph of the event """ graph = self.annotator.annotateEvent(event, self.getEventDescription()) ThreadedTriplestoreAdapter.getOrMake(self.getEventDescription().graphname) return graph
def staticAnnotationEvent(cls, wrapper, configuration, messageBusQueue): sd = wrapper.getSensorDescription() if isinstance(sd, list): for _sd in sd: graph = StaticEventAnnotator.__staticAnnotationEvent(_sd, configuration) #TODO send graph over messagebus? # if messageBusQueue: # msg = graph.serialize(format='n3') # messageBusQueue.add((msg, RabbitMQ.exchange_wrapper_registration, _sd.messagebus.routingKey)) ThreadedTriplestoreAdapter.getOrMake(StaticEventAnnotator.event_repository_name).saveGraph(graph, StaticEventAnnotator.event_repository_name) else: graph = StaticEventAnnotator.__staticAnnotationEvent(sd, configuration) # if messageBusQueue: # msg = graph.serialize(format='n3') # messageBusQueue.add((msg, RabbitMQ.exchange_wrapper_registration, sd.messagebus.routingKey)) ThreadedTriplestoreAdapter.getOrMake(StaticEventAnnotator.event_repository_name).saveGraph(graph, StaticEventAnnotator.event_repository_name)
def receiveEventHandler(self, channel, method, properties, body): """ Receives messages through the message bus, annotates the event and sends the annotated event :param channel: :param method: :param properties: :param body: :return: """ event = JSONObject(str(body)) if event.ceType in self.eventDescriptions: # annotatedevent = self.annotator.annotateEvent(event, self.eventDescriptions[event.ceType]) # if self.rm.args.messagebus and self.messageBusSendQueue: # message = annotatedevent.serialize(format='n3') # self.messageBusSendQueue.add((message, RabbitMQ.exchange_annotated_event, event.ceType)) if self.rm.args.triplestore: ThreadedTriplestoreAdapter.getOrMake(self.eventDescriptions[event.ceType].graphName)
def staticAnnotationSensor(cls, wrapper, configuration, messageBusQueue, api=None): sd = wrapper.getSensorDescription() if isinstance(sd, list): for _sd in sd: graph = StaticAnnotator.__staticAnnotationSesnor(_sd, configuration) if messageBusQueue or api: msg = graph.serialize(format='n3') if messageBusQueue: messageBusQueue.add((msg, RabbitMQ.exchange_wrapper_registration, _sd.messagebus.routingKey)) if api: api.set_static_stream_data(str(_sd.uuid), msg) if ThreadedTriplestoreAdapter.triplestore: ThreadedTriplestoreAdapter.getOrMake(StaticAnnotator.service_repository_name).saveGraph(graph, StaticAnnotator.service_repository_name) else: graph = StaticAnnotator.__staticAnnotationSesnor(sd, configuration) if messageBusQueue or api: msg = graph.serialize(format='n3') if messageBusQueue: messageBusQueue.add((msg, RabbitMQ.exchange_wrapper_registration, sd.messagebus.routingKey)) if api: api.set_static_stream_data(str(sd.uuid), msg) if ThreadedTriplestoreAdapter.triplestore: ThreadedTriplestoreAdapter.getOrMake(StaticAnnotator.service_repository_name).saveGraph(graph, StaticAnnotator.service_repository_name)