Source code for mindmeld.text_preparation.preprocessors
# -*- coding: utf-8 -*-## Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.# Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at# http://www.apache.org/licenses/LICENSE-2.0# Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License."""This module contains a preprocessor base class."""fromabcimportABC,abstractmethod
[docs]classPreprocessor(ABC):""" Base class for Preprocessor object """
[docs]@abstractmethoddefprocess(self,text):""" Args: text (str) Returns: (str) """pass
[docs]deftojson(self):""" Method defined to obtain recursive JSON representation of a TextPreparationPipeline. Args: None. Returns: JSON representation of Preprocessor (dict) . """return{self.__class__.__name__:None}
[docs]@staticmethoddefget_preprocessor(preprocessor:str):"""A static method to get a Preprocessor Args: preprocessor (str): Name of the desired Preprocessor class Returns: (Preprocessor): Preprocessor Class """ifpreprocessor==NoOpPreprocessor.__name__:returnNoOpPreprocessor()raiseTypeError(f"{preprocessor} is not a valid Preprocessor type.")