return self.__overload__(value)<EOL>

Overloads ``|`` as from left-to-right operator precedence expression.


return self.__overload__(value)<EOL>


log.debug('<STR_LIT>'.format(self._ctx))<EOL>test._context += <NUM_LIT:1><EOL>test._context_subject = self._ctx.subject<EOL>


def __exit__(self, etype, value, traceback):

log.debug('<STR_LIT>'.format(value))<EOL>test._context -= <NUM_LIT:1><EOL>if test._context == <NUM_LIT:0>:<EOL><INDENT>test._context_subject = empty<EOL><DEDENT>


_test = getattr(test, name)<EOL>if inspect.ismethod(_test):<EOL><INDENT>return _test<EOL><DEDENT>_test._ctx.style = self._style<EOL>return _test<EOL>

Overloads object attribute accessory proxy to the currently used
operator and parent test instance.


_test = test(*args, **kw)<EOL>_test._ctx.style = self._style<EOL>return _test<EOL>

Makes proxy object itself callable, delegating the invokation
to a new test instance.


log.debug('<STR_LIT>'.format(plugin))<EOL>if inspect.isfunction(plugin):<EOL><INDENT>return plugin(Engine)<EOL><DEDENT>if plugin and hasattr(plugin, '<STR_LIT>'):<EOL><INDENT>return plugin.register(Engine)<EOL><DEDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>

Register plugin in grappa.

`plugin` argument can be a function or a object that implement `register`
method, which should accept one argument: `grappa.Engine` instance.

Arguments:
    plugin (function|module): grappa plugin object to register.

Raises:
    ValueError: if `plugin` is not a valid interface.

Example::

    import grappa

    class MyOperator(grappa.Operator):
        pass

    def my_plugin(engine):
        engine.register(MyOperator)

    grappa.use(my_plugin)


<EOL>if ctx.reverse:<EOL><INDENT>self.engine.reverse()<EOL><DEDENT>if self.engine.empty:<EOL><INDENT>raise AssertionError('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>return self.run_assertions(ctx)<EOL><DEDENT>except Exception as _err:<EOL><INDENT>if getattr(_err, '<STR_LIT>', False):<EOL><INDENT>raise _err<EOL><DEDENT>return self.render_error(ctx, _err)<EOL><DEDENT>


def operator(name=None, operators=None, aliases=None, kind=None):

def delegator(assertion, subject, expected, *args, **kw):<EOL><INDENT>return assertion.test(subject, expected, *args, **kw)<EOL><DEDENT>def decorator(fn):<EOL><INDENT>operator = Operator(fn=fn, aliases=aliases, kind=kind)<EOL>_name = name if isinstance(name, six.string_types) else fn.__name__<EOL>operator.operators = (_name,)<EOL>_operators = operators<EOL>if isinstance(_operators, list):<EOL><INDENT>_operators = tuple(_operators)<EOL><DEDENT>if isinstance(_operators, tuple):<EOL><INDENT>operator.operators += _operators<EOL><DEDENT>Engine.register(operator)<EOL>return functools.partial(delegator, operator)<EOL><DEDENT>return decorator(name) if inspect.isfunction(name) else decorator<EOL>

Registers a new operator function in the test engine.

Arguments:
    *args: variadic arguments.
    **kw: variadic keyword arguments.

Returns:
    function


return operator(kind=Operator.Type.ATTRIBUTE, *args, **kw)<EOL>

Registers a new attribute only operator function in the test engine.

Arguments:
    *args: variadic arguments.
    **kw: variadic keyword arguments.

Returns:
    function


Engine.register(operator)<EOL>return operator<EOL>

Registers a new operator class in the test engine.

Arguments:
    operator (Operator): operator class to register.

Returns:
    Operator: operator class.


operator = Operator()<EOL>operator.__dict__ = self.__dict__.copy()<EOL>operator.__init__(*args, **kw)<EOL>return operator<EOL>

Overloads function invokation in current operator and creates a new
cloned operator instance.


@functools.wraps(matcher)<EOL>def observer(self, subject, *expected, **kw):<EOL><INDENT>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.before(subject, *expected, **kw)<EOL><DEDENT>result = matcher(self, subject, *expected, **kw)<EOL>if result is not True and hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.after_error(result, subject, *expected, **kw)<EOL><DEDENT>if result is True and hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.after_success(subject, *expected, **kw)<EOL><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.show_diff = all([<EOL>isinstance(subject, six.string_types),<EOL>all([isinstance(x, six.string_types) for x in expected]),<EOL>])<EOL><DEDENT>return result<EOL><DEDENT>return observer<EOL>

Internal decorator to trigger operator hooks before/after
matcher execution.


@observe<EOL><INDENT>def run_matcher(self, subject, *expected, **kw):<DEDENT>

<EOL>self.expected = expected<EOL>_args = (subject,)<EOL>if self.kind == OperatorTypes.MATCHER:<EOL><INDENT>_args += expected<EOL><DEDENT>try:<EOL><INDENT>result = self.match(*_args, **kw)<EOL><DEDENT>except Exception as error:<EOL><INDENT>return self._make_error(error=error)<EOL><DEDENT>reasons = []<EOL>if isinstance(result, tuple):<EOL><INDENT>result, reasons = result<EOL><DEDENT>if result is False and self.ctx.negate:<EOL><INDENT>return True<EOL><DEDENT>if result is True and not self.ctx.negate:<EOL><INDENT>return True<EOL><DEDENT>return self._make_error(reasons=reasons)<EOL>

Runs the operator matcher test function.


log.debug('<STR_LIT>'.format(<EOL>self.__class__.__name__, args<EOL>))<EOL>if self.kind == OperatorTypes.ATTRIBUTE:<EOL><INDENT>return self.match(self.ctx)<EOL><DEDENT>else:<EOL><INDENT>return self.run_matcher(*args, **kw)<EOL><DEDENT>

Runs the current operator with the subject arguments to test.

This method is implemented by matchers only.


for operator in operators:<EOL><INDENT>module, symbols = operator[<NUM_LIT:0>], operator[<NUM_LIT:1>:]<EOL>path = '<STR_LIT>'.format(module)<EOL>operator = __import__(path, None, None, symbols)<EOL>for symbol in symbols:<EOL><INDENT>Engine.register(getattr(operator, symbol))<EOL><DEDENT><DEDENT>

Loads the built-in operators into the global test engine.


@attribute(<EOL>operators=(<EOL>'<STR_LIT:to>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'<EOL>)<EOL>)<EOL>def be(ctx):

ctx.negate = False<EOL>

Semantic attributes providing chainable declarative DSL
for assertions.


@attribute(operators=(<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>'<EOL>))<EOL>def not_be(ctx):

ctx.negate = True<EOL>

Semantic negation attributes providing chainable declarative DSL
for assertions.


url = self.base_url<EOL>obdata = self.connection.make_get(url)<EOL>return ProductList(obdata, self)<EOL>

Lists all products in the system, returns ProductList you can iterate over.

        Holvi API does not currently support server-side filtering so you will have to use Pythons filter() function as usual.


candidates = list(filter(lambda c: c.code == code, self.list_products()))<EOL>if not len(candidates):<EOL><INDENT>return None<EOL><DEDENT>return candidates[<NUM_LIT:0>]<EOL>

Gets product with given code

        NOTE: Filters the list of products in this end due to API limitations


@classmethod<EOL><INDENT>def singleton(self, poolname, authkey):<DEDENT>

global CONNECTION_MAP<EOL>mapkey = "<STR_LIT>" % (poolname, authkey)<EOL>if not mapkey in CONNECTION_MAP:<EOL><INDENT>CONNECTION_MAP[mapkey] = Connection(poolname, authkey)<EOL><DEDENT>return CONNECTION_MAP[mapkey]<EOL>


if not self.session:<EOL><INDENT>self.session = requests.Session()<EOL>self.session.headers.update({<EOL>'<STR_LIT:Content-Type>': '<STR_LIT:application/json>',<EOL>'<STR_LIT>': '<STR_LIT>' % self.key<EOL>})<EOL><DEDENT>self.session.remove_expired_responses()<EOL>

Iniitializes a requests.Session for us if not already initialized


self._init_session()<EOL>r = self.session.get(url, params=params)<EOL>try:<EOL><INDENT>r.raise_for_status()<EOL><DEDENT>except Timeout as e:<EOL><INDENT>raise ApiTimeout(e.__str__(), response=e.response)  <EOL><DEDENT>except HTTPError as e:<EOL><INDENT>if e.response.status_code in (<NUM_LIT>, <NUM_LIT>):<EOL><INDENT>raise AuthenticationError(e.__str__(), response=e.response)  <EOL><DEDENT>else:<EOL><INDENT>raise ApiError(e.__str__(), response=e.response)  <EOL><DEDENT><DEDENT>return r.json()<EOL>


return self._make_ppp('<STR_LIT>', url, payload)<EOL>


def _make_ppp(self, method, url, payload):

self._init_session()<EOL>self.session.cache.clear()<EOL>m = getattr(self.session, method)<EOL>r = m(url, json=payload)<EOL>try:<EOL><INDENT>r.raise_for_status()<EOL><DEDENT>except Timeout as e:<EOL><INDENT>raise ApiTimeout(e.__str__(), response=e.response)  <EOL><DEDENT>except HTTPError as e:<EOL><INDENT>if e.response.status_code in (<NUM_LIT>, <NUM_LIT>):<EOL><INDENT>raise AuthenticationError(e.__str__(), response=e.response)  <EOL><DEDENT>else:<EOL><INDENT>raise ApiError(e.__str__(), response=e.response)  <EOL><DEDENT><DEDENT>return r.json()<EOL>

Internal helper to make POST/PUT/PATCH requests (or whatever the underlying library supports)


self._jsondata = {<EOL>"<STR_LIT:code>": None,<EOL>"<STR_LIT>": [],<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:email>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>}<EOL>

Creates the base set of attributes order has/needs


if self.code:<EOL><INDENT>raise HolviError("<STR_LIT>")<EOL><DEDENT>send_json = self.to_holvi_dict()<EOL>send_json.update({<EOL>'<STR_LIT>': self.api.connection.pool<EOL>})<EOL>url = six.u(self.api.base_url + "<STR_LIT>")<EOL>stat = self.api.connection.make_post(url, send_json)<EOL>code = stat["<STR_LIT>"].split("<STR_LIT:/>")[-<NUM_LIT:2>]  <EOL>return (stat["<STR_LIT>"], self.api.get_order(code))<EOL>

Saves this order to Holvi, returns a tuple with the order itself and checkout_uri


url = self.base_url + "<STR_LIT>".format(pool=self.connection.pool)<EOL>orders = self.connection.make_get(url, params=kwargs)<EOL>return OrderList(orders, self)<EOL>

Lists all orders in the system, returns OrderList you can iterate over.

        Add Holvi supported GET filters via kwargs, API documentation (last update time unknown) says following keys are supported:

          - filter_paid_time_from (datetime): Returns orders that are paid on or after the given datetime.
          - filter_paid_time_to (datetime): Returns orders that are paid on or before the given datetime.
          - filter_update_time_from (datetime): Returns orders that are updated on or after the given datetime.
          - filter_update_time_to (datetime): Returns orders that are updated on or before the given datetime.
          - firstname (string): Returns orders where buyer's first name matches the given string (parial, case insensitive match)
          - lastname (string): Returns orders where buyer's last name matches the given string (parial, case insensitive match)
          - street (string): Returns orders where buyer's street address matches the given string (parial, case insensitive match)
          - city (string): Returns orders where buyer's city matches the given string (parial, case insensitive match)
          - postcode (string): Returns orders where buyer's postcode matches the given string (parial, case insensitive match)
          - country (string): Returns orders where buyer's country matches the given string (parial, case insensitive match)
          - email (string): Returns orders where buyer's email address matches the given string (parial, case insensitive match)
          - company (string): Returns orders where buyer's company name matches the given string (parial, case insensitive match)

        All times are ISO datetimes, try for example '2016-01-20T00:00:00.0Z'.

        For other kinds of filtering use Pythons filter() function as usual.


url = self.base_url + "<STR_LIT>".format(code=order_code)<EOL>ojson = self.connection.make_get(url)<EOL>return Order(self, ojson)<EOL>


url = self.base_url<EOL>obdata = self.connection.make_get(url)<EOL>return IncomeCategoryList(obdata, self)<EOL>

Lists all products in the system, returns IncomeCategoryList you can iterate over.

        Holvi API does not currently support server-side filtering so you will have to use Pythons filter() function as usual.


url = self.base_url<EOL>obdata = self.connection.make_get(url)<EOL>return ExpenseCategoryList(obdata, self)<EOL>

Lists all products in the system, returns ExpenseCategoryList you can iterate over.

        Holvi API does not currently support server-side filtering so you will have to use Pythons filter() function as usual.


candidates = list(filter(lambda c: c.code == code, itertools.chain(self.list_income_categories(), self.list_expense_categories())))<EOL>if not len(candidates):<EOL><INDENT>return None<EOL><DEDENT>return candidates[<NUM_LIT:0>]<EOL>

Gets category with given code

        NOTE: Filters the list of income and expense categories in this end due to API limitations


checksum = <NUM_LIT:10> - (sum([int(c) * i for c, i in zip(str(n)[::-<NUM_LIT:1>], it.cycle((<NUM_LIT:7>, <NUM_LIT:3>, <NUM_LIT:1>)))]) % <NUM_LIT:10>)<EOL>if checksum == <NUM_LIT:10>:<EOL><INDENT>checksum = <NUM_LIT:0><EOL><DEDENT>return "<STR_LIT>" % (n, checksum)<EOL>

Calculates a checksum for a Finnish national reference number


return int2fin_reference(str(n)[:-<NUM_LIT:1>]) == str(n)<EOL>

Check that the given Finnish national reference number is valid (ie the checksum is valid)


if c in ISO_REFERENCE_VALID:<EOL><INDENT>return True<EOL><DEDENT>if raise_error:<EOL><INDENT>raise ValueError("<STR_LIT>" % (c, ISO_REFERENCE_VALID))<EOL><DEDENT>return False<EOL>

Helper to make sure the given character is valid for a reference number


iso_reference_valid_char(c, True)<EOL>return (ord(c) - <NUM_LIT>)<EOL>

Maps the characters in ISO reference (ones starting with RF) to their corresponding integers


n = n.upper()<EOL>numbers = []<EOL>for c in n:<EOL><INDENT>iso_reference_valid_char(c)<EOL>if c in ISO_REFERENCE_VALID_NUMERIC:<EOL><INDENT>numbers.append(c)<EOL><DEDENT>else:<EOL><INDENT>numbers.append(str(iso_reference_char2int(c)))<EOL><DEDENT><DEDENT>return int('<STR_LIT>'.join(numbers))<EOL>

Creates the huge number from ISO alphanumeric ISO reference


import warnings<EOL>warnings.warn("<STR_LIT>", DeprecationWarning)<EOL>return str2iso_reference(str(n))<EOL>

Calculates checksum (and adds the RF prefix) for an international reference number from an integer


cs_source = n + '<STR_LIT>'<EOL>cs = <NUM_LIT> - (iso_reference_str2int(cs_source) % <NUM_LIT>)<EOL>return "<STR_LIT>" % (cs, n)<EOL>

Calculates checksum (and adds the RF prefix) for an international reference number from a string (can contain any characters valid for the reference)


ref = str(ref)<EOL>cs_source = ref[<NUM_LIT:4>:] + ref[:<NUM_LIT:4>]<EOL>return (iso_reference_str2int(cs_source) % <NUM_LIT>) == <NUM_LIT:1><EOL>


def barcode(iban, reference, amount, due=None):

iban = iban.replace('<STR_LIT:U+0020>', '<STR_LIT>')<EOL>reference = reference.replace('<STR_LIT:U+0020>', '<STR_LIT>')<EOL>if reference.startswith('<STR_LIT>'):<EOL><INDENT>version = <NUM_LIT:5><EOL><DEDENT>else:<EOL><INDENT>version = <NUM_LIT:4><EOL><DEDENT>if version == <NUM_LIT:5>:<EOL><INDENT>reference = reference[<NUM_LIT:2>:]  <EOL>if len(reference) < <NUM_LIT>:<EOL><INDENT>reference = reference[:<NUM_LIT:2>] + ("<STR_LIT:0>" * (<NUM_LIT> - len(reference))) + reference[<NUM_LIT:2>:]<EOL><DEDENT><DEDENT>elif version == <NUM_LIT:4>:<EOL><INDENT>reference = reference.zfill(<NUM_LIT:20>)<EOL><DEDENT>if not iban.startswith('<STR_LIT>'):<EOL><INDENT>raise BarcodeException('<STR_LIT>')<EOL><DEDENT>iban = iban[<NUM_LIT:2>:]<EOL>amount = "<STR_LIT>" % (amount.quantize(Decimal('<STR_LIT>')).shift(<NUM_LIT:2>).to_integral_value())<EOL>if len(amount) != <NUM_LIT:8>:<EOL><INDENT>raise BarcodeException("<STR_LIT>")<EOL><DEDENT>if due:<EOL><INDENT>due = due.strftime("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>due = "<STR_LIT>"<EOL><DEDENT>if version == <NUM_LIT:4>:<EOL><INDENT>barcode = "<STR_LIT>" % (version, iban, amount, reference, due)<EOL><DEDENT>elif version == <NUM_LIT:5>:<EOL><INDENT>barcode = "<STR_LIT>" % (version, iban, amount, reference, due)<EOL><DEDENT>return barcode<EOL>

Calculates virtual barcode for IBAN account number and ISO reference

    Arguments:
        iban {string} -- IBAN formed account number
        reference {string} -- ISO 11649 creditor reference
        amount {decimal.Decimal} -- Amount in euros, 0.01 - 999999.99
        due {datetime.date} -- due date


pass<EOL>

For mapping properties from _jsondata to something more Pythonic

        For really simple objects there is no need to implement this


return self._jsondata<EOL>

For mapping the object back to JSON dict that holvi accepts


raise NotImplementedError()<EOL>

Creates the base set of attributes object has/needs


raise NotImplementedError()<EOL>


self._jsondata = {<EOL>"<STR_LIT:code>": None,<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": (datetime.datetime.now().date() + datetime.timedelta(days=<NUM_LIT>)).isoformat(),<EOL>"<STR_LIT>": datetime.datetime.now().date().isoformat(),<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>"<STR_LIT>": {<EOL>"<STR_LIT:name>": "<STR_LIT>",<EOL>"<STR_LIT:email>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>"<EOL>},<EOL>"<STR_LIT>": [],<EOL>}<EOL>

Creates the base set of attributes invoice has/needs


url = str(self.api.base_url + '<STR_LIT>').format(code=self.code)  <EOL>payload = {<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT>': send_email,<EOL>}<EOL>stat = self.api.connection.make_put(url, payload)<EOL>

Marks the invoice as sent in Holvi

        If send_email is False then the invoice is *not* automatically emailed to the recipient
        and your must take care of sending the invoice yourself.


self._jsondata["<STR_LIT>"] = []<EOL>for item in self.items:<EOL><INDENT>self._jsondata["<STR_LIT>"].append(item.to_holvi_dict())<EOL><DEDENT>self._jsondata["<STR_LIT>"] = self.issue_date.isoformat()<EOL>self._jsondata["<STR_LIT>"] = self.due_date.isoformat()<EOL>self._jsondata["<STR_LIT>"] = self.receiver.to_holvi_dict()<EOL>return {k: v for (k, v) in self._jsondata.items() if k in self._valid_keys}<EOL>

Convert our Python object to JSON acceptable to Holvi API


if not self.items:<EOL><INDENT>raise HolviError("<STR_LIT>")<EOL><DEDENT>if not self.subject:<EOL><INDENT>raise HolviError("<STR_LIT>")<EOL><DEDENT>send_json = self.to_holvi_dict()<EOL>if self.code:<EOL><INDENT>url = str(self.api.base_url + '<STR_LIT>').format(code=self.code)<EOL>if not self.code:<EOL><INDENT>send_patch = {k: v for (k, v) in send_json.items() if k in self._patch_valid_keys}<EOL>send_patch["<STR_LIT>"] = []<EOL>for item in self.items:<EOL><INDENT>send_patch["<STR_LIT>"].append(item.to_holvi_dict(True))<EOL><DEDENT>stat = self.api.connection.make_patch(url, send_patch)<EOL><DEDENT>else:<EOL><INDENT>stat = self.api.connection.make_put(url, send_json)<EOL><DEDENT>return Invoice(self.api, stat)<EOL><DEDENT>else:<EOL><INDENT>url = str(self.api.base_url)<EOL>stat = self.api.connection.make_post(url, send_json)<EOL>return Invoice(self.api, stat)<EOL><DEDENT>

Saves this invoice to Holvi, returns the created/updated invoice


return self.delete()<EOL>


url = str(self.api.base_url + '<STR_LIT>').format(code=self.code)  <EOL>payload = {<EOL>'<STR_LIT>': True,<EOL>}<EOL>stat = self.api.connection.make_put(url, payload)<EOL>


invoices = self.connection.make_get(self.base_url, params=kwargs)<EOL>return InvoiceList(invoices, self)<EOL>

Lists all invoices in the system, returns InvoiceList you can iterate over.

        Add Holvi supported GET filters via kwargs, on 2016.01.13 I was informed following keys are supported:

          - reference (lookup_type='icontains')
          - serial (Slightly complicated: try 'prefix-number-year', 'number-year', 'number', 'prefix')
          - category (exact)
          - receiver (field='receiver.name', lookup_type='icontains')
          - subject (lookup_type='icontains')
          - status (exact)
          - create_time_from (field='create_time', lookup_type='gte')
          - create_time_to (field='create_time', lookup_type='lte')
          - update_time_from (field='update_time', lookup_type='gte')
          - update_time_to (field='update_time', lookup_type='lte')

        All times are ISO datetimes, try for example '2016-01-20T00:00:00.0Z'.

        For other kinds of filtering use Pythons filter() function as usual.


url = self.base_url + '<STR_LIT>'.format(code=invoice_code)<EOL>ijson = self.connection.make_get(url)<EOL>return Invoice(self, ijson)<EOL>


driver = ogr.GetDriverByName('<STR_LIT>')<EOL>dataset = driver.Open(pathToShp)<EOL>if dataset is not None:<EOL><INDENT>layer = dataset.GetLayer()<EOL>spatialRef = layer.GetSpatialRef()<EOL>feature = layer.GetNextFeature()<EOL>geom = feature.GetGeometryRef()<EOL>spatialRef = geom.GetSpatialReference()<EOL>outSpatialRef = osr.SpatialReference()<EOL>outSpatialRef.ImportFromEPSG(<NUM_LIT>)<EOL>coordTrans = osr.CoordinateTransformation(spatialRef, outSpatialRef)<EOL>env = geom.GetEnvelope()<EOL>pointMAX = ogr.Geometry(ogr.wkbPoint)<EOL>pointMAX.AddPoint(env[<NUM_LIT:1>], env[<NUM_LIT:3>])<EOL>pointMAX.Transform(coordTrans)<EOL>pointMIN = ogr.Geometry(ogr.wkbPoint)<EOL>pointMIN.AddPoint(env[<NUM_LIT:0>], env[<NUM_LIT:2>])<EOL>pointMIN.Transform(coordTrans)<EOL>return [pointMAX.GetPoint()[<NUM_LIT:1>],pointMIN.GetPoint()[<NUM_LIT:0>],pointMIN.GetPoint()[<NUM_LIT:1>],pointMAX.GetPoint()[<NUM_LIT:0>]]<EOL><DEDENT>else:<EOL><INDENT>exit("<STR_LIT>")<EOL><DEDENT>

reprojette en WGS84 et recupere l'extend


URLlist=[]<EOL>listForcastSurface=['<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>']<EOL>if (<NUM_LIT:0> not in [int(x) for x in stepList]):<EOL><INDENT>listForcastSurface=listForcastSurface+['<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>']<EOL><DEDENT>listAnalyseSurface=['<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>']<EOL>if typeData == '<STR_LIT>' and all([x in listAnalyseSurface for x in paramList]):<EOL><INDENT>typeData= '<STR_LIT>'<EOL>validChoice = None<EOL>prbParameters =  None<EOL><DEDENT>else:<EOL><INDENT>if all([x in listForcastSurface for x in paramList]) and typeData != '<STR_LIT>':<EOL><INDENT>if typeData=='<STR_LIT>':<EOL><INDENT>typeData= '<STR_LIT>'<EOL>validChoice = typeData<EOL><DEDENT>else:<EOL><INDENT>validChoice = None<EOL><DEDENT>indexParameters=[i for i, elem in enumerate([x in listAnalyseSurface for x in paramList], <NUM_LIT:1>) if not elem]<EOL>prbParameters=[]<EOL>for i in indexParameters:<EOL><INDENT>prbParameters.append(paramList[i-<NUM_LIT:1>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if typeData != '<STR_LIT>':<EOL><INDENT>typeData= '<STR_LIT>'<EOL>validChoice = typeData<EOL><DEDENT>else:<EOL><INDENT>validChoice = None<EOL><DEDENT>indexParameters=[i for i, elem in enumerate([x in listAnalyseSurface for x in paramList], <NUM_LIT:1>) if not elem]<EOL>prbParameters=[]<EOL>for i in indexParameters:<EOL><INDENT>prbParameters.append(paramList[i-<NUM_LIT:1>])<EOL><DEDENT><DEDENT><DEDENT>today=date.today()<EOL>lastData = today - timedelta(days=<NUM_LIT>)<EOL>if dateStart < lastData or dateEnd > today : <EOL><INDENT>exit('<STR_LIT>' )<EOL><DEDENT>else:<EOL><INDENT>nbDays=(dateEnd-dateStart).days+<NUM_LIT:1><EOL>for i in range(<NUM_LIT:0>,nbDays):<EOL><INDENT>if dateStart + timedelta(days=i) == today:<EOL><INDENT>maxT=datetime.now().hour-<NUM_LIT:5><EOL>timeListCorr=[ x for x in stepList if x<maxT ]<EOL><DEDENT>else:<EOL><INDENT>timeListCorr=stepList<EOL><DEDENT>for t in timeListCorr:<EOL><INDENT>URL='<STR_LIT>'<EOL>URL=URL+"<STR_LIT>".format(grid).replace('<STR_LIT:.>','<STR_LIT:p>')+'<STR_LIT>'<EOL>URL=URL+'<STR_LIT:t>'+str(t).zfill(<NUM_LIT:2>)+'<STR_LIT>'<EOL>if (grid==<NUM_LIT:0.5>):<EOL><INDENT>URL=URL+'<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>URL=URL+'<STR_LIT>'<EOL><DEDENT>URL=URL+"<STR_LIT>".format(grid).replace('<STR_LIT:.>','<STR_LIT:p>')+'<STR_LIT:.>'<EOL>if typeData=='<STR_LIT>':<EOL><INDENT>URL=URL+'<STR_LIT>'<EOL><DEDENT>elif typeData=='<STR_LIT>':<EOL><INDENT>URL=URL+'<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>URL=URL+'<STR_LIT>'<EOL><DEDENT>URL=URL+"<STR_LIT>".join(levelList)+"<STR_LIT>"<EOL>URL=URL+"<STR_LIT>".join(paramList)+"<STR_LIT>"<EOL>URL=URL+"<STR_LIT>"+str(round(float(extent[<NUM_LIT:1>])-<NUM_LIT>,<NUM_LIT:1>))+"<STR_LIT>"+str(round(float(extent[<NUM_LIT:3>])+<NUM_LIT>,<NUM_LIT:1>))+"<STR_LIT>"+str(round(float(extent[<NUM_LIT:0>])+<NUM_LIT:0.5>,<NUM_LIT:1>))+"<STR_LIT>"+str(round(float(extent[<NUM_LIT:2>])-<NUM_LIT:0.5>,<NUM_LIT:1>))<EOL>URL=URL+"<STR_LIT>"+"<STR_LIT>".format(dateStart+timedelta(days=i))+str(t).zfill(<NUM_LIT:2>)<EOL>URLlist.append(URL)<EOL><DEDENT><DEDENT>return (URLlist,validChoice,prbParameters)<EOL><DEDENT>

Genere la structure de requete pour le téléchargement de données GFS

INPUTS:\n
-date : au format annee-mois-jour\n
-heure : au format heure:minute:seconde\n
-coord : une liste des coordonnees au format [N,W,S,E]\n
-dim_grille : taille de la grille en degree \n


dicoValues={}<EOL>for l in listeFile:<EOL><INDENT>grbs = pygrib.open(l)<EOL>grbs.seek(<NUM_LIT:0>)<EOL>index=<NUM_LIT:1><EOL>for j in range(len(listLevel),<NUM_LIT:0>,-<NUM_LIT:1>):<EOL><INDENT>for i in range(len(listParam)-<NUM_LIT:1>,-<NUM_LIT:1>,-<NUM_LIT:1>):<EOL><INDENT>grb = grbs[index]<EOL>p=grb.name.replace('<STR_LIT:U+0020>','<STR_LIT:_>')<EOL>if grb.level != <NUM_LIT:0>:<EOL><INDENT>l=str(grb.level)+'<STR_LIT:_>'+grb.typeOfLevel<EOL><DEDENT>else:<EOL><INDENT>l=grb.typeOfLevel<EOL><DEDENT>if p+'<STR_LIT:_>'+l not in dicoValues.keys():<EOL><INDENT>dicoValues[p+'<STR_LIT:_>'+l]=[]<EOL><DEDENT>dicoValues[p+'<STR_LIT:_>'+l].append(grb.values)<EOL>shape=grb.values.shape<EOL>lat,lon=grb.latlons()<EOL>geoparam=(lon.min(),lat.max(),grid,grid)<EOL>index+= <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>nbJour=(endDate-startDate).days+<NUM_LIT:1><EOL>for s in range(<NUM_LIT:0>, (len(liststep)*nbJour-len(listeFile))):<EOL><INDENT>for k in dicoValues.keys():<EOL><INDENT>dicoValues[k].append(np.full(shape, np.nan))<EOL><DEDENT><DEDENT>for i in range(len(dicoValues.keys())-<NUM_LIT:1>,-<NUM_LIT:1>,-<NUM_LIT:1>):<EOL><INDENT>dictParam=dict((k,dicoValues[dicoValues.keys()[i]][k]) for k in range(<NUM_LIT:0>,len(dicoValues[dicoValues.keys()[i]])))<EOL>sorted(dictParam.items(), key=lambda x: x[<NUM_LIT:0>])<EOL>outputImg=outFolder+'<STR_LIT:/>'+dicoValues.keys()[i]+'<STR_LIT:_>'+startDate.strftime('<STR_LIT>')+'<STR_LIT:_>'+endDate.strftime('<STR_LIT>')+'<STR_LIT>'<EOL>writeTiffFromDicoArray(dictParam,outputImg,shape,geoparam)<EOL><DEDENT>for f in listeFile:<EOL><INDENT>os.remove(f)<EOL><DEDENT>


@click.command()<EOL>@click.argument('<STR_LIT:filename>')<EOL>@click.option('<STR_LIT>', default=<NUM_LIT>, type=int)<EOL>@click.option('<STR_LIT>', default='<STR_LIT>')<EOL>@click.option('<STR_LIT>')<EOL>@click.option('<STR_LIT>')<EOL>def slinky(filename, seconds_available, bucket_name, aws_key, aws_secret):

if not os.environ.get('<STR_LIT>') and os.environ.get('<STR_LIT>'):<EOL><INDENT>print('<STR_LIT>')<EOL>exit()<EOL><DEDENT>print(create_temp_s3_link(filename, seconds_available, bucket_name))<EOL>

Simple program that creates an temp S3 link.


return BWT().encode(word, terminator)<EOL>

r"""Return the Burrows-Wheeler transformed form of a word.

    This is a wrapper for :py:meth:`BWT.encode`.

    Parameters
    ----------
    word : str
        The word to transform using BWT
    terminator : str
        A character added to signal the end of the string

    Returns
    -------
    str
        Word encoded by BWT

    Examples
    --------
    >>> bwt_encode('align')
    'n\x00ilag'
    >>> bwt_encode('banana')
    'annb\x00aa'
    >>> bwt_encode('banana', '@')
    'annb@aa'


return BWT().decode(code, terminator)<EOL>

r"""Return a word decoded from BWT form.

    This is a wrapper for :py:meth:`BWT.decode`.

    Parameters
    ----------
    code : str
        The word to transform from BWT form
    terminator : str
        A character added to signal the end of the string

    Returns
    -------
    str
        Word decoded by BWT

    Examples
    --------
    >>> bwt_decode('n\x00ilag')
    'align'
    >>> bwt_decode('annb\x00aa')
    'banana'
    >>> bwt_decode('annb@aa', '@')
    'banana'


def encode(self, word, terminator='<STR_LIT>'):

if word:<EOL><INDENT>if terminator in word:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(<EOL>terminator if terminator != '<STR_LIT>' else '<STR_LIT>'<EOL>)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>word += terminator<EOL>wordlist = sorted(<EOL>word[i:] + word[:i] for i in range(len(word))<EOL>)<EOL>return '<STR_LIT>'.join([w[-<NUM_LIT:1>] for w in wordlist])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return terminator<EOL><DEDENT>

r"""Return the Burrows-Wheeler transformed form of a word.

        Parameters
        ----------
        word : str
            The word to transform using BWT
        terminator : str
            A character added to signal the end of the string

        Returns
        -------
        str
            Word encoded by BWT

        Raises
        ------
        ValueError
            Specified terminator absent from code.

        Examples
        --------
        >>> bwt = BWT()
        >>> bwt.encode('align')
        'n\x00ilag'
        >>> bwt.encode('banana')
        'annb\x00aa'
        >>> bwt.encode('banana', '@')
        'annb@aa'


def decode(self, code, terminator='<STR_LIT>'):

if code:<EOL><INDENT>if terminator not in code:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(<EOL>terminator if terminator != '<STR_LIT>' else '<STR_LIT>'<EOL>)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>wordlist = ['<STR_LIT>'] * len(code)<EOL>for i in range(len(code)):<EOL><INDENT>wordlist = sorted(<EOL>code[i] + wordlist[i] for i in range(len(code))<EOL>)<EOL><DEDENT>rows = [w for w in wordlist if w[-<NUM_LIT:1>] == terminator][<NUM_LIT:0>]<EOL>return rows.rstrip(terminator)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>

r"""Return a word decoded from BWT form.

        Parameters
        ----------
        code : str
            The word to transform from BWT form
        terminator : str
            A character added to signal the end of the string

        Returns
        -------
        str
            Word decoded by BWT

        Raises
        ------
        ValueError
            Specified terminator absent from code.

        Examples
        --------
        >>> bwt = BWT()
        >>> bwt.decode('n\x00ilag')
        'align'
        >>> bwt.decode('annb\x00aa')
        'banana'
        >>> bwt.decode('annb@aa', '@')
        'banana'


if use_bwt:<EOL><INDENT>text = BWT().encode(text)<EOL><DEDENT>return RLE().encode(text)<EOL>

r"""Perform encoding of run-length-encoding (RLE).

    This is a wrapper for :py:meth:`RLE.encode`.

    Parameters
    ----------
    text : str
        A text string to encode
    use_bwt : bool
        Indicates whether to perform BWT encoding before RLE encoding

    Returns
    -------
    str
        Word decoded by RLE

    Examples
    --------
    >>> rle_encode('align')
    'n\x00ilag'
    >>> rle_encode('align', use_bwt=False)
    'align'

    >>> rle_encode('banana')
    'annb\x00aa'
    >>> rle_encode('banana', use_bwt=False)
    'banana'

    >>> rle_encode('aaabaabababa')
    'ab\x00abbab5a'
    >>> rle_encode('aaabaabababa', False)
    '3abaabababa'


text = RLE().decode(text)<EOL>if use_bwt:<EOL><INDENT>text = BWT().decode(text)<EOL><DEDENT>return text<EOL>

r"""Perform decoding of run-length-encoding (RLE).

    This is a wrapper for :py:meth:`RLE.decode`.

    Parameters
    ----------
    text : str
        A text string to decode
    use_bwt : bool
        Indicates whether to perform BWT decoding after RLE decoding

    Returns
    -------
    str
        Word decoded by RLE

    Examples
    --------
    >>> rle_decode('n\x00ilag')
    'align'
    >>> rle_decode('align', use_bwt=False)
    'align'

    >>> rle_decode('annb\x00aa')
    'banana'
    >>> rle_decode('banana', use_bwt=False)
    'banana'

    >>> rle_decode('ab\x00abbab5a')
    'aaabaabababa'
    >>> rle_decode('3abaabababa', False)
    'aaabaabababa'


if text:<EOL><INDENT>text = ((len(list(g)), k) for k, g in groupby(text))<EOL>text = (<EOL>(str(n) + k if n > <NUM_LIT:2> else (k if n == <NUM_LIT:1> else <NUM_LIT:2> * k))<EOL>for n, k in text<EOL>)<EOL><DEDENT>return '<STR_LIT>'.join(text)<EOL>

r"""Perform encoding of run-length-encoding (RLE).

        Parameters
        ----------
        text : str
            A text string to encode

        Returns
        -------
        str
            Word decoded by RLE

        Examples
        --------
        >>> rle = RLE()
        >>> bwt = BWT()
        >>> rle.encode(bwt.encode('align'))
        'n\x00ilag'
        >>> rle.encode('align')
        'align'

        >>> rle.encode(bwt.encode('banana'))
        'annb\x00aa'
        >>> rle.encode('banana')
        'banana'

        >>> rle.encode(bwt.encode('aaabaabababa'))
        'ab\x00abbab5a'
        >>> rle.encode('aaabaabababa')
        '3abaabababa'


mult = '<STR_LIT>'<EOL>decoded = []<EOL>for letter in list(text):<EOL><INDENT>if not letter.isdigit():<EOL><INDENT>if mult:<EOL><INDENT>decoded.append(int(mult) * letter)<EOL>mult = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>decoded.append(letter)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>mult += letter<EOL><DEDENT><DEDENT>text = '<STR_LIT>'.join(decoded)<EOL>return text<EOL>

r"""Perform decoding of run-length-encoding (RLE).

        Parameters
        ----------
        text : str
            A text string to decode

        Returns
        -------
        str
            Word decoded by RLE

        Examples
        --------
        >>> rle = RLE()
        >>> bwt = BWT()
        >>> bwt.decode(rle.decode('n\x00ilag'))
        'align'
        >>> rle.decode('align')
        'align'

        >>> bwt.decode(rle.decode('annb\x00aa'))
        'banana'
        >>> rle.decode('banana')
        'banana'

        >>> bwt.decode(rle.decode('ab\x00abbab5a'))
        'aaabaabababa'
        >>> rle.decode('3abaabababa')
        'aaabaabababa'


return Arithmetic(text).get_probs()<EOL>

r"""Generate a probability dict from the provided text.

    This is a wrapper for :py:meth:`Arithmetic.train`.

    Parameters
    ----------
    text : str
        The text data over which to calculate probability statistics. This must
        not contain the NUL (0x00) character because that's used to indicate
        the end of data.

    Returns
    -------
    dict
        A probability dict

    Example
    -------
    >>> ac_train('the quick brown fox jumped over the lazy dog')
    {' ': (Fraction(0, 1), Fraction(8, 45)),
     'o': (Fraction(8, 45), Fraction(4, 15)),
     'e': (Fraction(4, 15), Fraction(16, 45)),
     'u': (Fraction(16, 45), Fraction(2, 5)),
     't': (Fraction(2, 5), Fraction(4, 9)),
     'r': (Fraction(4, 9), Fraction(22, 45)),
     'h': (Fraction(22, 45), Fraction(8, 15)),
     'd': (Fraction(8, 15), Fraction(26, 45)),
     'z': (Fraction(26, 45), Fraction(3, 5)),
     'y': (Fraction(3, 5), Fraction(28, 45)),
     'x': (Fraction(28, 45), Fraction(29, 45)),
     'w': (Fraction(29, 45), Fraction(2, 3)),
     'v': (Fraction(2, 3), Fraction(31, 45)),
     'q': (Fraction(31, 45), Fraction(32, 45)),
     'p': (Fraction(32, 45), Fraction(11, 15)),
     'n': (Fraction(11, 15), Fraction(34, 45)),
     'm': (Fraction(34, 45), Fraction(7, 9)),
     'l': (Fraction(7, 9), Fraction(4, 5)),
     'k': (Fraction(4, 5), Fraction(37, 45)),
     'j': (Fraction(37, 45), Fraction(38, 45)),
     'i': (Fraction(38, 45), Fraction(13, 15)),
     'g': (Fraction(13, 15), Fraction(8, 9)),
     'f': (Fraction(8, 9), Fraction(41, 45)),
     'c': (Fraction(41, 45), Fraction(14, 15)),
     'b': (Fraction(14, 15), Fraction(43, 45)),
     'a': (Fraction(43, 45), Fraction(44, 45)),
     '\x00': (Fraction(44, 45), Fraction(1, 1))}


coder = Arithmetic()<EOL>coder.set_probs(probs)<EOL>return coder.encode(text)<EOL>

Encode a text using arithmetic coding with the provided probabilities.

    This is a wrapper for :py:meth:`Arithmetic.encode`.

    Parameters
    ----------
    text : str
        A string to encode
    probs : dict
        A probability statistics dictionary generated by
        :py:meth:`Arithmetic.train`

    Returns
    -------
    tuple
        The arithmetically coded text

    Example
    -------
    >>> pr = ac_train('the quick brown fox jumped over the lazy dog')
    >>> ac_encode('align', pr)
    (16720586181, 34)


coder = Arithmetic()<EOL>coder.set_probs(probs)<EOL>return coder.decode(longval, nbits)<EOL>

Decode the number to a string using the given statistics.

    This is a wrapper for :py:meth:`Arithmetic.decode`.

    Parameters
    ----------
    longval : int
        The first part of an encoded tuple from ac_encode
    nbits : int
        The second part of an encoded tuple from ac_encode
    probs : dict
        A probability statistics dictionary generated by
        :py:meth:`Arithmetic.train`

    Returns
    -------
    str
        The arithmetically decoded text

    Example
    -------
    >>> pr = ac_train('the quick brown fox jumped over the lazy dog')
    >>> ac_decode(16720586181, 34, pr)
    'align'


if text is not None:<EOL><INDENT>self.train(text)<EOL><DEDENT>

Initialize arithmetic coder object.

        Parameters
        ----------
        text : str
            The training text


return self._probs<EOL>

Return the probs dictionary.

        Returns
        -------
        dict
            The dictionary of probabilities


self._probs = probs<EOL>

Set the probs dictionary.

        Parameters
        ----------
        probs : dict
            The dictionary of probabilities


text = text_type(text)<EOL>if '<STR_LIT:\x00>' in text:<EOL><INDENT>text = text.replace('<STR_LIT:\x00>', '<STR_LIT:U+0020>')<EOL><DEDENT>counts = Counter(text)<EOL>counts['<STR_LIT:\x00>'] = <NUM_LIT:1><EOL>tot_letters = sum(counts.values())<EOL>tot = <NUM_LIT:0><EOL>self._probs = {}<EOL>prev = Fraction(<NUM_LIT:0>)<EOL>for char, count in sorted(<EOL>counts.items(), key=lambda x: (x[<NUM_LIT:1>], x[<NUM_LIT:0>]), reverse=True<EOL>):<EOL><INDENT>follow = Fraction(tot + count, tot_letters)<EOL>self._probs[char] = (prev, follow)<EOL>prev = follow<EOL>tot = tot + count<EOL><DEDENT>

r"""Generate a probability dict from the provided text.

        Text to 0-order probability statistics as a dict

        Parameters
        ----------
        text : str
            The text data over which to calculate probability statistics. This
            must not contain the NUL (0x00) character because that is used to
            indicate the end of data.

        Example
        -------
        >>> ac = Arithmetic()
        >>> ac.train('the quick brown fox jumped over the lazy dog')
        >>> ac.get_probs()
        {' ': (Fraction(0, 1), Fraction(8, 45)),
         'o': (Fraction(8, 45), Fraction(4, 15)),
         'e': (Fraction(4, 15), Fraction(16, 45)),
         'u': (Fraction(16, 45), Fraction(2, 5)),
         't': (Fraction(2, 5), Fraction(4, 9)),
         'r': (Fraction(4, 9), Fraction(22, 45)),
         'h': (Fraction(22, 45), Fraction(8, 15)),
         'd': (Fraction(8, 15), Fraction(26, 45)),
         'z': (Fraction(26, 45), Fraction(3, 5)),
         'y': (Fraction(3, 5), Fraction(28, 45)),
         'x': (Fraction(28, 45), Fraction(29, 45)),
         'w': (Fraction(29, 45), Fraction(2, 3)),
         'v': (Fraction(2, 3), Fraction(31, 45)),
         'q': (Fraction(31, 45), Fraction(32, 45)),
         'p': (Fraction(32, 45), Fraction(11, 15)),
         'n': (Fraction(11, 15), Fraction(34, 45)),
         'm': (Fraction(34, 45), Fraction(7, 9)),
         'l': (Fraction(7, 9), Fraction(4, 5)),
         'k': (Fraction(4, 5), Fraction(37, 45)),
         'j': (Fraction(37, 45), Fraction(38, 45)),
         'i': (Fraction(38, 45), Fraction(13, 15)),
         'g': (Fraction(13, 15), Fraction(8, 9)),
         'f': (Fraction(8, 9), Fraction(41, 45)),
         'c': (Fraction(41, 45), Fraction(14, 15)),
         'b': (Fraction(14, 15), Fraction(43, 45)),
         'a': (Fraction(43, 45), Fraction(44, 45)),
         '\x00': (Fraction(44, 45), Fraction(1, 1))}


text = text_type(text)<EOL>if '<STR_LIT:\x00>' in text:<EOL><INDENT>text = text.replace('<STR_LIT:\x00>', '<STR_LIT:U+0020>')<EOL><DEDENT>minval = Fraction(<NUM_LIT:0>)<EOL>maxval = Fraction(<NUM_LIT:1>)<EOL>for char in text + '<STR_LIT:\x00>':<EOL><INDENT>prob_range = self._probs[char]<EOL>delta = maxval - minval<EOL>maxval = minval + prob_range[<NUM_LIT:1>] * delta<EOL>minval = minval + prob_range[<NUM_LIT:0>] * delta<EOL><DEDENT>delta = (maxval - minval) / <NUM_LIT:2><EOL>nbits = long(<NUM_LIT:0>)<EOL>while delta < <NUM_LIT:1>:<EOL><INDENT>nbits += <NUM_LIT:1><EOL>delta *= <NUM_LIT:2><EOL><DEDENT>if nbits == <NUM_LIT:0>:  <EOL><INDENT>return <NUM_LIT:0>, <NUM_LIT:0><EOL><DEDENT>avg = (maxval + minval) * <NUM_LIT:2> ** (nbits - <NUM_LIT:1>)<EOL>return avg.numerator // avg.denominator, nbits<EOL>

Encode a text using arithmetic coding.

        Text and the 0-order probability statistics -> longval, nbits

        The encoded number is Fraction(longval, 2**nbits)

        Parameters
        ----------
        text : str
            A string to encode

        Returns
        -------
        tuple
            The arithmetically coded text

        Example
        -------
        >>> ac = Arithmetic('the quick brown fox jumped over the lazy dog')
        >>> ac.encode('align')
        (16720586181, 34)


val = Fraction(longval, long(<NUM_LIT:1>) << nbits)<EOL>letters = []<EOL>probs_items = [<EOL>(char, minval, maxval)<EOL>for (char, (minval, maxval)) in self._probs.items()<EOL>]<EOL>char = '<STR_LIT:\x00>'<EOL>while True:<EOL><INDENT>for (char, minval, maxval) in probs_items:  <EOL><INDENT>if minval <= val < maxval:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if char == '<STR_LIT:\x00>':<EOL><INDENT>break<EOL><DEDENT>letters.append(char)<EOL>delta = maxval - minval<EOL>val = (val - minval) / delta<EOL><DEDENT>return '<STR_LIT>'.join(letters)<EOL>

Decode the number to a string using the given statistics.

        Parameters
        ----------
        longval : int
            The first part of an encoded tuple from encode
        nbits : int
            The second part of an encoded tuple from encode

        Returns
        -------
        str
            The arithmetically decoded text

        Example
        -------
        >>> ac = Arithmetic('the quick brown fox jumped over the lazy dog')
        >>> ac.decode(16720586181, 34)
        'align'


features = []<EOL>pos = <NUM_LIT:0><EOL>ipa = normalize('<STR_LIT>', text_type(ipa.lower()))<EOL>maxsymlen = max(len(_) for _ in _PHONETIC_FEATURES)<EOL>while pos < len(ipa):<EOL><INDENT>found_match = False<EOL>for i in range(maxsymlen, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>if (<EOL>pos + i - <NUM_LIT:1> <= len(ipa)<EOL>and ipa[pos : pos + i] in _PHONETIC_FEATURES<EOL>):<EOL><INDENT>features.append(_PHONETIC_FEATURES[ipa[pos : pos + i]])<EOL>pos += i<EOL>found_match = True<EOL><DEDENT><DEDENT>if not found_match:<EOL><INDENT>features.append(-<NUM_LIT:1>)<EOL>pos += <NUM_LIT:1><EOL><DEDENT><DEDENT>return features<EOL>

Convert IPA to features.

    This translates an IPA string of one or more phones to a list of ints
    representing the features of the string.

    Parameters
    ----------
    ipa : str
        The IPA representation of a phone or series of phones

    Returns
    -------
    list of ints
        A representation of the features of the input string

    Examples
    --------
    >>> ipa_to_features('mut')
    [2709662981243185770, 1825831513894594986, 2783230754502126250]
    >>> ipa_to_features('fon')
    [2781702983095331242, 1825831531074464170, 2711173160463936106]
    >>> ipa_to_features('telz')
    [2783230754502126250, 1826957430176000426, 2693158761954453926,
    2783230754501863834]


<EOL>if feature not in _FEATURE_MASK:<EOL><INDENT>raise AttributeError(<EOL>"<STR_LIT>"<EOL>+ "<STR_LIT>".join(<EOL>(<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>)<EOL>)<EOL>+ "<STR_LIT:'>"<EOL>)<EOL><DEDENT>mask = _FEATURE_MASK[feature]<EOL>pos_mask = mask >> <NUM_LIT:1><EOL>retvec = []<EOL>for char in vector:<EOL><INDENT>if char < <NUM_LIT:0>:<EOL><INDENT>retvec.append(float('<STR_LIT>'))<EOL><DEDENT>else:<EOL><INDENT>masked = char & mask<EOL>if masked == <NUM_LIT:0>:<EOL><INDENT>retvec.append(<NUM_LIT:0>)  <EOL><DEDENT>elif masked == mask:<EOL><INDENT>retvec.append(<NUM_LIT:2>)  <EOL><DEDENT>elif masked & pos_mask:<EOL><INDENT>retvec.append(<NUM_LIT:1>)  <EOL><DEDENT>else:<EOL><INDENT>retvec.append(-<NUM_LIT:1>)  <EOL><DEDENT><DEDENT><DEDENT>return retvec<EOL>

Get a feature vector.

    This returns a list of ints, equal in length to the vector input,
        representing presence/absence/neutrality with respect to a particular
        phonetic feature.

    Parameters
    ----------
    vector : list
        A tuple or list of ints representing the phonetic features of a phone
        or series of phones (such as is returned by the ipa_to_features
        function)
    feature : str
        A feature name from the set:

            - ``consonantal``
            - ``sonorant``
            - ``syllabic``
            - ``labial``
            - ``round``
            - ``coronal``
            - ``anterior``
            - ``distributed``
            - ``dorsal``
            - ``high``
            - ``low``
            - ``back``
            - ``tense``
            - ``pharyngeal``
            - ``ATR``
            - ``voice``
            - ``spread_glottis``
            - ``constricted_glottis``
            - ``continuant``
            - ``strident``
            - ``lateral``
            - ``delayed_release``
            - ``nasal``

    Returns
    -------
    list of ints
        A list indicating presence/absence/neutrality with respect to the
        feature

    Raises
    ------
    AttributeError
        feature must be one of ...

    Examples
    --------
    >>> tails = ipa_to_features('telz')
    >>> get_feature(tails, 'consonantal')
    [1, -1, 1, 1]
    >>> get_feature(tails, 'sonorant')
    [-1, 1, 1, -1]
    >>> get_feature(tails, 'nasal')
    [-1, -1, -1, -1]
    >>> get_feature(tails, 'coronal')
    [1, -1, 1, 1]


if feat1 < <NUM_LIT:0> or feat2 < <NUM_LIT:0>:<EOL><INDENT>return -<NUM_LIT:1.0><EOL><DEDENT>if feat1 == feat2:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>magnitude = len(_FEATURE_MASK)<EOL>featxor = feat1 ^ feat2<EOL>diffbits = <NUM_LIT:0><EOL>while featxor:<EOL><INDENT>if featxor & <NUM_LIT>:<EOL><INDENT>diffbits += <NUM_LIT:1><EOL><DEDENT>featxor >>= <NUM_LIT:1><EOL><DEDENT>return <NUM_LIT:1> - (diffbits / (<NUM_LIT:2> * magnitude))<EOL>

Compare features.

    This returns a number in the range [0, 1] representing a comparison of two
    feature bundles.

    If one of the bundles is negative, -1 is returned (for unknown values)

    If the bundles are identical, 1 is returned.

    If they are inverses of one another, 0 is returned.

    Otherwise, a float representing their similarity is returned.

    Parameters
    ----------
    feat1 : int
        A feature bundle
    feat2 : int
        A feature bundle

    Returns
    -------
    float
        A comparison of the feature bundles

    Examples
    --------
    >>> cmp_features(ipa_to_features('l')[0], ipa_to_features('l')[0])
    1.0
    >>> cmp_features(ipa_to_features('l')[0], ipa_to_features('n')[0])
    0.8709677419354839
    >>> cmp_features(ipa_to_features('l')[0], ipa_to_features('z')[0])
    0.8709677419354839
    >>> cmp_features(ipa_to_features('l')[0], ipa_to_features('i')[0])
    0.564516129032258


self.ngcorpus = Counter()<EOL>if corpus is None:<EOL><INDENT>return<EOL><DEDENT>elif isinstance(corpus, Corpus):<EOL><INDENT>self.corpus_importer(corpus)<EOL><DEDENT>else:<EOL><INDENT>raise TypeError(<EOL>'<STR_LIT>'<EOL>+ str(type(corpus))<EOL>+ '<STR_LIT>'<EOL>)<EOL><DEDENT>

r"""Initialize Corpus.

        Parameters
        ----------
        corpus : Corpus
            The :py:class:`Corpus` from which to initialize the n-gram corpus.
            By default, this is None, which initializes an empty NGramCorpus.
            This can then be populated using NGramCorpus methods.

        Raises
        ------
        TypeError
            Corpus argument must be None or of type abydos.Corpus

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> ngcorp = NGramCorpus(Corpus(tqbf))


def corpus_importer(self, corpus, n_val=<NUM_LIT:1>, bos='<STR_LIT>', eos='<STR_LIT>'):

if not corpus or not isinstance(corpus, Corpus):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>sentences = corpus.sents()<EOL>for sent in sentences:<EOL><INDENT>ngs = Counter(sent)<EOL>for key in ngs.keys():<EOL><INDENT>self._add_to_ngcorpus(self.ngcorpus, [key], ngs[key])<EOL><DEDENT>if n_val > <NUM_LIT:1>:<EOL><INDENT>if bos and bos != '<STR_LIT>':<EOL><INDENT>sent = [bos] + sent<EOL><DEDENT>if eos and eos != '<STR_LIT>':<EOL><INDENT>sent += [eos]<EOL><DEDENT>for i in range(<NUM_LIT:2>, n_val + <NUM_LIT:1>):<EOL><INDENT>for j in range(len(sent) - i + <NUM_LIT:1>):<EOL><INDENT>self._add_to_ngcorpus(<EOL>self.ngcorpus, sent[j : j + i], <NUM_LIT:1><EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>

r"""Fill in self.ngcorpus from a Corpus argument.

        Parameters
        ----------
        corpus :Corpus
            The Corpus from which to initialize the n-gram corpus
        n_val : int
            Maximum n value for n-grams
        bos : str
            String to insert as an indicator of beginning of sentence
        eos : str
            String to insert as an indicator of end of sentence

        Raises
        ------
        TypeError
            Corpus argument of the Corpus class required.

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> ngcorp = NGramCorpus()
        >>> ngcorp.corpus_importer(Corpus(tqbf))


def get_count(self, ngram, corpus=None):

if not corpus:<EOL><INDENT>corpus = self.ngcorpus<EOL><DEDENT>if not ngram:<EOL><INDENT>return corpus[None]<EOL><DEDENT>if isinstance(ngram, (text_type, str)):<EOL><INDENT>ngram = text_type(ngram).split()<EOL><DEDENT>if ngram[<NUM_LIT:0>] in corpus:<EOL><INDENT>return self.get_count(ngram[<NUM_LIT:1>:], corpus[ngram[<NUM_LIT:0>]])<EOL><DEDENT>return <NUM_LIT:0><EOL>

r"""Get the count of an n-gram in the corpus.

        Parameters
        ----------
        ngram : str
            The n-gram to retrieve the count of from the n-gram corpus
        corpus : Corpus
            The corpus

        Returns
        -------
        int
            The n-gram count

        Examples
        --------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> ngcorp = NGramCorpus(Corpus(tqbf))
        >>> NGramCorpus(Corpus(tqbf)).get_count('the')
        2
        >>> NGramCorpus(Corpus(tqbf)).get_count('fox')
        1


def _add_to_ngcorpus(self, corpus, words, count):

if words[<NUM_LIT:0>] not in corpus:<EOL><INDENT>corpus[words[<NUM_LIT:0>]] = Counter()<EOL><DEDENT>if len(words) == <NUM_LIT:1>:<EOL><INDENT>corpus[words[<NUM_LIT:0>]][None] += count<EOL><DEDENT>else:<EOL><INDENT>self._add_to_ngcorpus(corpus[words[<NUM_LIT:0>]], words[<NUM_LIT:1>:], count)<EOL><DEDENT>

Build up a corpus entry recursively.

        Parameters
        ----------
        corpus : Corpus
            The corpus
        words : [str]
            Words to add to the corpus
        count : int
            Count of words


with c_open(corpus_file, '<STR_LIT:r>', encoding='<STR_LIT:utf-8>') as gng:<EOL><INDENT>for line in gng:<EOL><INDENT>line = line.rstrip().split('<STR_LIT:\t>')<EOL>words = line[<NUM_LIT:0>].split()<EOL>self._add_to_ngcorpus(self.ngcorpus, words, int(line[<NUM_LIT:2>]))<EOL><DEDENT><DEDENT>

Fill in self.ngcorpus from a Google NGram corpus file.

        Parameters
        ----------
        corpus_file : file
            The Google NGram file from which to initialize the n-gram corpus


if '<STR_LIT:U+0020>' in term:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>tcount = self.get_count(term)<EOL>if tcount == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>return <NUM_LIT:1> + log10(tcount)<EOL>

r"""Return term frequency.

        Parameters
        ----------
        term : str
            The term for which to calculate tf

        Returns
        -------
        float
            The term frequency (tf)

        Raises
        ------
        ValueError
            tf can only calculate the frequency of individual words

        Examples
        --------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> ngcorp = NGramCorpus(Corpus(tqbf))
        >>> NGramCorpus(Corpus(tqbf)).tf('the')
        1.3010299956639813
        >>> NGramCorpus(Corpus(tqbf)).tf('fox')
        1.0


self.corpus = []<EOL>self.doc_split = doc_split<EOL>self.sent_split = sent_split<EOL>for document in corpus_text.split(doc_split):<EOL><INDENT>doc = []<EOL>for sentence in (s.split() for s in document.split(sent_split)):<EOL><INDENT>if stop_words:<EOL><INDENT>for word in set(stop_words):<EOL><INDENT>while word in sentence:<EOL><INDENT>sentence.remove(word)<EOL><DEDENT><DEDENT><DEDENT>for char in set(filter_chars):<EOL><INDENT>sentence = [word.replace(char, '<STR_LIT>') for word in sentence]<EOL><DEDENT>if sentence:<EOL><INDENT>doc.append(sentence)<EOL><DEDENT><DEDENT>if doc:<EOL><INDENT>self.corpus.append(doc)<EOL><DEDENT><DEDENT>

r"""Initialize Corpus.

        By default, when importing a corpus:
            - two consecutive newlines divide documents
            - single newlines divide sentences
            - other whitespace divides words

        Parameters
        ----------
        corpus_text : str
            The corpus text as a single string
        doc_split : str
            A character or string used to split corpus_text into documents
        sent_split : str
            A character or string used to split documents into sentences
        filter_chars : list
            A list of characters (as a string, tuple, set, or list) to filter
            out of the corpus text
        stop_words : list
            A list of words (as a tuple, set, or list) to filter out of the
            corpus text

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> corp = Corpus(tqbf)


return self.corpus<EOL>

r"""Return the docs in the corpus.

        Each list within a doc represents the sentences in that doc, each of
        which is in turn a list of words within that sentence.

        Returns
        -------
        [[[str]]]
            The docs in the corpus as a list of lists of lists of strs

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> corp = Corpus(tqbf)
        >>> corp.docs()
        [[['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy',
        'dog.'], ['And', 'then', 'it', 'slept.'], ['And', 'the', 'dog',
        'ran', 'off.']]]
        >>> len(corp.docs())
        1


return self.docs()<EOL>

r"""Return the paragraphs in the corpus.

        Each list within a paragraph represents the sentences in that doc, each
        of which is in turn a list of words within that sentence.
        This is identical to the docs() member function and exists only to
        mirror part of NLTK's API for corpora.

        Returns
        -------
        [[[str]]]
            The paragraphs in the corpus as a list of lists of lists of strs

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> corp = Corpus(tqbf)
        >>> corp.paras()
        [[['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy',
        'dog.'], ['And', 'then', 'it', 'slept.'], ['And', 'the', 'dog',
        'ran', 'off.']]]
        >>> len(corp.paras())
        1


return [words for sents in self.corpus for words in sents]<EOL>

r"""Return the sentences in the corpus.

        Each list within a sentence represents the words within that sentence.

        Returns
        -------
        [[str]]
            The sentences in the corpus as a list of lists of strs

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> corp = Corpus(tqbf)
        >>> corp.sents()
        [['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy',
        'dog.'], ['And', 'then', 'it', 'slept.'], ['And', 'the', 'dog',
        'ran', 'off.']]
        >>> len(corp.sents())
        3


return [words for sents in self.sents() for words in sents]<EOL>

r"""Return the words in the corpus as a single list.

        Returns
        -------
        [str]
            The words in the corpus as a list of strs

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> corp = Corpus(tqbf)
        >>> corp.words()
        ['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy',
        'dog.', 'And', 'then', 'it', 'slept.', 'And', 'the', 'dog', 'ran',
        'off.']
        >>> len(corp.words())
        18


return [<EOL>[words for sents in doc for words in sents] for doc in self.corpus<EOL>]<EOL>

r"""Return the docs in the corpus, with sentences flattened.

        Each list within the corpus represents all the words of that document.
        Thus the sentence level of lists has been flattened.

        Returns
        -------
        [[str]]
            The docs in the corpus as a list of list of strs

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> corp = Corpus(tqbf)
        >>> corp.docs_of_words()
        [['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy',
        'dog.', 'And', 'then', 'it', 'slept.', 'And', 'the', 'dog', 'ran',
        'off.']]
        >>> len(corp.docs_of_words())
        1


doc_list = []<EOL>for doc in self.corpus:<EOL><INDENT>sent_list = []<EOL>for sent in doc:<EOL><INDENT>sent_list.append('<STR_LIT:U+0020>'.join(sent))<EOL><DEDENT>doc_list.append(self.sent_split.join(sent_list))<EOL>del sent_list<EOL><DEDENT>return self.doc_split.join(doc_list)<EOL>

r"""Return the raw corpus.

        This is reconstructed by joining sub-components with the corpus' split
        characters

        Returns
        -------
        str
            The raw corpus

        Example
        -------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n'
        >>> tqbf += 'And then it slept.\n And the dog ran off.'
        >>> corp = Corpus(tqbf)
        >>> print(corp.raw())
        The quick brown fox jumped over the lazy dog.
        And then it slept.
        And the dog ran off.
        >>> len(corp.raw())
        85


docs_with_term = <NUM_LIT:0><EOL>docs = self.docs_of_words()<EOL>for doc in docs:<EOL><INDENT>doc_set = set(doc)<EOL>if transform:<EOL><INDENT>transformed_doc = []<EOL>for word in doc_set:<EOL><INDENT>transformed_doc.append(transform(word))<EOL><DEDENT>doc_set = set(transformed_doc)<EOL><DEDENT>if term in doc_set:<EOL><INDENT>docs_with_term += <NUM_LIT:1><EOL><DEDENT><DEDENT>if docs_with_term == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>return log10(len(docs) / docs_with_term)<EOL>

r"""Calculate the Inverse Document Frequency of a term in the corpus.

        Parameters
        ----------
        term : str
            The term to calculate the IDF of
        transform : function
            A function to apply to each document term before checking for the
            presence of term

        Returns
        -------
        float
            The IDF

        Examples
        --------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n\n'
        >>> tqbf += 'And then it slept.\n\n And the dog ran off.'
        >>> corp = Corpus(tqbf)
        >>> print(corp.docs())
        [[['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy',
        'dog.']],
        [['And', 'then', 'it', 'slept.']],
        [['And', 'the', 'dog', 'ran', 'off.']]]
        >>> round(corp.idf('dog'), 10)
        0.4771212547
        >>> round(corp.idf('the'), 10)
        0.1760912591


return SStemmer().stem(word)<EOL>

Return the S-stemmed form of a word.

    This is a wrapper for :py:meth:`SStemmer.stem`.

    Parameters
    ----------
    word : str
        The word to stem

    Returns
    -------
    str
        Word stem

    Examples
    --------
    >>> s_stemmer('summaries')
    'summary'
    >>> s_stemmer('summary')
    'summary'
    >>> s_stemmer('towers')
    'tower'
    >>> s_stemmer('reading')
    'reading'
    >>> s_stemmer('census')
    'census'


lowered = word.lower()<EOL>if lowered[-<NUM_LIT:3>:] == '<STR_LIT>' and lowered[-<NUM_LIT:4>:-<NUM_LIT:3>] not in {'<STR_LIT:e>', '<STR_LIT:a>'}:<EOL><INDENT>return word[:-<NUM_LIT:3>] + ('<STR_LIT:Y>' if word[-<NUM_LIT:1>:].isupper() else '<STR_LIT:y>')<EOL><DEDENT>if lowered[-<NUM_LIT:2>:] == '<STR_LIT>' and lowered[-<NUM_LIT:3>:-<NUM_LIT:2>] not in {'<STR_LIT:a>', '<STR_LIT:e>', '<STR_LIT:o>'}:<EOL><INDENT>return word[:-<NUM_LIT:1>]<EOL><DEDENT>if lowered[-<NUM_LIT:1>:] == '<STR_LIT:s>' and lowered[-<NUM_LIT:2>:-<NUM_LIT:1>] not in {'<STR_LIT:u>', '<STR_LIT:s>'}:<EOL><INDENT>return word[:-<NUM_LIT:1>]<EOL><DEDENT>return word<EOL>

Return the S-stemmed form of a word.

        Parameters
        ----------
        word : str
            The word to stem

        Returns
        -------
        str
            Word stem

        Examples
        --------
        >>> stmr = SStemmer()
        >>> stmr.stem('summaries')
        'summary'
        >>> stmr.stem('summary')
        'summary'
        >>> stmr.stem('towers')
        'tower'
        >>> stmr.stem('reading')
        'reading'
        >>> stmr.stem('census')
        'census'


return UEALite().stem(<EOL>word, max_word_length, max_acro_length, return_rule_no, var<EOL>)<EOL>

Return UEA-Lite stem.

    This is a wrapper for :py:meth:`UEALite.stem`.

    Parameters
    ----------
    word : str
        The word to stem
    max_word_length : int
        The maximum word length allowed
    max_acro_length : int
        The maximum acronym length allowed
    return_rule_no : bool
        If True, returns the stem along with rule number
    var : str
        Variant rules to use:

            - ``Adams`` to use Jason Adams' rules
            - ``Perl`` to use the original Perl rules

    Returns
    -------
    str or (str, int)
        Word stem

    Examples
    --------
    >>> uealite('readings')
    'read'
    >>> uealite('insulted')
    'insult'
    >>> uealite('cussed')
    'cuss'
    >>> uealite('fancies')
    'fancy'
    >>> uealite('eroded')
    'erode'


def _stem_with_duplicate_character_check(word, del_len):<EOL><INDENT>if word[-<NUM_LIT:1>] == '<STR_LIT:s>':<EOL><INDENT>del_len += <NUM_LIT:1><EOL><DEDENT>stemmed_word = word[:-del_len]<EOL>if re_match(r'<STR_LIT>', stemmed_word):<EOL><INDENT>stemmed_word = stemmed_word[:-<NUM_LIT:1>]<EOL><DEDENT>return stemmed_word<EOL><DEDENT>def _stem(word):<EOL><INDENT>stemmed_word = word<EOL>rule_no = <NUM_LIT:0><EOL>if not word:<EOL><INDENT>return word, <NUM_LIT:0><EOL><DEDENT>if word in self._problem_words or (<EOL>word == '<STR_LIT>' and var == '<STR_LIT>'<EOL>):<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>if max_word_length and len(word) > max_word_length:<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>if "<STR_LIT:'>" in word:<EOL><INDENT>if word[-<NUM_LIT:2>:] in {"<STR_LIT>", "<STR_LIT>"}:<EOL><INDENT>stemmed_word = word[:-<NUM_LIT:2>]<EOL><DEDENT>if word[-<NUM_LIT:1>:] == "<STR_LIT:'>":<EOL><INDENT>stemmed_word = word[:-<NUM_LIT:1>]<EOL><DEDENT>stemmed_word = stemmed_word.replace("<STR_LIT>", '<STR_LIT>')<EOL>stemmed_word = stemmed_word.replace("<STR_LIT>", '<STR_LIT>')<EOL>stemmed_word = stemmed_word.replace("<STR_LIT>", '<STR_LIT>')<EOL>stemmed_word = stemmed_word.replace("<STR_LIT>", '<STR_LIT>')<EOL>return stemmed_word, <NUM_LIT><EOL><DEDENT>if word.isdigit():<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>hyphen = word.find('<STR_LIT:->')<EOL>if len(word) > hyphen > <NUM_LIT:0>:<EOL><INDENT>if (<EOL>word[:hyphen].isalpha()<EOL>and word[hyphen + <NUM_LIT:1> :].isalpha()<EOL>):<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT><DEDENT>elif '<STR_LIT:_>' in word:<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>elif word[-<NUM_LIT:1>] == '<STR_LIT:s>' and word[:-<NUM_LIT:1>].isupper():<EOL><INDENT>if var == '<STR_LIT>' and len(word) - <NUM_LIT:1> > max_acro_length:<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>return word[:-<NUM_LIT:1>], <NUM_LIT><EOL><DEDENT>elif word.isupper():<EOL><INDENT>if var == '<STR_LIT>' and len(word) > max_acro_length:<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>return word, <NUM_LIT><EOL><DEDENT>elif re_match(r'<STR_LIT>', word):<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>elif word[<NUM_LIT:0>].isupper():<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT>elif var == '<STR_LIT>' and re_match(<EOL>r'<STR_LIT>', word<EOL>):<EOL><INDENT>return word, <NUM_LIT><EOL><DEDENT><DEDENT>for n in range(<NUM_LIT:7>, <NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>if word[-n:] in self._rules[var][n]:<EOL><INDENT>rule_no, del_len, add_str = self._rules[var][n][word[-n:]]<EOL>if del_len:<EOL><INDENT>stemmed_word = word[:-del_len]<EOL><DEDENT>else:<EOL><INDENT>stemmed_word = word<EOL><DEDENT>if add_str:<EOL><INDENT>stemmed_word += add_str<EOL><DEDENT>break<EOL><DEDENT><DEDENT>if not rule_no:<EOL><INDENT>if re_match(r'<STR_LIT>', word):  <EOL><INDENT>stemmed_word = _stem_with_duplicate_character_check(<EOL>word, <NUM_LIT:3><EOL>)<EOL>rule_no = <NUM_LIT><EOL><DEDENT>elif re_match(r'<STR_LIT>', word):  <EOL><INDENT>stemmed_word = _stem_with_duplicate_character_check(<EOL>word, <NUM_LIT:2><EOL>)<EOL>rule_no = <NUM_LIT><EOL><DEDENT>elif word[-<NUM_LIT:1>] == '<STR_LIT:s>':  <EOL><INDENT>stemmed_word = word[:-<NUM_LIT:1>]<EOL>rule_no = <NUM_LIT><EOL><DEDENT><DEDENT>return stemmed_word, rule_no<EOL><DEDENT>stem, rule_no = _stem(word)<EOL>if return_rule_no:<EOL><INDENT>return stem, rule_no<EOL><DEDENT>return stem<EOL>

Return UEA-Lite stem.

        Parameters
        ----------
        word : str
            The word to stem
        max_word_length : int
            The maximum word length allowed
        max_acro_length : int
            The maximum acronym length allowed
        return_rule_no : bool
            If True, returns the stem along with rule number
        var : str
            Variant rules to use:

                - ``Adams`` to use Jason Adams' rules
                - ``Perl`` to use the original Perl rules

        Returns
        -------
        str or (str, int)
            Word stem

        Examples
        --------
        >>> uealite('readings')
        'read'
        >>> uealite('insulted')
        'insult'
        >>> uealite('cussed')
        'cuss'
        >>> uealite('fancies')
        'fancy'
        >>> uealite('eroded')
        'erode'


return SnowballDanish().stem(word)<EOL>

Return Snowball Danish stem.

    This is a wrapper for :py:meth:`SnowballDanish.stem`.

    Parameters
    ----------
    word : str
        The word to stem

    Returns
    -------
    str
        Word stem

    Examples
    --------
    >>> sb_danish('underviser')
    'undervis'
    >>> sb_danish('suspension')
    'suspension'
    >>> sb_danish('sikkerhed')
    'sikker'


<EOL>word = normalize('<STR_LIT>', text_type(word.lower()))<EOL>r1_start = min(max(<NUM_LIT:3>, self._sb_r1(word)), len(word))<EOL>_r1 = word[r1_start:]<EOL>if _r1[-<NUM_LIT:7>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:7>]<EOL><DEDENT>elif _r1[-<NUM_LIT:6>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word = word[:-<NUM_LIT:6>]<EOL><DEDENT>elif _r1[-<NUM_LIT:5>:] in {<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>}:<EOL><INDENT>word = word[:-<NUM_LIT:5>]<EOL><DEDENT>elif _r1[-<NUM_LIT:4>:] in {<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>}:<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL><DEDENT>elif _r1[-<NUM_LIT:3>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT>elif _r1[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT>elif _r1[-<NUM_LIT:1>:] == '<STR_LIT:e>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>elif _r1[-<NUM_LIT:1>:] == '<STR_LIT:s>':<EOL><INDENT>if len(word) > <NUM_LIT:1> and word[-<NUM_LIT:2>] in self._s_endings:<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if word[r1_start:][-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>if word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT>_r1 = word[r1_start:]<EOL>repeat_step2 = False<EOL>if _r1[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL>repeat_step2 = True<EOL><DEDENT>elif _r1[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>elif _r1[-<NUM_LIT:3>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL>repeat_step2 = True<EOL><DEDENT>elif _r1[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL>repeat_step2 = True<EOL><DEDENT>if repeat_step2:<EOL><INDENT>if word[r1_start:][-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if (<EOL>len(word[r1_start:]) >= <NUM_LIT:1><EOL>and len(word) >= <NUM_LIT:2><EOL>and word[-<NUM_LIT:1>] == word[-<NUM_LIT:2>]<EOL>and word[-<NUM_LIT:1>] not in self._vowels<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>return word<EOL>

Return Snowball Danish stem.

        Parameters
        ----------
        word : str
            The word to stem

        Returns
        -------
        str
            Word stem

        Examples
        --------
        >>> stmr = SnowballDanish()
        >>> stmr.stem('underviser')
        'undervis'
        >>> stmr.stem('suspension')
        'suspension'
        >>> stmr.stem('sikkerhed')
        'sikker'


return CLEFSwedish().stem(word)<EOL>

Return CLEF Swedish stem.

    This is a wrapper for :py:meth:`CLEFSwedish.stem`.

    Parameters
    ----------
    word : str
        The word to stem

    Returns
    -------
    str
        Word stem

    Examples
    --------
    >>> clef_swedish('undervisa')
    'undervis'
    >>> clef_swedish('suspension')
    'suspensio'
    >>> clef_swedish('visshet')
    'viss'


wlen = len(word) - <NUM_LIT:2><EOL>if wlen > <NUM_LIT:2> and word[-<NUM_LIT:1>] == '<STR_LIT:s>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL>wlen -= <NUM_LIT:1><EOL><DEDENT>_endings = {<EOL><NUM_LIT:5>: {'<STR_LIT>', '<STR_LIT>'},<EOL><NUM_LIT:4>: {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'},<EOL><NUM_LIT:3>: {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'},<EOL><NUM_LIT:2>: {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'},<EOL><NUM_LIT:1>: {'<STR_LIT:a>', '<STR_LIT:e>', '<STR_LIT:n>', '<STR_LIT:t>'},<EOL>}<EOL>for end_len in range(<NUM_LIT:5>, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>if wlen > end_len and word[-end_len:] in _endings[end_len]:<EOL><INDENT>return word[:-end_len]<EOL><DEDENT><DEDENT>return word<EOL>

Return CLEF Swedish stem.

        Parameters
        ----------
        word : str
            The word to stem

        Returns
        -------
        str
            Word stem

        Examples
        --------
        >>> clef_swedish('undervisa')
        'undervis'
        >>> clef_swedish('suspension')
        'suspensio'
        >>> clef_swedish('visshet')
        'viss'


return Caumanns().stem(word)<EOL>

Return Caumanns German stem.

    This is a wrapper for :py:meth:`Caumanns.stem`.

    Parameters
    ----------
    word : str
        The word to stem

    Returns
    -------
    str
        Word stem

    Examples
    --------
    >>> caumanns('lesen')
    'les'
    >>> caumanns('graues')
    'grau'
    >>> caumanns('buchstabieren')
    'buchstabier'


if not word:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>upper_initial = word[<NUM_LIT:0>].isupper()<EOL>word = normalize('<STR_LIT>', text_type(word.lower()))<EOL>word = word.translate(self._umlauts)<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>new_word = word[<NUM_LIT:0>]<EOL>for i in range(<NUM_LIT:1>, len(word)):<EOL><INDENT>if new_word[i - <NUM_LIT:1>] == word[i]:<EOL><INDENT>new_word += '<STR_LIT:*>'<EOL><DEDENT>else:<EOL><INDENT>new_word += word[i]<EOL><DEDENT><DEDENT>word = new_word<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:$>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:%>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:&>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:#>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:!>')<EOL>while len(word) > <NUM_LIT:3>:<EOL><INDENT>if (len(word) > <NUM_LIT:4> and word[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>'}) or (<EOL>len(word) > <NUM_LIT:5> and word[-<NUM_LIT:2>:] == '<STR_LIT>'<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT>elif (word[-<NUM_LIT:1>] in {'<STR_LIT:e>', '<STR_LIT:s>', '<STR_LIT:n>'}) or (<EOL>not upper_initial and word[-<NUM_LIT:1>] in {'<STR_LIT:t>', '<STR_LIT:!>'}<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if len(word) > <NUM_LIT:5> and word[-<NUM_LIT:5>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>if word[-<NUM_LIT:1>] == '<STR_LIT:z>':<EOL><INDENT>word = word[:-<NUM_LIT:1>] + '<STR_LIT:x>'<EOL><DEDENT>word = word.replace('<STR_LIT:$>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT:%>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT:&>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT:#>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT:!>', '<STR_LIT>')<EOL>word = '<STR_LIT>'.join(<EOL>[word[<NUM_LIT:0>]]<EOL>+ [<EOL>word[i - <NUM_LIT:1>] if word[i] == '<STR_LIT:*>' else word[i]<EOL>for i in range(<NUM_LIT:1>, len(word))<EOL>]<EOL>)<EOL>if len(word) > <NUM_LIT:4>:<EOL><INDENT>word = word.replace('<STR_LIT>', '<STR_LIT>', <NUM_LIT:1>)<EOL><DEDENT>return word<EOL>

Return Caumanns German stem.

        Parameters
        ----------
        word : str
            The word to stem

        Returns
        -------
        str
            Word stem

        Examples
        --------
        >>> stmr = Caumanns()
        >>> stmr.stem('lesen')
        'les'
        >>> stmr.stem('graues')
        'grau'
        >>> stmr.stem('buchstabieren')
        'buchstabier'


return CLEFGerman().stem(word)<EOL>

Return CLEF German stem.

    This is a wrapper for :py:meth:`CLEFGerman.stem`.

    Parameters
    ----------
    word : str
        The word to stem

    Returns
    -------
    str
        Word stem

    Examples
    --------
    >>> clef_german('lesen')
    'lese'
    >>> clef_german('graues')
    'grau'
    >>> clef_german('buchstabieren')
    'buchstabier'


<EOL>word = normalize('<STR_LIT>', text_type(word.lower()))<EOL>word = word.translate(self._umlauts)<EOL>wlen = len(word) - <NUM_LIT:1><EOL>if wlen > <NUM_LIT:3>:<EOL><INDENT>if wlen > <NUM_LIT:5>:<EOL><INDENT>if word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>return word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT>if wlen > <NUM_LIT:4>:<EOL><INDENT>if word[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>return word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>if word[-<NUM_LIT:1>] in {'<STR_LIT:e>', '<STR_LIT:n>', '<STR_LIT:r>', '<STR_LIT:s>'}:<EOL><INDENT>return word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>return word<EOL>

Return CLEF German stem.

        Parameters
        ----------
        word : str
            The word to stem

        Returns
        -------
        str
            Word stem

        Examples
        --------
        >>> stmr = CLEFGerman()
        >>> stmr.stem('lesen')
        'lese'
        >>> stmr.stem('graues')
        'grau'
        >>> stmr.stem('buchstabieren')
        'buchstabier'


return Porter2().stem(word, early_english)<EOL>

Return the Porter2 (Snowball English) stem.

    This is a wrapper for :py:meth:`Porter2.stem`.

    Parameters
    ----------
    word : str
        The word to stem
    early_english : bool
        Set to True in order to remove -eth & -est (2nd & 3rd person singular
        verbal agreement suffixes)

    Returns
    -------
    str
        Word stem

    Examples
    --------
    >>> porter2('reading')
    'read'
    >>> porter2('suspension')
    'suspens'
    >>> porter2('elusiveness')
    'elus'

    >>> porter2('eateth', early_english=True)
    'eat'


def stem(self, word, early_english=False):

<EOL>word = normalize('<STR_LIT>', text_type(word.lower()))<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>if word in self._exception1dict:<EOL><INDENT>return self._exception1dict[word]<EOL><DEDENT>elif word in self._exception1set:<EOL><INDENT>return word<EOL><DEDENT>if len(word) < <NUM_LIT:3>:<EOL><INDENT>return word<EOL><DEDENT>while word and word[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>word = word[<NUM_LIT:1>:]<EOL>if len(word) < <NUM_LIT:2>:<EOL><INDENT>return word<EOL><DEDENT><DEDENT>if word[<NUM_LIT:0>] == '<STR_LIT:y>':<EOL><INDENT>word = '<STR_LIT:Y>' + word[<NUM_LIT:1>:]<EOL><DEDENT>for i in range(<NUM_LIT:1>, len(word)):<EOL><INDENT>if word[i] == '<STR_LIT:y>' and word[i - <NUM_LIT:1>] in self._vowels:<EOL><INDENT>word = word[:i] + '<STR_LIT:Y>' + word[i + <NUM_LIT:1> :]<EOL><DEDENT><DEDENT>r1_start = self._sb_r1(word, self._r1_prefixes)<EOL>r2_start = self._sb_r2(word, self._r1_prefixes)<EOL>if word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT>elif word[-<NUM_LIT:1>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>if len(word) < <NUM_LIT:3>:<EOL><INDENT>return word<EOL><DEDENT>if word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT>elif word[-<NUM_LIT:3>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>if len(word) > <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT>else:<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>pass<EOL><DEDENT>elif word[-<NUM_LIT:1>] == '<STR_LIT:s>':<EOL><INDENT>if self._sb_has_vowel(word[:-<NUM_LIT:2>]):<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if word in self._exception2set:<EOL><INDENT>return word<EOL><DEDENT>step1b_flag = False<EOL>if word[-<NUM_LIT:5>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:5>:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:5>:] == '<STR_LIT>':<EOL><INDENT>if self._sb_has_vowel(word[:-<NUM_LIT:5>]):<EOL><INDENT>word = word[:-<NUM_LIT:5>]<EOL>step1b_flag = True<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if self._sb_has_vowel(word[:-<NUM_LIT:4>]):<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL>step1b_flag = True<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:3>:<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if self._sb_has_vowel(word[:-<NUM_LIT:3>]):<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL>step1b_flag = True<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if self._sb_has_vowel(word[:-<NUM_LIT:2>]):<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL>step1b_flag = True<EOL><DEDENT><DEDENT>elif early_english:<EOL><INDENT>if word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if self._sb_has_vowel(word[:-<NUM_LIT:3>]):<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL>step1b_flag = True<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if self._sb_has_vowel(word[:-<NUM_LIT:3>]):<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL>step1b_flag = True<EOL><DEDENT><DEDENT><DEDENT>if step1b_flag:<EOL><INDENT>if word[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word += '<STR_LIT:e>'<EOL><DEDENT>elif word[-<NUM_LIT:2>:] in self._doubles:<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>elif self._sb_short_word(word, self._r1_prefixes):<EOL><INDENT>word += '<STR_LIT:e>'<EOL><DEDENT><DEDENT>if (<EOL>len(word) > <NUM_LIT:2><EOL>and word[-<NUM_LIT:1>] in {'<STR_LIT:Y>', '<STR_LIT:y>'}<EOL>and word[-<NUM_LIT:2>] not in self._vowels<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:1>] + '<STR_LIT:i>'<EOL><DEDENT>if word[-<NUM_LIT:2>] == '<STR_LIT:a>':<EOL><INDENT>if word[-<NUM_LIT:7>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:7>:<EOL><INDENT>word = word[:-<NUM_LIT:5>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:6>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:6>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:2>] == '<STR_LIT:c>':<EOL><INDENT>if word[-<NUM_LIT:4>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:1>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:2>] == '<STR_LIT:e>':<EOL><INDENT>if word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:2>] == '<STR_LIT:g>':<EOL><INDENT>if word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if (<EOL>r1_start >= <NUM_LIT:1><EOL>and len(word[r1_start:]) >= <NUM_LIT:3><EOL>and word[-<NUM_LIT:4>] == '<STR_LIT:l>'<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:2>] == '<STR_LIT:l>':<EOL><INDENT>if word[-<NUM_LIT:6>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:6>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:5>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:5>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:1>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:3>:<EOL><INDENT>word = word[:-<NUM_LIT:1>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if (<EOL>r1_start >= <NUM_LIT:1><EOL>and len(word[r1_start:]) >= <NUM_LIT:2><EOL>and word[-<NUM_LIT:3>] in self._li<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:2>] == '<STR_LIT:o>':<EOL><INDENT>if word[-<NUM_LIT:7>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:7>:<EOL><INDENT>word = word[:-<NUM_LIT:5>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:5>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:5>:<EOL><INDENT>word = word[:-<NUM_LIT:3>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:2>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:2>] == '<STR_LIT:s>':<EOL><INDENT>if word[-<NUM_LIT:7>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:7>:<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:5>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:5>:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:2>] == '<STR_LIT:t>':<EOL><INDENT>if word[-<NUM_LIT:6>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:6>:<EOL><INDENT>word = word[:-<NUM_LIT:5>] + '<STR_LIT>'<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:5>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:5>:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:5>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:5>:<EOL><INDENT>word = word[:-<NUM_LIT:3>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT><DEDENT>if word[-<NUM_LIT:7>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:7>:<EOL><INDENT>word = word[:-<NUM_LIT:5>] + '<STR_LIT:e>'<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:6>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:6>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:5>:] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:5>:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:5>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r2_start:]) >= <NUM_LIT:5>:<EOL><INDENT>word = word[:-<NUM_LIT:5>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:3>:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT>for suffix in (<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>):<EOL><INDENT>if word[-len(suffix) :] == suffix:<EOL><INDENT>if len(word[r2_start:]) >= len(suffix):<EOL><INDENT>word = word[: -len(suffix)]<EOL><DEDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if (<EOL>len(word[r2_start:]) >= <NUM_LIT:3><EOL>and len(word) >= <NUM_LIT:4><EOL>and word[-<NUM_LIT:4>] in tuple('<STR_LIT>')<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT><DEDENT>if word[-<NUM_LIT:1>] == '<STR_LIT:e>':<EOL><INDENT>if len(word[r2_start:]) >= <NUM_LIT:1> or (<EOL>len(word[r1_start:]) >= <NUM_LIT:1><EOL>and not self._sb_ends_in_short_syllable(word[:-<NUM_LIT:1>])<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:1>] == '<STR_LIT:l>':<EOL><INDENT>if len(word[r2_start:]) >= <NUM_LIT:1> and word[-<NUM_LIT:2>] == '<STR_LIT:l>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>for i in range(<NUM_LIT:0>, len(word)):<EOL><INDENT>if word[i] == '<STR_LIT:Y>':<EOL><INDENT>word = word[:i] + '<STR_LIT:y>' + word[i + <NUM_LIT:1> :]<EOL><DEDENT><DEDENT>return word<EOL>

Return the Porter2 (Snowball English) stem.

        Parameters
        ----------
        word : str
            The word to stem
        early_english : bool
            Set to True in order to remove -eth & -est (2nd & 3rd person
            singular verbal agreement suffixes)

        Returns
        -------
        str
            Word stem

        Examples
        --------
        >>> stmr = Porter2()
        >>> stmr.stem('reading')
        'read'
        >>> stmr.stem('suspension')
        'suspens'
        >>> stmr.stem('elusiveness')
        'elus'

        >>> stmr.stem('eateth', early_english=True)
        'eat'


return SnowballGerman().stem(word, alternate_vowels)<EOL>

Return Snowball German stem.

    This is a wrapper for :py:meth:`SnowballGerman.stem`.

    Parameters
    ----------
    word : str
        The word to stem
    alternate_vowels : bool
        Composes ae as ä, oe as ö, and ue as ü before running the algorithm

    Returns
    -------
    str
        Word stem

    Examples
    --------
    >>> sb_german('lesen')
    'les'
    >>> sb_german('graues')
    'grau'
    >>> sb_german('buchstabieren')
    'buchstabi'


def stem(self, word, alternate_vowels=False):

<EOL>word = normalize('<STR_LIT>', word.lower())<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>if len(word) > <NUM_LIT:2>:<EOL><INDENT>for i in range(<NUM_LIT:2>, len(word)):<EOL><INDENT>if word[i] in self._vowels and word[i - <NUM_LIT:2>] in self._vowels:<EOL><INDENT>if word[i - <NUM_LIT:1>] == '<STR_LIT:u>':<EOL><INDENT>word = word[: i - <NUM_LIT:1>] + '<STR_LIT>' + word[i:]<EOL><DEDENT>elif word[i - <NUM_LIT:1>] == '<STR_LIT:y>':<EOL><INDENT>word = word[: i - <NUM_LIT:1>] + '<STR_LIT:Y>' + word[i:]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if alternate_vowels:<EOL><INDENT>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>r1_start = max(<NUM_LIT:3>, self._sb_r1(word))<EOL>r2_start = self._sb_r2(word)<EOL>niss_flag = False<EOL>if word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:3>:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:2>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:2>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:2>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL>niss_flag = True<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:2>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL>niss_flag = True<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:1>:] == '<STR_LIT:e>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:1>:<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL>niss_flag = True<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:1>:] == '<STR_LIT:s>':<EOL><INDENT>if (<EOL>len(word[r1_start:]) >= <NUM_LIT:1><EOL>and len(word) >= <NUM_LIT:2><EOL>and word[-<NUM_LIT:2>] in self._s_endings<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if niss_flag and word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>if word[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:3>:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:2>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r1_start:]) >= <NUM_LIT:2>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if (<EOL>len(word[r1_start:]) >= <NUM_LIT:2><EOL>and len(word) >= <NUM_LIT:6><EOL>and word[-<NUM_LIT:3>] in self._st_endings<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>if word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r2_start:]) >= <NUM_LIT:4> and word[-<NUM_LIT:5>] != '<STR_LIT:e>':<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL><DEDENT><DEDENT>elif word[-<NUM_LIT:4>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>if len(word[r2_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL>if word[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>'} and len(word[r1_start:]) >= <NUM_LIT:2>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>if len(word[r2_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL>if word[-<NUM_LIT:4>:] == '<STR_LIT>' and len(word[r2_start:]) >= <NUM_LIT:4>:<EOL><INDENT>word = word[:-<NUM_LIT:4>]<EOL><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>' and len(word[r2_start:]) >= <NUM_LIT:2>:<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:3>:] in {'<STR_LIT:end>', '<STR_LIT>'}:<EOL><INDENT>if len(word[r2_start:]) >= <NUM_LIT:3>:<EOL><INDENT>word = word[:-<NUM_LIT:3>]<EOL>if (<EOL>word[-<NUM_LIT:2>:] == '<STR_LIT>'<EOL>and len(word[r2_start:]) >= <NUM_LIT:2><EOL>and word[-<NUM_LIT:3>] != '<STR_LIT:e>'<EOL>):<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT><DEDENT>elif word[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>if len(word[r2_start:]) >= <NUM_LIT:2> and word[-<NUM_LIT:3>] != '<STR_LIT:e>':<EOL><INDENT>word = word[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>for i in range(<NUM_LIT:0>, len(word)):<EOL><INDENT>if word[i] == '<STR_LIT:Y>':<EOL><INDENT>word = word[:i] + '<STR_LIT:y>' + word[i + <NUM_LIT:1> :]<EOL><DEDENT>elif word[i] == '<STR_LIT>':<EOL><INDENT>word = word[:i] + '<STR_LIT:u>' + word[i + <NUM_LIT:1> :]<EOL><DEDENT><DEDENT>_umlauts = dict(zip((ord(_) for _ in '<STR_LIT>'), '<STR_LIT>'))<EOL>word = word.translate(_umlauts)<EOL>return word<EOL>

Return Snowball German stem.

        Parameters
        ----------
        word : str
            The word to stem
        alternate_vowels : bool
            Composes ae as ä, oe as ö, and ue as ü before running the algorithm

        Returns
        -------
        str
            Word stem

        Examples
        --------
        >>> stmr = SnowballGerman()
        >>> stmr.stem('lesen')
        'les'
        >>> stmr.stem('graues')
        'grau'
        >>> stmr.stem('buchstabieren')
        'buchstabi'


return SnowballDutch().stem(word)<EOL>

Return Snowball Dutch stem.

    This is a wrapper for :py:meth:`SnowballDutch.stem`.

    Parameters
    ----------
    word : str
        The word to stem

    Returns
    -------
    str
        Word stem

    Examples
    --------
    >>> sb_dutch('lezen')
    'lez'
    >>> sb_dutch('opschorting')
    'opschort'
    >>> sb_dutch('ongrijpbaarheid')
    'ongrijp'


if (<EOL>len(word) > <NUM_LIT:1><EOL>and word[-<NUM_LIT:1>] == word[-<NUM_LIT:2>]<EOL>and word[-<NUM_LIT:1>] in {'<STR_LIT:d>', '<STR_LIT:k>', '<STR_LIT:t>'}<EOL>):<EOL><INDENT>return word[:-<NUM_LIT:1>]<EOL><DEDENT>return word<EOL>

Undouble endings -kk, -dd, and -tt.

        Parameters
        ----------
        word : str
          The word to stem

        Returns
        -------
        str
            The word with doubled endings undoubled