Esempio n. 1
0
def test_entity_object_not_implemented() -> None:
    """
    Reshape converts json response from Duckling APIs
    to dialogy's BaseEntity.

    We are checking for an unknown entity type here.
    This would lead to a `NotImplementedError`.
    """
    entities_json = [config.mock_unknown_entity]
    parser = DucklingParser(locale="en_IN")

    with pytest.raises(NotImplementedError):
        parser.reshape(entities_json)
Esempio n. 2
0
def test_entity_object_error_on_missing_value() -> None:
    """
    This json has missing `value` key. We can see that we will get a
    `KeyError` raised, this happens during the validation phase.
    """
    entities_json = [{
        "body": "3 people",
        "start": 67,
        "end": 75,
        "dim": "people",
        "latent": False,
    }]
    parser = DucklingParser(locale="en_IN")

    with pytest.raises(KeyError):
        parser.reshape(entities_json)
Esempio n. 3
0
def test_entity_json_to_object_people_entity() -> None:
    """
    Reshape converts json response from Duckling APIs
    to dialogy's BaseEntity.

    We are checking for PeopleEntity here.

    """
    entities_json = [config.mock_people_entity]
    parser = DucklingParser(locale="en_IN")
    entities = parser.reshape(entities_json)
    assert isinstance(entities[0], PeopleEntity)
Esempio n. 4
0
def test_entity_json_to_object_time_interval_entity():
    """
    Reshape converts json response from Duckling APIs
    to dialogy's BaseEntity.

    We are checking for TimeIntervalEntity here.
    """
    parser = DucklingParser(locale="en_IN")
    entities_json = [config.mock_interval_entity]

    entities = parser.reshape(entities_json)
    assert isinstance(entities[0], TimeIntervalEntity)
Esempio n. 5
0
def test_entity_json_to_object_numerical_entity() -> None:
    """
    Reshape converts json response from Duckling APIs
    to dialogy's BaseEntity.

    We are checking for NumericalEntity here.
    """
    entities_json = [{
        "body": "four",
        "start": 7,
        "value": {
            "value": 4,
            "type": "value"
        },
        "end": 11,
        "dim": "number",
        "latent": False,
    }]
    parser = DucklingParser(locale="en_IN")
    entities = parser.reshape(entities_json)
    assert isinstance(entities[0], NumericalEntity)