Exemple #1
0
def test_load_lexicon():
    lexicon = load_lexicon({
        "John": [{
            "d": "j",
            "t": "e"
        }],
        "good": [{
            "d": "Lx.Good(x)",
            "t": "et"
        }]
    })
    assert lexicon == {
        "John": [SentenceNode("John", parse_formula("j"), parse_type("e"))],
        "good":
        [SentenceNode("good", parse_formula("Lx.Good(x)"), parse_type("et"))],
    }
Exemple #2
0
def test_parsing_type_blank():
    with pytest.raises(ParseError):
        parse_type("     \t    \n \r \f")
Exemple #3
0
def test_parsing_type_empty_string():
    with pytest.raises(ParseError):
        parse_type("")
Exemple #4
0
def test_parsing_type_unknown_token():
    with pytest.raises(ParseError):
        parse_type("e?")
Exemple #5
0
def test_parsing_type_invalid_letter():
    with pytest.raises(ParseError):
        parse_type("b")
Exemple #6
0
def test_parsing_type_invalid_abbreviation():
    with pytest.raises(ParseError):
        parse_type("evt")
Exemple #7
0
def test_parsing_type_missing_output_type():
    with pytest.raises(ParseError):
        parse_type("<e>")
Exemple #8
0
def test_parsing_compound_type():
    assert parse_type("<e, t>") == ComplexType(TYPE_ENTITY, TYPE_TRUTH_VALUE)
Exemple #9
0
def test_parsing_type_trailing_input():
    with pytest.raises(ParseError):
        parse_type("<e, t> e")
Exemple #10
0
def test_parsing_type_missing_closing_bracket():
    with pytest.raises(ParseError):
        parse_type("<e, t")
Exemple #11
0
def test_parsing_type_missing_opening_bracket():
    with pytest.raises(ParseError):
        parse_type("e, t>")
Exemple #12
0
def test_parsing_big_compound_type_with_abbreviations():
    assert parse_type("<et, <e, st>>") == ComplexType(
        ComplexType(TYPE_ENTITY, TYPE_TRUTH_VALUE),
        ComplexType(TYPE_ENTITY, ComplexType(TYPE_WORLD, TYPE_TRUTH_VALUE)),
    )
Exemple #13
0
def test_parsing_big_compound_type():
    assert parse_type("<<e, t>, <e, <s, t>>>") == ComplexType(
        ComplexType(TYPE_ENTITY, TYPE_TRUTH_VALUE),
        ComplexType(TYPE_ENTITY, ComplexType(TYPE_WORLD, TYPE_TRUTH_VALUE)),
    )
Exemple #14
0
def test_types_are_AtomicType_class():
    typ = parse_type("<et, et>")
    assert isinstance(typ.left.left, AtomicType)
    assert isinstance(typ.left.right, AtomicType)
    assert isinstance(typ.right.left, AtomicType)
    assert isinstance(typ.right.right, AtomicType)
Exemple #15
0
def test_parsing_abbreviated_compound_types():
    assert parse_type("et") == ComplexType(TYPE_ENTITY, TYPE_TRUTH_VALUE)
    assert parse_type("vt") == ComplexType(TYPE_EVENT, TYPE_TRUTH_VALUE)
Exemple #16
0
def test_translate_unknown_word_in_sentence(lexicon):
    nodes = translate_sentence("John is whorlious", lexicon)

    assert len(nodes) == 2

    # TODO [2019-05-20]: For now, this is just wrong (but wrong in the expected way).
    assert nodes[0].text == "John is whorlious"
    assert nodes[0].formula == Call(Var("Whorlious"), Var("john"))
    assert nodes[0].type == TYPE_TRUTH_VALUE

    assert nodes[1].text == "John is whorlious"
    assert nodes[1].formula == Call(Var("John"), Var("whorlious"))
    assert nodes[1].type == TYPE_TRUTH_VALUE


pred = SentenceNode("does", parse_formula("Lx.P(x)"), parse_type("<e, t>"))
entity = SentenceNode("me", Var("me"), TYPE_ENTITY)


def test_combine_to_saturate_predicate():
    assert can_combine(pred, entity)
    node = combine(pred, entity)
    assert node.text == "does me"
    assert node.formula == Call(pred.formula, entity.formula)
    assert node.type == TYPE_TRUTH_VALUE


def test_combine_every_child(lexicon):
    every = lexicon["every"][0]
    child = lexicon["child"][0]
    node = combine(every, child)
Exemple #17
0
def test_parsing_type_missing_comma():
    with pytest.raises(ParseError):
        parse_type("<e t>")
Exemple #18
0
def test_parsing_atomic_types():
    assert parse_type("e") == TYPE_ENTITY
    assert parse_type("t") == TYPE_TRUTH_VALUE
    assert parse_type("v") == TYPE_EVENT
    assert parse_type("s") == TYPE_WORLD