BVB Source Codes

TextBlob Show base.py Source code

Return Download TextBlob: download base.py Source code - Download TextBlob Source code - Type:.py
  1. # -*- coding: utf-8 -*-
  2. """Abstract base classes for models (taggers, noun phrase extractors, etc.)
  3. which define the interface for descendant classes.
  4.  
  5. .. versionchanged:: 0.7.0
  6.    All base classes are defined in the same module, ``textblob.base``.
  7. """
  8. from __future__ import absolute_import
  9. from abc import ABCMeta, abstractmethod
  10.  
  11. import nltk
  12.  
  13. from textblob.compat import with_metaclass
  14.  
  15. ##### POS TAGGERS #####
  16.  
  17. class BaseTagger(with_metaclass(ABCMeta)):
  18.     """Abstract tagger class from which all taggers
  19.    inherit from. All descendants must implement a
  20.    ``tag()`` method.
  21.    """
  22.     @abstractmethod
  23.     def tag(self, text, tokenize=True):
  24.         """Return a list of tuples of the form (word, tag)
  25.        for a given set of text.
  26.        """
  27.         return
  28.  
  29. ##### NOUN PHRASE EXTRACTORS #####
  30.  
  31. class BaseNPExtractor(with_metaclass(ABCMeta)):
  32.     """Abstract base class from which all NPExtractor classes inherit.
  33.    Descendant classes must implement an ``extract(text)`` method
  34.    that returns a list of noun phrases as strings.
  35.    """
  36.  
  37.     @abstractmethod
  38.     def extract(self, text):
  39.         """Return a list of noun phrases (strings) for a body of text."""
  40.         return
  41.  
  42. ##### TOKENIZERS #####
  43.  
  44. class BaseTokenizer(with_metaclass(ABCMeta), nltk.tokenize.api.TokenizerI):
  45.     """Abstract base class from which all Tokenizer classes inherit.
  46.    Descendant classes must implement a ``tokenize(text)`` method
  47.    that returns a list of noun phrases as strings.
  48.    """
  49.     @abstractmethod
  50.     def tokenize(self, text):
  51.         """Return a list of tokens (strings) for a body of text.
  52.  
  53.        :rtype: list
  54.        """
  55.         return
  56.  
  57.     def itokenize(self, text, *args, **kwargs):
  58.         """Return a generator that generates tokens "on-demand".
  59.  
  60.        .. versionadded:: 0.6.0
  61.  
  62.        :rtype: generator
  63.        """
  64.         return (t for t in self.tokenize(text, *args, **kwargs))
  65.  
  66. ##### SENTIMENT ANALYZERS ####
  67.  
  68. DISCRETE = 'ds'
  69. CONTINUOUS = 'co'
  70.  
  71.  
  72. class BaseSentimentAnalyzer(with_metaclass(ABCMeta)):
  73.     """Abstract base class from which all sentiment analyzers inherit.
  74.    Should implement an ``analyze(text)`` method which returns either the
  75.    results of analysis.
  76.    """
  77.     kind = DISCRETE
  78.  
  79.     def __init__(self):
  80.         self._trained = False
  81.  
  82.     def train(self):
  83.         # Train me
  84.         self._trained = True
  85.  
  86.     @abstractmethod
  87.     def analyze(self, text):
  88.         """Return the result of of analysis. Typically returns either a
  89.        tuple, float, or dictionary.
  90.        """
  91.         # Lazily train the classifier
  92.         if not self._trained:
  93.             self.train()
  94.         # Analyze text
  95.         return None
  96.  
  97. ##### PARSERS #####
  98.  
  99. class BaseParser(with_metaclass(ABCMeta)):
  100.     """Abstract parser class from which all parsers inherit from. All
  101.    descendants must implement a ``parse()`` method.
  102.    """
  103.     @abstractmethod
  104.     def parse(self, text):
  105.         """Parses the text."""
  106.         return
  107.  
downloadbase.py Source code - Download TextBlob Source code
Related Source Codes/Software:
monaco-editor - A browser based code editor 2017-01-07
grumpy - Grumpy is a Python to Go source code transcompiler... 2017-01-07
flinux - Foreign LINUX - Run unmodified Linux applications ... 2017-01-07
beeswithmachineguns - A utility for arming (creating) many bees (micro E... 2017-01-07
TopDeepLearning - A list of popular github projects related to deep ... 2017-01-07
yui3 - A library for building richly interactive web appl... 2017-01-07
KineticJS - KineticJS is an HTML5 Canvas JavaScript framework ... 2017-01-07
web-design-standards - Open source UI components and visual style guide f... 2017-01-07
Knuff - The debug application for Apple Push Notification ... 2017-01-07
RoundedImageView - A fast ImageView that supports rounded corners, ov... 2017-01-07
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top