Example #1
0
def contrast_gist(request, uid, query=None, return_gist=False):
    '''contrast_gist is currently a sub for some "view_contrast" view (that should
    be defined as views.view_contrast, as a simple graph seems more appropriate
    to show a contrast and its conditions than some static thing we would render!
    :param uid: the uid for the contrast
    :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
    '''
    contrast_cypher, lookup = Contrast.cypher(uid, return_lookup=True)
    contrast_cypher = add_cypher_relations(contrast_cypher, lookup)

    contrast = Contrast.get(uid)[0]
    if query is None:
        query = "MATCH (c:condition)-[r:HASCONTRAST]->(con:contrast) WHERE con.id='%s' RETURN c.name as condition_name,con.name as contrast_name;" % (
            uid)

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

    context = {
        "relations": contrast_cypher["links"],
        "nodes": contrast_cypher["nodes"],
        "node_type": "contrast",
        "node_name": contrast["name"],
        "query": query
    }
    if return_gist is True:
        return context
    return render(request, 'graph/gist.html', context)
Example #2
0
def contrast_gist(request,uid,query=None,return_gist=False):
    '''contrast_gist is currently a sub for some "view_contrast" view (that should
    be defined as views.view_contrast, as a simple graph seems more appropriate 
    to show a contrast and its conditions than some static thing we would render!
    :param uid: the uid for the contrast
    :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
    '''
    contrast_cypher,lookup = Contrast.cypher(uid,return_lookup=True)
    contrast_cypher = add_cypher_relations(contrast_cypher,lookup)

    contrast = Contrast.get(uid)[0]
    if query == None:
        query = "MATCH (c:condition)-[r:HASCONTRAST]->(con:contrast) WHERE con.id='%s' RETURN c.name as condition_name,con.name as contrast_name;" %(uid)

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

    context = {"relations":contrast_cypher["links"],
               "nodes":contrast_cypher["nodes"],
               "node_type":"contrast",
               "node_name":contrast["name"],
               "query":query}
    if return_gist == True:
        return context
    return render(request,'graph/gist.html',context)
Example #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
Example #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