How to use the textdistance.libraries.prototype.clone function in textdistance

To help you get started, we’ve selected a few textdistance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github life4 / textdistance / run_tests.py View on Github external
import os

try:
    import unittest2 as unittest
except ImportError:
    import unittest

import textdistance
from textdistance.libraries import prototype


libraries = prototype.clone()
# CONSTRAINTS = os.getenv('WITH_CONSTRAINTS', 'yes') == 'yes'
# NUMPY = os.getenv('WITH_NUMPY', 'yes') == 'yes'
CONSTRAINTS = os.environ['WITH_CONSTRAINTS'] == 'yes'
NUMPY = os.environ['WITH_NUMPY'] == 'yes'


from tests import *  # noQA


if __name__ == '__main__':
    unittest.main()
github life4 / textdistance / textdistance / benchmark.py View on Github external
# built-in
import json
from collections import defaultdict, namedtuple
from timeit import timeit

# project
from tabulate import tabulate

# app
from .libraries import LIBRARIES_FILE, prototype


# python3 -m textdistance.benchmark


libraries = prototype.clone()
Lib = namedtuple('Lib', ['algorithm', 'library', 'function', 'time', 'presets'])


EXTERNAL_SETUP = """
from {library} import {function} as func
presets = {presets}
if presets:
    func = func(presets)
"""

INTERNAL_SETUP = """
from textdistance import {} as cls
func = cls(external=False)
"""

STMT = """
github life4 / textdistance / textdistance / algorithms / base.py View on Github external
# built-in
from collections import Counter

# app
from ..libraries import prototype
from ..utils import find_ngrams


libraries = prototype.clone()
libraries.optimize()


class Base(object):
    def __init__(self, qval=1, external=True):
        self.qval = qval
        self.external = external

    def __call__(self, *sequences):
        raise NotImplementedError

    @staticmethod
    def maximum(*sequences):
        """Get maximum possible value
        """
        return max(map(len, sequences))