tweebo_parser package

Submodules

tweebo_parser.api module

Module contains the following class:

class tweebo_parser.api.API(hostname='0.0.0.0', port=8000, retries=10, log_errors=False)[source]

Bases: object

Allows easy connection and requests to the TweeboParse API server. TweeboParse is a Twitter specific dependency parser.

Attributes:

  1. hostname – The IP address of the TweeboParser API server.
  2. port – The Port that the TweeboParser API server is attached to.
  3. retries – Number of times to retry json decoding the returned data.
  4. log_errors – Whether to log errors or not. If this is True it logs errors under tweebo_log file within your temp_dir
__init__(hostname='0.0.0.0', port=8000, retries=10, log_errors=False)[source]
Parameters:
  • hostname (str) – The IP address of the TweeboParser API server.
  • port (int) – The Port that the TweeboParser API server is attached to.
  • retries (int) – Number of times to retry json decoding the returned data.
Return type:

None

log_error(text)[source]

Given some error text it will log the text if self.log_errors is True

Parameters:text (str) – Error text to log
Return type:None
parse_conll(texts, retry_count=0)[source]

Processes the texts using TweeboParse and returns them in CoNLL format.

Parameters:
  • texts (List[str]) – The List of Strings to be processed by TweeboParse.
  • retry_count (int) – The number of times it has retried for. Default 0 does not require setting, main purpose is for recursion.
Return type:

List[str]

Returns:

A list of CoNLL formated strings.

Raises:

ServerError – Caused when the server is not running.

:raises requests.exceptions.HTTPError: Caused when the
input texts is not formated correctly e.g. When you give it a String not a list of Strings.
:raises json.JSONDecodeError: Caused if after self.retries
attempts to parse the data it cannot decode the data.
Example:
parse_stanford(texts, retry_count=0)[source]

Processes the texts using TweeboParse and returns them in a Stanford styled format (as in the same format as the json return of the Stanford CoreNLP server dependency parser).

Parameters:
  • texts (List[str]) – The List of Strings to be processed by TweeboParse.
  • retry_count (int) – The number of times it has retried for. Default 0 does not require setting, main purpose is for recursion.
Return type:

List[Dict[str, Union[str, int]]]

Returns:

A list of dicts.

Raises:

ServerError – Caused when the server is not running.

:raises requests.exceptions.HTTPError: Caused when the
input texts is not formated correctly e.g. When you give it a String not a list of Strings.
:raises json.JSONDecodeError: Caused if after self.retries
attempts to parse the data it cannot decode the data.
Example:
::
from tweebo_parser import API tweebo_api = API() text_data = [‘hello how are you’, ‘Where are we going’] result = tweebo_api.parse_stanford(text_data) print(result) [{}]
exception tweebo_parser.api.ServerError(excpetion, hostname, port)[source]

Bases: Exception

Exception raised when the Server API is not avliable.

Attributes:

  1. message – Explains why it could not connect to the server, and details of the server it tried to connect to.
__init__(excpetion, hostname, port)[source]
Parameters:
  • exception – The requests exception instance that is raised.
  • hostname (str) – The IP address of the API server.
  • port (int) – The Port that the API server is attached to.
Return type:

None

Module contents