Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
# 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 = """
# 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))