Пример #1
0
   def handle_DATA(self,msg):
       global connections
       failed_recipients=[]

       m=QueryParser(msg)
       recipients=m.getUsers()
       data=m.getReply()
       sensors=m.getSensors()
       cmds=m.getCmds()
       '''
       print "R->",recipients
       print "D->",data
       print "S->",sensors
       print "C->",cmds.keys()
       '''
       for recipient in recipients:
         if self.is_connected(recipient):
            if "DATA" in cmds.keys() or "ERR" in cmds.keys():
               connections[recipient].sendMessage("@"+self.user+" "+data,False)
            elif "GET" in cmds.keys() or "PUT" in cmds.keys():
                if self.is_allow(recipient,sensors):
                   connections[recipient].sendMessage("@"+self.user+" "+data,False)
                else:failed_recipients.append(recipient)
            else:failed_recipients.append(recipient)
         else:failed_recipients.append(recipient)

       if len(failed_recipients)==0:
          self.sendMessage("Done",False)
       else:
          self.sendMessage("Failed:"+str(failed_recipients),False)
Пример #2
0
    def query(self, query):

        if query is None:
            return Results.list_commands()

        # print query

        query_segments = query.lower().split(" ", 1)
        command = query_segments[0]

        if len(query_segments) == 2:
            args = query_segments[1]
        else:
            args = None

        command_suggestions = QueryParser.parse_command(command)

        print(command_suggestions)

        if args is not None and len(command_suggestions) == 1:
            if not self.ensure_connection():
                return
            return Results.list_music(self.__client, self.__album_art_cache,
                                      command_suggestions[0], args)
        else:
            return Results.list_commands(command_suggestions)
Пример #3
0
def layer_query(request, service_name):
    layer = layers_provider.get_layer(service_name, request)
    query_params = QueryParser.parse(request)
    # print (query_params.__dict__.keys())
    # TODO validate query params before calling GeoDjangoQuery.query
    query_result = GeoDjangoQuery.query(layer, query_params)
    context = get_context(dict(json=query_result, layer=layer))
    return response_to_format(request, context, REST_ENDPOINT_LAYER_QUERY_TPL)
def layer_query(request, service_name):
    layer = layers_provider.get_layer(service_name, request)
    query_params = QueryParser.parse(request)
    # print (query_params.__dict__.keys())
    # TODO validate query params before calling GeoDjangoQuery.query
    query_result = GeoDjangoQuery.query(layer, query_params)
    context = get_context(dict(
        json=query_result,
        layer=layer
    ))
    return response_to_format(request, context, REST_ENDPOINT_LAYER_QUERY_TPL)
Пример #5
0
    def _compile(self):
        """
        Compile this query

        Before calling compile, be sure that they queryString
        and any parameters have been set
        """
        if not self.queryString or self.queryString == "":
            return

        log.debug(u"RepoQuery.compile(): %s" % self.queryString)

        if self.queryString:
            self.ast = QueryParser.parse('stmt', self.queryString)
            log.debug(u"compile: AST = %s" % self.ast)
            self._logical_plan = self.__analyze(self.ast)
            self._queryStringIsStale = False
            self.stale = True
        else:
            self._logical_plan = None
            self.stale = True
Пример #6
0
    def _compile(self):
        """
        Compile this query

        Before calling compile, be sure that they queryString
        and any parameters have been set
        """
        if not self.queryString or self.queryString == "":
            return

        log.debug(u"RepoQuery.compile(): %s" % self.queryString)

        if self.queryString:
            self.ast = QueryParser.parse('stmt', self.queryString)
            log.debug(u"compile: AST = %s" % self.ast)
            self._logical_plan = self.__analyze(self.ast)
            self._queryStringIsStale = False
            self.stale = True
        else:
            self._logical_plan = None
            self.stale = True
Пример #7
0
def NETSNetworkBuilder(input1):
    '''
    Function takes several strings as arguments from the user and with them generates and NETS abstraction network with
    edge metadata.
    :param input1: string containing file path/name for SPARQL query
    '''

    print str('Started building OWL-NETS Abstraction Network: ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    print '\n'

    # input1 = 'SPARQL_Queries/Trametinib_query'
    # input1 = 'SPARQL_Queries/Angiogenesis_query'
    # input1 = 'SPARQL_Queries/DDI_reactome_query'
    # input1 = 'SPARQL_Queries/DisGeNet_Query'

    # parse query and return triples
    query_text = QueryParser.QueryParser(input1)

    # create a graph representation of query
    graph = GraphMaker(query_text[0])

    # visualize graph
    # A = nx.nx_agraph.to_agraph(graph)
    # A.draw('example.png', prog='dot', edge_data='predicate')

    ## NETS NODES
    # will return a list of NETS nodes
    NETS_nodes = NETSNodeFinder(graph)

    ## NETS EDGES
    # create sub-graph from graph with NETS_nodes and nodes with out degree > 0
    keep = [node for node in graph.nodes() if graph.out_degree(node) > 0 or node in NETS_nodes]
    sub_graph = graph.subgraph(keep)

    # get NETS edges and maintains order specified in query
    NETS_edges = NETSEdgeFinder(NETS_nodes, sub_graph)

    # get direction of NETS edges
    NETS_edge_order = EdgeDirection(graph, sub_graph, NETS_edges)
    # remove once KaBOB is updated
    # NETS_edge_order = [('?trem', '?drug'), ('?drug', '?trem'), ('?drug', '?targetBioEntity')]

    # get edge metadata
    NETS_edge_metadata = EdgeMetadata(graph, sub_graph, NETS_edge_order)

    # update query text
    updated_query_text = QueryParser.NETSQueryParser(query_text, NETS_nodes, NETS_edge_metadata)

    for x in updated_query_text[0].split('\n'):
        print x

    ## QUERY ENDPOINT
    # authentication file (format: url, user, password) - should be placed in same user directory as query
    authentication = 'SPARQL_Queries/authentication'

    # look to see if results already exist (if OWL-NETS was previously run)
    if str(input1.split('/')[-1]) + '_results.json' in os.listdir(''.join(str(input1.split('/')[-2]) + '/')):

        print 'Using existing query results'
        print '\n'

        with open(input1.rpartition(".")[-1] + "_results.json") as json_data:
            results = json.load(json_data)
    else:
        print 'Generating new query results'
        print '\n'

        # run query
        results = QueryRunner.RunQuery(updated_query_text[0], authentication)

        # export results to json file
        # input2 = 'Query_Data/Trametinib_query.json'
        with open(str(input1.rpartition(".")[-1] + "_results.json"), 'w') as outfile:
            json.dump(results, outfile)

    ## NETWORK POPULATION
    # get and set node metadata
    node_info = NodeDic(results, NETS_edge_metadata, updated_query_text[1:])

    # organize output for labeling edges
    edge_data = EdgeDic(NETS_edge_metadata[0])

    # build NETS graph
    NETS_graph = NETSGraph(results, NETS_edge_order, DictCleaner(node_info[0], 'id', 'label'), node_info[1], edge_data)

    # write graphs to gml and JSON files
    # input3 = 'Network_Data/Angiogenesis_query_NETS'
    nx.write_gml(NETS_graph, str(input1.rpartition(".")[-1] + "_NETS") + '_network.gml')
    GraphJson(NETS_graph, NETS_edge_metadata[1], str(input1.rpartition(".")[-1] + "_NETS") + '_network.json')

    print str(
        'Finished building OWL-NETS Representation network: ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + '\n'