Ejemplo n.º 1
0
def test_wit_response():
    from rasa.nlu.emulators.wit import WitEmulator

    em = WitEmulator()
    data = {
        "text":
        "I want italian food",
        "intent": {
            "name": "inform",
            "confidence": 0.4794813722432127
        },
        "entities": [{
            "entity": "cuisine",
            "value": "italian",
            "start": 7,
            "end": 14
        }],
    }
    norm = em.normalise_response_json(data)
    assert norm == [{
        "entities": {
            "cuisine": {
                "confidence": None,
                "type": "value",
                "value": "italian",
                "start": 7,
                "end": 14,
            }
        },
        "intent": "inform",
        "_text": "I want italian food",
        "confidence": 0.4794813722432127,
    }]
Ejemplo n.º 2
0
def _create_emulator(mode: Optional[Text]) -> NoEmulator:
    """Create emulator for specified mode.
    If no emulator is specified, we will use the Rasa NLU format."""

    if mode is None:
        return NoEmulator()
    elif mode.lower() == "wit":
        from rasa.nlu.emulators.wit import WitEmulator

        return WitEmulator()
    elif mode.lower() == "luis":
        from rasa.nlu.emulators.luis import LUISEmulator

        return LUISEmulator()
    elif mode.lower() == "dialogflow":
        from rasa.nlu.emulators.dialogflow import DialogflowEmulator

        return DialogflowEmulator()
    else:
        raise ErrorResponse(
            400,
            "BadRequest",
            "Invalid parameter value for 'emulation_mode'. "
            "Should be one of 'WIT', 'LUIS', 'DIALOGFLOW'.",
            {
                "parameter": "emulation_mode",
                "in": "query"
            },
        )
Ejemplo n.º 3
0
    def _create_emulator(mode: Optional[Text]) -> NoEmulator:
        """Create emulator for specified mode.

        If no emulator is specified, we will use the Rasa NLU format."""

        if mode is None:
            return NoEmulator()
        elif mode.lower() == 'wit':
            from rasa.nlu.emulators.wit import WitEmulator
            return WitEmulator()
        elif mode.lower() == 'luis':
            from rasa.nlu.emulators.luis import LUISEmulator
            return LUISEmulator()
        elif mode.lower() == 'dialogflow':
            from rasa.nlu.emulators.dialogflow import DialogflowEmulator
            return DialogflowEmulator()
        elif mode.lower() == 'lite':
            from litemind.nlu.emulators.lite import LiteEmulator
            return LiteEmulator()
        elif mode.lower() == 'coref':
            from litemind.nlu.emulators.coref import CorefEmulator
            return CorefEmulator()
        elif mode.lower() == 'entity':
            from litemind.nlu.emulators.entity import EntityEmulator
            return EntityEmulator()
        elif mode.lower() == 'link':
            from litemind.nlu.emulators.link import LinkEmulator
            return LinkEmulator()
        elif mode.lower() == 'relation':
            from litemind.nlu.emulators.relation import RelationEmulator
            return RelationEmulator()
        else:
            raise ValueError("unknown emulator mode : {0}".format(mode))
Ejemplo n.º 4
0
def test_wit_response():
    from rasa.nlu.emulators.wit import WitEmulator
    em = WitEmulator()
    data = {
        "text": "I want italian food",
        "intent": {"name": "inform", "confidence": 0.4794813722432127},
        "entities": [{"entity": "cuisine", "value": "italian",
                      "start": 7, "end": 14}]}
    norm = em.normalise_response_json(data)
    assert norm == [{
        'entities': {
            'cuisine': {
                'confidence': None,
                'type': 'value',
                'value': 'italian',
                'start': 7,
                'end': 14
            }
        },
        'intent': 'inform',
        '_text': 'I want italian food',
        'confidence': 0.4794813722432127,
    }]
Ejemplo n.º 5
0
    def _create_emulator(mode: Optional[Text]) -> NoEmulator:
        """Create emulator for specified mode.

        If no emulator is specified, we will use the Rasa NLU format."""

        if mode is None:
            return NoEmulator()
        elif mode.lower() == 'wit':
            from rasa.nlu.emulators.wit import WitEmulator
            return WitEmulator()
        elif mode.lower() == 'luis':
            from rasa.nlu.emulators.luis import LUISEmulator
            return LUISEmulator()
        elif mode.lower() == 'dialogflow':
            from rasa.nlu.emulators.dialogflow import DialogflowEmulator
            return DialogflowEmulator()
        else:
            raise ValueError("unknown mode : {0}".format(mode))
Ejemplo n.º 6
0
def test_wit_request():
    from rasa.nlu.emulators.wit import WitEmulator

    em = WitEmulator()
    norm = em.normalise_request_json({"text": ["arb text"]})
    assert norm == {"text": "arb text", "time": None}
Ejemplo n.º 7
0
def test_wit_response():
    from rasa.nlu.emulators.wit import WitEmulator

    em = WitEmulator()
    data = {
        "text":
        "I want italian food",
        "intent": {
            "name": "inform",
            "confidence": 0.4794813722432127
        },
        "entities": [
            {
                "entity": "cuisine",
                "value": "italian",
                "start": 7,
                "end": 14,
                "confidence_entity": 0.1234,
            },
            {
                "entity": "cuisine",
                "value": "italian",
                "role": "desert",
                "start": 7,
                "end": 14,
                "confidence_entity": 0.1234,
            },
        ],
    }
    norm = em.normalise_response_json(data)

    expected = {
        "text": "I want italian food",
        "intents": [{
            "name": "inform",
            "confidence": 0.4794813722432127
        }],
        "entities": {
            "cuisine:cuisine": [{
                "name": "cuisine",
                "role": "cuisine",
                "start": 7,
                "end": 14,
                "body": "italian",
                "value": "italian",
                "confidence": 0.1234,
                "entities": [],
            }],
            "cuisine:desert": [{
                "name": "cuisine",
                "role": "desert",
                "start": 7,
                "end": 14,
                "body": "italian",
                "value": "italian",
                "confidence": 0.1234,
                "entities": [],
            }],
        },
    }

    assert norm == expected