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"))], }
def test_parsing_type_blank(): with pytest.raises(ParseError): parse_type(" \t \n \r \f")
def test_parsing_type_empty_string(): with pytest.raises(ParseError): parse_type("")
def test_parsing_type_unknown_token(): with pytest.raises(ParseError): parse_type("e?")
def test_parsing_type_invalid_letter(): with pytest.raises(ParseError): parse_type("b")
def test_parsing_type_invalid_abbreviation(): with pytest.raises(ParseError): parse_type("evt")
def test_parsing_type_missing_output_type(): with pytest.raises(ParseError): parse_type("<e>")
def test_parsing_compound_type(): assert parse_type("<e, t>") == ComplexType(TYPE_ENTITY, TYPE_TRUTH_VALUE)
def test_parsing_type_trailing_input(): with pytest.raises(ParseError): parse_type("<e, t> e")
def test_parsing_type_missing_closing_bracket(): with pytest.raises(ParseError): parse_type("<e, t")
def test_parsing_type_missing_opening_bracket(): with pytest.raises(ParseError): parse_type("e, t>")
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)), )
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)), )
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)
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)
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)
def test_parsing_type_missing_comma(): with pytest.raises(ParseError): parse_type("<e t>")
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