Exemple #1
0
def task_gist(request, uid, query=None, return_gist=False):
    '''task_gist will return a cypher gist for a task, including nodes and relations
    :param uid: the uid for the task
    :param query: a custom query. If not defined, will show a table of concepts asserted.
    :param return_gist: if True, will return the context with all needed variables
    '''
    task_cypher, lookup = Task.cypher(uid, return_lookup=True)
    task_cypher = add_cypher_relations(task_cypher, lookup)

    task = Task.get(uid)[0]
    if query is None:
        query = "MATCH (t:task)-[r:ASSERTS]->(c:concept) RETURN t.name as task_name,c.name as concept_name;"

    # Join by newline
    task_cypher["links"] = "\n".join(task_cypher["links"])
    task_cypher["nodes"] = "\n".join(task_cypher["nodes"])

    context = {
        "relations": task_cypher["links"],
        "nodes": task_cypher["nodes"],
        "node_type": "task",
        "node_name": task["name"],
        "query": query
    }
    if return_gist is True:
        return context
    return render(request, 'graph/gist.html', context)
Exemple #2
0
def task_gist(request,uid,query=None,return_gist=False):
    '''task_gist will return a cypher gist for a task, including nodes and relations
    :param uid: the uid for the task
    :param query: a custom query. If not defined, will show a table of concepts asserted.
    :param return_gist: if True, will return the context with all needed variables
    '''    
    task_cypher,lookup = Task.cypher(uid,return_lookup=True)
    task_cypher = add_cypher_relations(task_cypher,lookup)

    task = Task.get(uid)[0]
    if query == None:
        query = "MATCH (t:task)-[r:ASSERTS]->(c:concept) RETURN t.name as task_name,c.name as concept_name;"

    # Join by newline
    task_cypher["links"] = "\n".join(task_cypher["links"])
    task_cypher["nodes"] = "\n".join(task_cypher["nodes"])

    context = {"relations":task_cypher["links"],
               "nodes":task_cypher["nodes"],
               "node_type":"task",
               "node_name":task["name"],
               "query":query}
    if return_gist == True:
        return context
    return render(request,'graph/gist.html',context)
Exemple #3
0
def add_cypher_relations(cypher, lookup):
    '''add_cypher_relations will look up relations for connected nodes returned from an object. This is akin to
    adding one layer of the tree to the graph (and the function could be modified to add more)
    :param cypher: the cypher object, a dictionary with nodes and links as keys, each a list of them.
    '''
    node_types = list(lookup)
    for node_type in node_types:
        for term in lookup[node_type]:
            if node_type == "condition":
                new_cypher, lookup = Condition.cypher(term,
                                                      lookup=lookup,
                                                      return_lookup=True)
            elif node_type == "task":
                new_cypher, lookup = Task.cypher(term,
                                                 lookup=lookup,
                                                 return_lookup=True)
            elif node_type == "contrast":
                new_cypher, lookup = Contrast.cypher(term,
                                                     lookup=lookup,
                                                     return_lookup=True)
            elif node_type == "concept":
                new_cypher, lookup = Concept.cypher(term,
                                                    lookup=lookup,
                                                    return_lookup=True)
            cypher = merge_cypher(cypher, new_cypher)
    return cypher
Exemple #4
0
def add_cypher_relations(cypher,lookup):
    '''add_cypher_relations will look up relations for connected nodes returned from an object. This is akin to
    adding one layer of the tree to the graph (and the function could be modified to add more)
    :param cypher: the cypher object, a dictionary with nodes and links as keys, each a list of them.
    '''
    node_types = list(lookup)
    for node_type in node_types:
        for term in lookup[node_type]:
            if node_type == "condition":
                new_cypher,lookup = Condition.cypher(term,lookup=lookup,return_lookup=True)
            elif node_type == "task":
                new_cypher,lookup = Task.cypher(term,lookup=lookup,return_lookup=True)
            elif node_type == "contrast":
                new_cypher,lookup = Contrast.cypher(term,lookup=lookup,return_lookup=True)
            elif node_type == "concept":
                new_cypher,lookup = Concept.cypher(term,lookup=lookup,return_lookup=True)
            cypher = merge_cypher(cypher,new_cypher)
    return cypher