Ejemplo n.º 1
0
def test_nested_and_query_entity_equality():
    """Tests NestedEntity and QueryEntity equality operations"""
    entity_a = NestedEntity(
        ("Entity", "Entity", "entity"),
        (Span(0, 5), ) * 3,
        (Span(0, 0), ) * 3,
        Entity("text", "type", "role", "value", "display"),
    )
    entity_b = QueryEntity(
        ("Entity", "Entity", "entity"),
        (Span(0, 5), ) * 3,
        (Span(0, 0), ) * 3,
        Entity("text", "type", "role", "value", "display"),
    )

    assert entity_a == entity_b
    assert not entity_a != entity_b

    entity_a = NestedEntity(
        ("Entity123", "Entity", "entity"),
        (Span(0, 5), ) * 3,
        (Span(0, 0), ) * 3,
        Entity("text", "type", "role", "value", "display"),
    )
    entity_b = QueryEntity(
        ("Entity", "Entity", "entity"),
        (Span(0, 5), ) * 3,
        (Span(0, 0), ) * 3,
        Entity("text", "type", "role", "value", "display"),
    )

    assert not entity_a == entity_b
    assert entity_a != entity_b
Ejemplo n.º 2
0
def test_query_entity_equality():
    """Tests query entity equality"""
    entity_a = QueryEntity(('Entity', 'Entity', 'entity'), (Span(0, 5), ) * 3,
                           (Span(0, 0), ) * 3,
                           Entity('text', 'type', 'role', 'value', 'display'))
    entity_b = QueryEntity(('Entity', 'Entity', 'entity'), (Span(0, 5), ) * 3,
                           (Span(0, 0), ) * 3,
                           Entity('text', 'type', 'role', 'value', 'display'))

    assert entity_a == entity_b
Ejemplo n.º 3
0
def test_dump_multi_nested(query_factory):
    """Tests dumping a query with multiple nested system entities"""
    query_text = "show me houses between 600,000 and 1,000,000 dollars"
    query = query_factory.create_query(query_text)

    lower = NestedEntity.from_query(query,
                                    Span(8, 14),
                                    parent_offset=15,
                                    entity_type="sys_number")
    upper = NestedEntity.from_query(query,
                                    Span(20, 28),
                                    parent_offset=15,
                                    entity_type="sys_number")
    raw_entity = Entity(
        "between 600,000 dollars and 1,000,000",
        "price",
        value={"children": [lower, upper]},
    )
    entities = [QueryEntity.from_query(query, Span(15, 51), entity=raw_entity)]
    processed_query = ProcessedQuery(query, entities=entities)

    markup_text = ("show me houses {between {600,000|sys_number} and "
                   "{1,000,000|sys_number} dollars|price}")

    assert markup.dump_query(processed_query) == markup_text
    assert markup.dump_query(processed_query, no_group=True) == markup_text
    assert markup.dump_query(processed_query, no_entity=True) == query_text
Ejemplo n.º 4
0
def test_query_entity_equality():
    """Tests query entity equality"""
    entity_a = QueryEntity(
        ("Entity", "Entity", "entity"),
        (Span(0, 5), ) * 3,
        (Span(0, 0), ) * 3,
        Entity("text", "type", "role", "value", "display"),
    )
    entity_b = QueryEntity(
        ("Entity", "Entity", "entity"),
        (Span(0, 5), ) * 3,
        (Span(0, 0), ) * 3,
        Entity("text", "type", "role", "value", "display"),
    )

    assert entity_a == entity_b
Ejemplo n.º 5
0
def test_canonical_text_rel(resolver_text_rel):
    """Tests that entity resolution works for a canonical entity in the map"""
    expected = {'id': '2', 'cname': 'Pine and Market'}
    predicted = resolver_text_rel.predict(
        Entity('Pine and Market', ENTITY_TYPE))[0]
    assert predicted['id'] == expected['id']
    assert predicted['cname'] == expected['cname']
Ejemplo n.º 6
0
def test_canonical_text_rel(resolver_text_rel):
    """Tests that entity resolution works for a canonical entity in the map"""
    expected = {"id": "2", "cname": "Pine and Market"}
    predicted = resolver_text_rel.predict(
        Entity("Pine and Market", ENTITY_TYPE))[0]
    assert predicted["id"] == expected["id"]
    assert predicted["cname"] == expected["cname"]
Ejemplo n.º 7
0
def test_entity_string():
    """Tests string representation of entities"""
    entity = NestedEntity(
        ("Entity", "Entity", "entity"),
        (Span(0, 5), ) * 3,
        (Span(0, 0), ) * 3,
        Entity("text", "type", "role", "value", "display"),
    )
    assert str(entity) == "type:role 'Entity' 0-5"
Ejemplo n.º 8
0
def test_nested_and_query_entity_equality():
    """Tests NestedEntity and QueryEntity equality operations"""
    entity_a = NestedEntity(('Entity', 'Entity', 'entity'), (Span(0, 5), ) * 3,
                            (Span(0, 0), ) * 3,
                            Entity('text', 'type', 'role', 'value', 'display'))
    entity_b = QueryEntity(('Entity', 'Entity', 'entity'), (Span(0, 5), ) * 3,
                           (Span(0, 0), ) * 3,
                           Entity('text', 'type', 'role', 'value', 'display'))

    assert entity_a == entity_b
    assert not entity_a != entity_b

    entity_a = NestedEntity(('Entity123', 'Entity', 'entity'),
                            (Span(0, 5), ) * 3, (Span(0, 0), ) * 3,
                            Entity('text', 'type', 'role', 'value', 'display'))
    entity_b = QueryEntity(('Entity', 'Entity', 'entity'), (Span(0, 5), ) * 3,
                           (Span(0, 0), ) * 3,
                           Entity('text', 'type', 'role', 'value', 'display'))

    assert not entity_a == entity_b
    assert entity_a != entity_b
Ejemplo n.º 9
0
def test_dump_nested(query_factory):
    """Tests dumping a query with a nested system entity"""
    query_text = "show me houses under 600,000 dollars"
    query = query_factory.create_query(query_text)

    nested = NestedEntity.from_query(
        query, Span(0, 6), parent_offset=21, entity_type="sys_number"
    )
    raw_entity = Entity("600,000 dollars", "price", value={"children": [nested]})
    entities = [QueryEntity.from_query(query, Span(21, 35), entity=raw_entity)]
    processed_query = ProcessedQuery(query, entities=entities)

    markup_text = "show me houses under {{600,000|sys_number} dollars|price}"
    assert markup.dump_query(processed_query) == markup_text
    assert markup.dump_query(processed_query, no_group=True) == markup_text
    assert markup.dump_query(processed_query, no_entity=True) == query_text
Ejemplo n.º 10
0
def test_entity_string():
    """Tests string representation of entities"""
    entity = NestedEntity(('Entity', 'Entity', 'entity'), (Span(0, 5), ) * 3,
                          (Span(0, 0), ) * 3,
                          Entity('text', 'type', 'role', 'value', 'display'))
    assert str(entity) == "type:role 'Entity' 0-5"
Ejemplo n.º 11
0
def test_entity_equality():
    """Tests entity equality"""
    entity_a = Entity('text', 'type', 'role', 'value', 'display')
    entity_b = Entity('text', 'type', 'role', 'value', 'display')

    assert entity_a == entity_b
Ejemplo n.º 12
0
def test_entity_equality():
    """Tests entity equality"""
    entity_a = Entity("text", "type", "role", "value", "display")
    entity_b = Entity("text", "type", "role", "value", "display")

    assert entity_a == entity_b
Ejemplo n.º 13
0
def test_synonym_deprecated_class(resolver_deprecated_class):
    """Tests that entity resolution works for an entity synonym in the map"""
    expected = {"id": "2", "cname": "Pine and Market"}
    predicted = resolver_deprecated_class.predict(Entity("Pine St", ENTITY_TYPE))[0]
    assert predicted["id"] == expected["id"]
    assert predicted["cname"] == expected["cname"]
Ejemplo n.º 14
0
def test_synonym(resolver):
    """Tests that entity resolution works for an entity synonym in the map"""
    expected = {'id': '2', 'cname': 'Pine and Market'}
    predicted = resolver.predict(Entity('Pine St', ENTITY_TYPE))[0]
    assert predicted['id'] == expected['id']
    assert predicted['cname'] == expected['cname']