Example #1
0
def test_get_entities_data(mocker):
    store = ModelStore()

    serviceid = "MedicalAssistant-test"
    model_type = "ner"
    datasources_map = dict(
        predefined_entities=[
            "PERSON", "NORP", "FACILITY", "ORG", "GPE", "LOC", "PRODUCT",
            "EVENT", "WORK_OF_ART", "LANGUAGE", "ORDINAL"
        ],
        entities=["CATEGORY", "DISEASE", "DOCTOR", "PATIENT"],
        patterns=[
            dict(
                entity="custom_date",
                pattern=
                "\\d{4}\\s/\\s\\d{2}\\s/\\s\\d{2}|\\d{2}\\s/\\s\\d{2}\\s/\\s\\d{4}"
            ),
            dict(entity="custom_email",
                 pattern="[a-z0-9A-Z_.-]+@[da-zA-Z.-]+.[a-zA-Z.]{2,6}")
        ],
        distinct_token_list=[],
        intents=[],
        synonymMappings=[])
    default_engine = "ice_commons.er.engines.spacy_ner.SpacyDefaultNER"
    custom_engine = "ice_commons.er.engines.mitie_ner.MitieCustomNER"
    pos = True
    projects_map = dict(
        custom_entity_model="ice_commons.er.engines.mitie_ner.MitieCustomNER",
        ner_status="trained",
        language="EN",
        predefined_entity_model=
        "ice_commons.er.engines.spacy_ner.SpacyDefaultNER")

    original_text = "Is Dr . Manu Nair , Cardiologist available for a consultation on 21 / 10 / 2018 at 2 PM "
    text = "Is Dr . Manu Nair , cardiologist available for a consultation on 21 / 10 / 2018 at 2 PM"

    model = mocker.patch('ice_commons.store.models.ModelStore.get_model')
    model.return_value.predict.return_value = ([], [])
    mocker.patch(
        'ice_commons.store.models.ModelStore.filter_prediction_results',
        return_value=[
            dict(start=12, tag='custom_date', end=17, entity='21 / 10 / 2018')
        ])
    ice_ent = mocker.patch('ice_commons.store.models.IceEntitiesModelManager')
    ice_ent.return_value.get_ice_entities.return_value = []
    mocker.patch('ice_commons.store.models.ModelStore.get_resolved_mappings',
                 return_value=[])
    mocker.patch('ice_commons.store.models.ModelStore.get_entities_for_ds',
                 return_value=[[], [], []])

    resp = (store.get_entities(serviceid, model_type, custom_engine, text,
                               original_text, pos, default_engine,
                               datasources_map, projects_map))
    assert resp == ([{
        'start': 12,
        'tag': 'custom_date',
        'end': 17,
        'entity': '21 / 10 / 2018'
    }], [])
Example #2
0
def test_get_entities_null(mocker):
    store = ModelStore()
    serviceid = model_type = custom_engine = text = original_text = pos = default_engine = ""
    datasources_map = projects_map = {}
    model = mocker.patch('ice_commons.store.models.ModelStore.get_model')
    model.return_value.predict.return_value = ([], [])
    mocker.patch(
        'ice_commons.store.models.ModelStore.filter_prediction_results')
    ice_ent = mocker.patch('ice_commons.store.models.IceEntitiesModelManager')
    ice_ent.return_value.get_ice_entities.return_value = []
    mocker.patch('ice_commons.store.models.ModelStore.get_resolved_mappings',
                 return_value=[])
    mocker.patch('ice_commons.store.models.ModelStore.get_entities_for_ds',
                 return_value=[[], [], []])

    resp = (store.get_entities(serviceid, model_type, custom_engine, text,
                               original_text, pos, default_engine,
                               datasources_map, projects_map))
    assert resp == ([], None)