<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 15.12.2014

'''
from __future__ import unicode_literals
from eWRT.ws.rest import MultiRESTClient

from weblyzard_api.client import (
    WEBLYZARD_API_URL, WEBLYZARD_API_USER, WEBLYZARD_API_PASS)

SERVER_URL_PATH = '/rest/polarity/document'


class OpinionClient(MultiRESTClient):

    URL_PATH = '/'.join(SERVER_URL_PATH.split('/')[:-1])

    def __init__(self, url=WEBLYZARD_API_URL, usr=WEBLYZARD_API_USER,
                 pwd=<PASSWORD>, default_timeout=None):
        '''
        :param url: URL of the jeremia web service
        :param usr: optional user name
        :param pwd: <PASSWORD>
        '''
        MultiRESTClient.__init__(self, service_urls=url, user=usr, password=<PASSWORD>,
                                 default_timeout=default_timeout)

    def get_polarity(self, content, content_format, annotations=None,
                     allow_unsupported=False):
        '''
        Sends the content in the content_format to the opinion mining server
        to calculate the polarity/sentiment of the content.

        :param content str: The string containing the document to analyze.
        :param content_format str: The format of the content. Must be 'xml' or
            'plaintext'
        :returns: The content (modified, if xml) and the content's overall
            polarity in a dict with content and polarity as keys. If an error
            ocurred, it is also contained in the dict with the 'error' key.
        :rtype: dict
        '''
        result = None
        retrycount = 1
        retries = 0
        while retries <= retrycount:
            retries += 1
            try:
                result = self.request('document',
                                      parameters={'format': content_format,
                                                  'content': content,
                                                  'annotations': annotations,
                                                  'allow_unsupported': allow_unsupported},
                                      return_plain=False)
                break
            except Exception as e:<commit_msg>new: ignored_entity_regexp parameter to control annotation types skipped in sentiment assignment<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 15.12.2014

'''
from __future__ import unicode_literals
from eWRT.ws.rest import MultiRESTClient

from weblyzard_api.client import (
    WEBLYZARD_API_URL, WEBLYZARD_API_USER, WEBLYZARD_API_PASS)

SERVER_URL_PATH = '/rest/polarity/document'


class OpinionClient(MultiRESTClient):

    URL_PATH = '/'.join(SERVER_URL_PATH.split('/')[:-1])

    def __init__(self, url=WEBLYZARD_API_URL, usr=WEBLYZARD_API_USER,
                 pwd=<PASSWORD>, default_timeout=None):
        '''
        :param url: URL of the jeremia web service
        :param usr: optional user name
        :param pwd: <PASSWORD>
        '''
        MultiRESTClient.__init__(self, service_urls=url, user=usr, password=<PASSWORD>,
                                 default_timeout=default_timeout)

    def get_polarity(self, content, content_format, annotations=None,
                     allow_unsupported=False, ignored_entity_regexp=None):
        '''
        Sends the content in the content_format to the opinion mining server
        to calculate the polarity/sentiment of the content.

        :param content str: The string containing the document to analyze.
        :param content_format str: The format of the content. Must be 'xml' or
            'plaintext'
        :returns: The content (modified, if xml) and the content's overall
            polarity in a dict with content and polarity as keys. If an error
            ocurred, it is also contained in the dict with the 'error' key.
        :rtype: dict
        '''
        result = None
        retrycount = 1
        retries = 0
        while retries <= retrycount:
            retries += 1
            try:
                result = self.request('document',
                                      parameters={'format': content_format,
                                                  'content': content,
                                                  'annotations': annotations,
                                                  'allow_unsupported': allow_unsupported,
                                                  'ignored_entity_regexp': ignored_entity_regexp},
                                      return_plain=False)
                break
            except Exception as e:
{'fraction_non_alphanumeric': 0.07813525935653316, 'fraction_numerical': 0.005690523090391771, 'mean_word_length': 1.8105781057810577, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '972633', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1140, 'n_words': 342}