# Buggy code
def parse(self, text):
    # type: (basestring) -> dict
    """Parse the input text, classify it and return an object containing its intent and entities."""

    current_context = self.context.copy()

    current_context.update(
        {
            "text": text,
        }
    )

    for component in self.pipeline:
        try:
            args = rasa_nlu.components.fill_args(
                component.process_args(), current_context, self.config
            )
            updates = component.process(*args)
            if updates:
                current_context.update(updates)
        except rasa_nlu.components.MissingArgumentError as e:
            raise Exception(
                "Failed to parse at component '{}'. {}".format(
                    component.name, e.message
                )
            )

    result = self.default_output_attributes.copy()
    all_attributes = (
        list(self.default_output_attributes.keys()) + self.output_attributes
    )
    # Ensure only keys of `all_attributes` are present and no other keys are returned
    result.update(
        {key: current_context[key] for key in all_attributes if key in current_context}
    )
    return result


# Traceback (Exception)
INFO:root:using mitie backend
INFO:root:Started http server on port 5000

root@177-Rancher-host:/home/devuser/rasa_nlu-master# Error categorizing text:
[2017-03-27 05:02:00,849] ERROR in app: Exception on /parse [POST]
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "build/bdist.linux-x86_64/egg/rasa_nlu/server.py", line 42, in decorated
File "build/bdist.linux-x86_64/egg/rasa_nlu/server.py", line 63, in parse_get
File "build/bdist.linux-x86_64/egg/rasa_nlu/data_router.py", line 189, in parse
response = model.interpreter.parse(data['text'])
File "build/bdist.linux-x86_64/egg/rasa_nlu/interpreters/mitie_interpreter.py", line 60, in parse
intent, score = self.get_intent(tokens)
File "build/bdist.linux-x86_64/egg/rasa_nlu/interpreters/mitie_interpreter.py", line 53, in get_intent
label, score = self.classifier(tokens, self.featurizer.feature_extractor)
File "/usr/local/lib/python2.7/dist-packages/mitie/mitie.py", line 747, in __call__
raise Exception("Unable to classify text.")
Exception: Unable to classify text.
10.236.220.173 - - [2017-03-27 05:02:00] "POST /parse HTTP/1.1" 500 412 0.006278


************************** FATAL ERROR DETECTED **************************
************************** FATAL ERROR DETECTED **************************
************************** FATAL ERROR DETECTED **************************

Two fatal errors have been detected, the first was inappropriately ignored.
To prevent further fatal errors from being ignored this application will be
terminated immediately and you should go fix this buggy program.

The error message from this fatal error was:


Error detected at line 43.
Error detected in file src/text_feature_extraction.cpp.
Error detected in function mitie::text_sample_type mitie::extract_BoW_features(const std::vector<std::__cxx11::basic_string<char>                                       >&amp;).

Failing expression was words.size() > 0.
words can't be empty



python: ../dlib/dlib/vectorstream/../error.h:268: void dlib::fatal_error::check_for_previous_fatal_errors(): Assertion `false' failed.

# Fixed code
def parse(self, text):
    # type: (basestring) -> dict
    """Parse the input text, classify it and return an object containing its intent and entities."""

    if not text:
        # Not all components are able to handle empty strings. So we need to prevent that...
        # This default return will not contain all output attributes of all components,
        # but in the end, no one should pass an empty string in the first place.
        return self.default_output_attributes.copy()

    current_context = self.context.copy()

    current_context.update(
        {
            "text": text,
        }
    )

    for component in self.pipeline:
        try:
            args = rasa_nlu.components.fill_args(
                component.process_args(), current_context, self.config
            )
            updates = component.process(*args)
            if updates:
                current_context.update(updates)
        except rasa_nlu.components.MissingArgumentError as e:
            raise Exception(
                "Failed to parse at component '{}'. {}".format(
                    component.name, e.message
                )
            )

    result = self.default_output_attributes.copy()
    all_attributes = (
        list(self.default_output_attributes.keys()) + self.output_attributes
    )
    # Ensure only keys of `all_attributes` are present and no other keys are returned
    result.update(
        {key: current_context[key] for key in all_attributes if key in current_context}
    )
    return result