コード例 #1
0
def test_BeliefTriplet():
    nlp = load_danish(transformer=None)
    doc = nlp("Dette består af to sætninger")
    span = next(doc.sents)

    path = (0, 1, 2, 3)
    bt = BeliefTriplet(
        head_id=path[0],
        relation_ids=path[1:-1],
        tail_id=path[-1],
        span=span,
        confidence=1,
    )

    assert len(bt.relation_list) == 2
    assert isinstance(bt.confidence, float)
    assert isinstance(bt.head_span, Span)
    assert isinstance(bt.head, str)

    path = (3, 1, 2, 0)
    rev_bt = BeliefTriplet(
        head_id=path[0],
        relation_ids=path[1:-1],
        tail_id=path[-1],
        span=span,
        confidence=1,
    )

    assert bt < rev_bt, "belief triplets should be sorted according to their heads"
コード例 #2
0
def simple_triplets() -> List[BeliefTriplet]:
    nlp = load_danish(transformer=None)
    doc = nlp("Dette består af to sætninger")
    span = next(doc.sents)

    path = (0, 1, 2, 3)
    bt = BeliefTriplet(
        head_id=path[0],
        relation_ids=path[1:-1],
        tail_id=path[-1],
        span=span,
        confidence=1,
    )

    doc = nlp("Mit navn er Kenneth. .")
    span = next(doc.sents)

    path = (0, 1, 2)
    bt_ = BeliefTriplet(
        head_id=path[0],
        relation_ids=path[1:-1],
        tail_id=path[-1],
        span=span,
        confidence=1,
    )
    return [bt, bt_]
コード例 #3
0
def create_graph_with_filters(triplet_filters, group_filters):
    nlp = bg.load_danish()
    bp = bg.BeliefParser(nlp=nlp)

    graph = bg.BeliefGraph(parser=bp, triplet_filters=[], group_filters=[])
    graph.add_texts(EXAMPLES)
    graph.replace_filters(triplet_filters=triplet_filters,
                          group_filters=group_filters)
    return graph
コード例 #4
0
def test_belief_parser():
    nlp = bg.load_danish()
    belief_parser = bg.BeliefParser(nlp=nlp)
    triplets = belief_parser.parse_texts(EXAMPLE)

    assert isinstance(triplets, Iterable)

    triplets = list(triplets)
    assert isinstance(triplets[0], bg.BeliefTriplet)

    for t in triplets:
        print(t)
コード例 #5
0
def simple_graph():
    nlp = bg.load_danish()
    bp = bg.BeliefParser(nlp=nlp)

    graph = bg.BeliefGraph(parser=bp, triplet_filters=[], group_filters=[])
    return graph