(g: SemanticGraph)
return new_graphs
Adds a numeric restriction to the last added edge in the graph.

    :param g: a graph with a non-empty list of edges
    :return: a list of suggested graphs
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76")], free_entities=[{'linkings':[("Q37876", "Natalie Portman")], 'tokens':["Portman"], 'type':'PERSON'}, {'linkings': [('2012', '2012')], 'type': 'YEAR', 'tokens': ['2012']}]))
    [SemanticGraph([Edge(0, ?qvar-None->Q76~None->2012)], 1)]
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='2009')], free_entities=[{'linkings': [('2012', '2012')], 'type': 'YEAR', 'tokens': ['2012']}]))
    []
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='2009')]))
    []
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='2009')], free_entities=[{'linkings':[("Q37876", "Natalie Portman")], 'tokens':["Portman"], 'type':'PERSON'}]))
    []
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76")]))
    [SemanticGraph([Edge(0, ?qvar-None->Q76~None->MIN)], 0), SemanticGraph([Edge(0, ?qvar-None->Q76~None->MAX)], 0)]
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='MIN')]))
    []
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='MIN'), Edge(leftentityid=QUESTION_VAR, rightentityid="Q5")]))
    []
Adds a numeric restriction to the last added edge in the graph.
Adds a numeric restriction to the last added edge in the graph .
def last_edge_numeric_constraint(g: SemanticGraph):
    """
    Adds a numeric restriction to the last added edge in the graph.

    :param g: a graph with a non-empty list of edges
    :return: a list of suggested graphs
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76")], free_entities=[{'linkings':[("Q37876", "Natalie Portman")], 'tokens':["Portman"], 'type':'PERSON'}, {'linkings': [('2012', '2012')], 'type': 'YEAR', 'tokens': ['2012']}]))
    [SemanticGraph([Edge(0, ?qvar-None->Q76~None->2012)], 1)]
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='2009')], free_entities=[{'linkings': [('2012', '2012')], 'type': 'YEAR', 'tokens': ['2012']}]))
    []
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='2009')]))
    []
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='2009')], free_entities=[{'linkings':[("Q37876", "Natalie Portman")], 'tokens':["Portman"], 'type':'PERSON'}]))
    []
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76")]))
    [SemanticGraph([Edge(0, ?qvar-None->Q76~None->MIN)], 0), SemanticGraph([Edge(0, ?qvar-None->Q76~None->MAX)], 0)]
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='MIN')]))
    []
    >>> last_edge_numeric_constraint(SemanticGraph([Edge(leftentityid=QUESTION_VAR, rightentityid="Q76", qualifierentityid='MIN'), Edge(leftentityid=QUESTION_VAR, rightentityid="Q5")]))
    []
    """
    if len(g.edges) == 0 or g.edges[-1].qualifierentityid is not None:
        return []
    new_graphs = []
    entities_to_consider = [e for e in g.free_entities if e.get("type") == 'YEAR']
    skipped = [e for e in g.free_entities if e.get("type") != 'YEAR']
    if not entities_to_consider and not any(e.temporal for e in g.edges) and QUESTION_VAR in g.edges[-1].nodes():
        add_args = []
        sorting = 'MIN'
        if len(argmin_markers & set(g.tokens)) > 0:
            add_args = arg_relations['MIN']
            sorting = 'MIN'
        elif len(argmax_markers & set(g.tokens)) > 0:
            add_args = arg_relations['MAX']
            sorting = 'MAX'
        for rel in add_args:
            new_g = copy(g)
            new_g.free_entities = skipped[:]
            edge_to_modify = new_g.edges[-1]
            edge_to_modify.qualifierentityid = sorting
            edge_to_modify.qualifierrelationid = rel
            new_graphs.append(new_g)
    while entities_to_consider:
        entity = entities_to_consider.pop(0)
        if entity.get('linkings'):
            for rel in year_relations:
                new_g = copy(g)
                new_g.free_entities = skipped[:] + entities_to_consider[:]
                edge_to_modify = new_g.edges[-1]
                edge_to_modify.qualifierentityid = entity['linkings'][0][0]
                edge_to_modify.qualifierrelationid = rel
                new_graphs.append(new_g)
    return new_graphs
def last_edge_numeric_constraint ( g : SemanticGraph ) : if len ( g . edges ) == 0 or g . edges [ - 1 ] . qualifierentityid is not None : return [ ] new_graphs = [ ] entities_to_consider = [ e for e in g . free_entities if e . get ( "type" ) == 'YEAR' ] skipped = [ e for e in g . free_entities if e . get ( "type" ) != 'YEAR' ] if not entities_to_consider and not any ( e . temporal for e in g . edges ) and QUESTION_VAR in g . edges [ - 1 ] . nodes ( ) : add_args = [ ] sorting = 'MIN' if len ( argmin_markers & set ( g . tokens ) ) > 0 : add_args = arg_relations [ 'MIN' ] sorting = 'MIN' elif len ( argmax_markers & set ( g . tokens ) ) > 0 : add_args = arg_relations [ 'MAX' ] sorting = 'MAX' for rel in add_args : new_g = copy ( g ) new_g . free_entities = skipped [ : ] edge_to_modify = new_g . edges [ - 1 ] edge_to_modify . qualifierentityid = sorting edge_to_modify . qualifierrelationid = rel new_graphs . append ( new_g ) while entities_to_consider : entity = entities_to_consider . pop ( 0 ) if entity . get ( 'linkings' ) : for rel in year_relations : new_g = copy ( g ) new_g . free_entities = skipped [ : ] + entities_to_consider [ : ] edge_to_modify = new_g . edges [ - 1 ] edge_to_modify . qualifierentityid = entity [ 'linkings' ] [ 0 ] [ 0 ] edge_to_modify . qualifierrelationid = rel new_graphs . append ( new_g ) return new_graphs