Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
175 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
------- | ||
License | ||
------- | ||
It is released under the MIT license. | ||
Copyright (c) 2013 Hiroyuki Tanaka | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
""" | ||
|
||
|
||
try: | ||
from setuptools import Extension, setup | ||
except: | ||
from distutils import Extension, setup | ||
|
||
from Cython.Build import cythonize | ||
|
||
ext_modules = cythonize("editdistance/bycython.pyx") | ||
|
||
with open("README.rst") as readme_file: | ||
readme = readme_file.read() | ||
|
||
setup( | ||
name="editdistance", | ||
version="0.7.0", | ||
python_requires=">=3.6", | ||
description="Fast implementation of the edit distance(Levenshtein distance)", | ||
long_description=readme, | ||
long_description_content_type="text/x-rst", | ||
author="Hiroyuki Tanaka", | ||
author_email="aflc0x@gmail.com", | ||
url="https://www.github.com/roy-ht/editdistance", | ||
ext_modules=ext_modules, | ||
packages=["editdistance"], | ||
package_data={ | ||
"editdistance": ["__init__.pxd", "_editdistance.h", "bycython.pxd", "def.h"] | ||
}, | ||
classifiers=[ | ||
"License :: OSI Approved :: MIT License", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3 :: Only", | ||
"Programming Language :: Python :: 3.6", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# cython: language_level=3 | ||
from editdistance.bycython cimport eval | ||
from editdistance.bycython cimport eval, eval_criterion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from .bycython import eval | ||
from .bycython import eval, eval_criterion | ||
|
||
|
||
def distance(*args, **kwargs): | ||
""""An alias to eval""" | ||
return eval(*args, **kwargs) | ||
|
||
def distance_le_than(*args, **kwargs): | ||
""""An alias to eval""" | ||
return eval_criterion(*args, **kwargs) | ||
|
||
__all__ = ('eval', 'distance') | ||
__all__ = ('eval', 'distance', "eval_criterion", "distance_le_than") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# cython: language_level=3 | ||
cpdef unsigned int eval(object a, object b) except 0xffffffffffffffff | ||
cpdef bint eval_criterion(object a, object b, const unsigned int thr) except 0xffffffffffffffff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
import unittest | ||
import random | ||
|
||
|
||
class TestEditDistance(unittest.TestCase): | ||
def test_editdistance(self): | ||
import editdistance | ||
self.assertEqual(1, editdistance.eval('abc', 'aec')) | ||
|
||
|
||
def test_editdistance_criterion(self): | ||
import editdistance | ||
self.assertEqual(False, editdistance.eval_criterion('abcb', 'aeca', 1)) | ||
self.assertEqual(True, editdistance.eval_criterion('abc', 'aec', 1)) | ||
|
||
def test_dp_editdistance(self): | ||
from editdistance.bycython import eval_dp | ||
self.assertEqual(3, eval_dp('bbb', 'a')) | ||
self.assertEqual(3, eval_dp('a', 'bbb')) | ||
|
||
def test_dp_vs_default(self): | ||
for _ in range(10): | ||
import editdistance | ||
from editdistance.bycython import eval_dp | ||
seq1 = random.choices([0, 1, 2], k=random.randint(10, 50)) | ||
seq2 = random.choices([0, 1, 2], k=random.randint(10, 50)) | ||
|
||
self.assertEqual(editdistance.eval(seq1, seq2), eval_dp(seq1, seq2)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |