(g: SemanticGraph)
return denotations
Convert the given graph to a WikiData query and retrieve the denotations of the graph. The results contain the
     list of the possible graph denotations

    :param g: graph as a SemanticGraph
    :return: graph denotations as a list of dictionaries
    >>> get_graph_denotations(SemanticGraph([Edge(leftentityid='Q35637', relationid='P1346', rightentityid=QUESTION_VAR, qualifierentityid='2009')]))
    ['Q76']
    >>> get_graph_denotations(SemanticGraph([Edge(leftentityid='Q37320', relationid='P131', rightentityid='?m0Q37320'), Edge(leftentityid='?m0Q37320', relationid='P421', rightentityid=QUESTION_VAR)]))
    ['Q941023', 'Q28146035']
Convert the given graph to a WikiData query and retrieve the denotations of the graph. The results contain the
     list of the possible graph denotations
Convert the given graph to a WikiData query and retrieve the denotations of the graph . The results contain the list of the possible graph denotations
def get_graph_denotations(g: SemanticGraph):
    """
    Convert the given graph to a WikiData query and retrieve the denotations of the graph. The results contain the
     list of the possible graph denotations

    :param g: graph as a SemanticGraph
    :return: graph denotations as a list of dictionaries
    >>> get_graph_denotations(SemanticGraph([Edge(leftentityid='Q35637', relationid='P1346', rightentityid=QUESTION_VAR, qualifierentityid='2009')]))
    ['Q76']
    >>> get_graph_denotations(SemanticGraph([Edge(leftentityid='Q37320', relationid='P131', rightentityid='?m0Q37320'), Edge(leftentityid='?m0Q37320', relationid='P421', rightentityid=QUESTION_VAR)]))
    ['Q941023', 'Q28146035']
    """
    qvar_name = QUESTION_VAR[1:]
    if "zip" in g.tokens and any(e.relationid == "P281" for e in g.edges):
        denotations = endpoint_access.query_wikidata(graph_to_query(g, limit=100))
        denotations = [r for r in denotations if any('x' not in r[b] for b in r)]  # Post process zip codes
        post_processed = []
        for r in denotations:
            codes = re.split("[-–]", r[qvar_name])
            for p in codes:
                if p:
                    if len(p) < len(codes[0]):
                        p = codes[0][:(len(codes[0])) - len(p)] + p
                    post_processed.append(p)
        return post_processed
    edges = [e for e in g.edges if e.rightentityid != "Q5"]  # filter out edges with human as argument since they often fail
    denotations = endpoint_access.query_wikidata(graph_to_query(SemanticGraph(edges=edges), limit=100))
    if denotations and all('step' in d for d in denotations):
        min_transitive_steps = min([d['step'] for d in denotations])
        denotations = [d for d in denotations if d['step'] == min_transitive_steps]
    denotations = list({d[qvar_name] for d in denotations if qvar_name in d})
    if not sentence.get_question_type(" ".join(g.tokens)) == 'temporal':
        denotations = filter_auxiliary_entities_by_id(denotations)  # Filter out WikiData auxiliary variables, e.g. Q24523h-87gf8y48
    else:
        denotations = [l for _, labels in queries.get_labels_for_entities(denotations).items() for l in labels]
    return denotations
def get_graph_denotations ( g : SemanticGraph ) : qvar_name = QUESTION_VAR [ 1 : ] if "zip" in g . tokens and any ( e . relationid == "P281" for e in g . edges ) : denotations = endpoint_access . query_wikidata ( graph_to_query ( g , limit = 100 ) ) denotations = [ r for r in denotations if any ( 'x' not in r [ b ] for b in r ) ] # Post process zip codes post_processed = [ ] for r in denotations : codes = re . split ( "[-–]",  r q v ar_name]) for p in codes : if p : if len ( p ) < len ( codes [ 0 ] ) : p = codes [ 0 ] [ : ( len ( codes [ 0 ] ) ) - len ( p ) ] + p post_processed . append ( p ) return post_processed edges = [ e for e in g . edges if e . rightentityid != "Q5" ] # filter out edges with human as argument since they often fail denotations = endpoint_access . query_wikidata ( graph_to_query ( SemanticGraph ( edges = edges ) , limit = 100 ) ) if denotations and all ( 'step' in d for d in denotations ) : min_transitive_steps = min ( [ d [ 'step' ] for d in denotations ] ) denotations = [ d for d in denotations if d [ 'step' ] == min_transitive_steps ] denotations = list ( { d [ qvar_name ] for d in denotations if qvar_name in d } ) if not sentence . get_question_type ( " " . join ( g . tokens ) ) == 'temporal' : denotations = filter_auxiliary_entities_by_id ( denotations ) # Filter out WikiData auxiliary variables, e.g. Q24523h-87gf8y48 else : denotations = [ l for _ , labels in queries . get_labels_for_entities ( denotations ) . items ( ) for l in labels ] return denotations