Esempio n. 1
0
def test_luis_response():
    from rasa_nlu.emulators.luis import LUISEmulator
    em = LUISEmulator()
    data = {
        "text": "I want italian food",
        "intent": "inform",
        "entities": [{
            "entity": "cuisine",
            "value": "italian"
        }]
    }
    norm = em.normalise_response_json(data)
    assert norm == {
        "query":
        data["text"],
        "topScoringIntent": {
            "intent": "inform",
            "score": None
        },
        "entities": [{
            "entity": e["value"],
            "type": e["entity"],
            "startIndex": None,
            "endIndex": None,
            "score": None
        } for e in data["entities"]]
    }
Esempio n. 2
0
def test_emulators_can_handle_missing_data():
    from rasa_nlu.emulators.luis import LUISEmulator
    em = LUISEmulator()
    norm = em.normalise_response_json(
        {"text": "this data doesn't contain an intent result"})
    assert norm["topScoringIntent"] is None
    assert norm["intents"] == []
Esempio n. 3
0
def test_emulators_can_handle_missing_data():
    from rasa_nlu.emulators.luis import LUISEmulator
    em = LUISEmulator()
    norm = em.normalise_response_json({
        "text": "this data doesn't contain an intent result"})
    assert norm["topScoringIntent"] is None
    assert norm["intents"] == []
Esempio n. 4
0
def test_luis_response():
    from rasa_nlu.emulators.luis import LUISEmulator
    em = LUISEmulator()
    data = {
        "text":
        "I want italian food",
        "intent": {
            "name": "restaurant_search",
            "confidence": 0.737014589341683
        },
        "intent_ranking": [{
            "confidence": 0.737014589341683,
            "name": "restaurant_search"
        }, {
            "confidence": 0.11605464483122209,
            "name": "goodbye"
        }, {
            "confidence": 0.08816417744097163,
            "name": "greet"
        }, {
            "confidence": 0.058766588386123204,
            "name": "affirm"
        }],
        "entities": [{
            "entity": "cuisine",
            "value": "italian"
        }]
    }
    norm = em.normalise_response_json(data)
    assert norm == {
        "query":
        data["text"],
        "topScoringIntent": {
            "intent": "restaurant_search",
            "score": 0.737014589341683
        },
        "intents": [{
            "intent": "restaurant_search",
            "score": 0.737014589341683
        }, {
            "intent": "goodbye",
            "score": 0.11605464483122209
        }, {
            "intent": "greet",
            "score": 0.08816417744097163
        }, {
            "intent": "affirm",
            "score": 0.058766588386123204
        }],
        "entities": [{
            "entity": e["value"],
            "type": e["entity"],
            "startIndex": None,
            "endIndex": None,
            "score": None
        } for e in data["entities"]]
    }
Esempio n. 5
0
 def __create_emulator(self):
     mode = self.config['emulate']
     if mode is None:
         from rasa_nlu.emulators import NoEmulator
         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() == 'api':
         from rasa_nlu.emulators.api import ApiEmulator
         return ApiEmulator()
     else:
         raise ValueError("unknown mode : {0}".format(mode))
Esempio n. 6
0
    def __create_emulator(self):
        """Sets which NLU webservice to emulate among those supported by Rasa"""

        mode = self.config['emulate']
        if mode is None:
            from rasa_nlu.emulators import NoEmulator
            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() == 'api':
            from rasa_nlu.emulators.api import ApiEmulator
            return ApiEmulator()
        else:
            raise ValueError("unknown mode : {0}".format(mode))
Esempio n. 7
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))
Esempio n. 8
0
def test_luis_request():
    from rasa_nlu.emulators.luis import LUISEmulator
    em = LUISEmulator()
    norm = em.normalise_request_json({"q": ["arb text"]})
    assert norm == {"text": "arb text", "project": "default", "time": None}
Esempio n. 9
0
def test_luis_request():
    from rasa_nlu.emulators.luis import LUISEmulator
    em = LUISEmulator()
    norm = em.normalise_request_json({"q": ["arb text"]})
    assert norm == {"text": "arb text", "project": "default", "time": None}
Esempio n. 10
0
def test_luis_response():
    from rasa_nlu.emulators.luis import LUISEmulator
    em = LUISEmulator()
    data = {
        "text": "I want italian food",
        "intent": {"name": "restaurant_search", "confidence": 0.737014589341683},
        "intent_ranking": [
            {
                "confidence": 0.737014589341683,
                "name": "restaurant_search"
            },
            {
                "confidence": 0.11605464483122209,
                "name": "goodbye"
            },
            {
                "confidence": 0.08816417744097163,
                "name": "greet"
            },
            {
                "confidence": 0.058766588386123204,
                "name": "affirm"
            }
        ],
        "entities": [{"entity": "cuisine", "value": "italian"}]
    }
    norm = em.normalise_response_json(data)
    assert norm == {
        "query": data["text"],
        "topScoringIntent": {
            "intent": "restaurant_search",
            "score": 0.737014589341683
        },
        "intents": [
            {
                "intent": "restaurant_search",
                "score": 0.737014589341683
            },
            {
                "intent": "goodbye",
                "score": 0.11605464483122209
            },
            {
                "intent": "greet",
                "score": 0.08816417744097163
            },
            {
                "intent": "affirm",
                "score": 0.058766588386123204
            }
        ],
        "entities": [
            {
                "entity": e["value"],
                "type": e["entity"],
                "startIndex": None,
                "endIndex": None,
                "score": None
            } for e in data["entities"]
            ]
    }