Beispiel #1
0
    def process(
        self,
        message: Message,
        config: Optional[RasaNLUModelConfig] = None,
        **kwargs: Any,
    ) -> None:
        """Process an incoming message."""

        APOSTROPHE_OPTIONS = ["'", "`"]

        # removing accent and lowercasing characters
        message.text = unidecode(message.text.lower())
        # remove apostrophe from the phrase (important be first than s_regex regex)
        for APOSTROPHE in APOSTROPHE_OPTIONS:
            message.text = message.text.replace(APOSTROPHE, "")
            # set regex parameters
        n_regex = r"\b(n|N)\1*\b"
        s_regex = r"\b(s|S)\1*\b"
        # set replace words
        S_WORD = "sim"
        N_WORD = "nao"

        # replace regex by "sim"
        message.text = re.sub(s_regex, S_WORD, message.text)
        # replace regex by "nao"
        message.text = re.sub(n_regex, N_WORD, message.text)
    def process(self, message: Message, **kwargs: Any) -> None:
        """Process an incoming message."""
        APOSTROPHE_OPTIONS = ["'", "`"]

        # remove apostrophe from the phrase (important be first than s_regex regex)
        for APOSTROPHE in APOSTROPHE_OPTIONS:
            message.text = message.text.replace(APOSTROPHE, "")

        PREPROCESS_FACTORY = PreprocessingFactory().get_preprocess(
            self.language)

        message.text = PREPROCESS_FACTORY.preprocess(message.text)
Beispiel #3
0
    def process(self, message: Message, **kwargs: Any) -> None:
        """Process an incoming message."""

        language_preprocessor = PreprocessingFactory(self.language).factory()
        _message = language_preprocessor.preprocess(message)
        message.text = _message.text
        message.data = _message.data
    def preprocess(self, example: Message) -> Message:
        phrase = example.text
        entities = example.data.get('entities')

        phrase = self.emoji_handling(phrase)
        phrase, entities = self.default_preprocessing(phrase, entities)

        example.text = phrase
        if entities:
            example.data['entities'] = entities

        return example
Beispiel #5
0
    def tokenize(self, message: Message, attribute: Text) -> List[Token]:

        # extract the visual information from the text information
        if LANG_VISUAL_DELIMITER in message.text:
            visual_data_string = message.text[message.text.index(LANG_VISUAL_DELIMITER) + 1 + len(LANG_VISUAL_DELIMITER):]
            message.set('visual_info', visual_data_string.strip())
            message.text = message.text[0: message.text.index(LANG_VISUAL_DELIMITER)]

        doc = self.get_doc(message, attribute)

        tokens = []
        for t in doc:
            # do not send the visual information to the feedforward layers
            # that lead to the transformer module
            if LANG_VISUAL_DELIMITER in t.text:
                break
            tokens.append(Token(t.text, t.idx, lemma=t.lemma_, data={POS_TAG_KEY: self._tag_of_token(t)}))

        return tokens
    def process(self, message: Message, **kwargs: Any) -> None:
        print(
            "Process an incoming message.....................................")
        """
        This is the components chance to process an incoming
        message. The component can rely on
        any context attribute to be present, that gets created
        by a call to :meth:`components.Component.pipeline_init`
        of ANY component and
        on any context attributes created by a call to
        :meth:`components.Component.process`
        of components previous to this one."""
        input = message.text.lower()
        print("msggggggggg..................:", input)
        input = input.replace("+", " add ").replace("-", " subtract ").replace(
            "*", " multiply ").replace("/", " divide ").replace(
                "(", " left ").replace(")", " right ")
        message.text = input
        print("msgggg.............", message.text)
        #duck.parse(message.text)

        pass
Beispiel #7
0
 def process(self, message: Message, **kwargs: Any) -> None:
     for spell_typo, spell_correct in self.typos.items():
         message.text = message.text.replace(spell_typo, spell_correct)