-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
e5fd42e
commit 9bd595a
Showing
30 changed files
with
196 additions
and
79 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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
[build-system] | ||
requires = [ | ||
"setuptools>=42", | ||
"wheel" | ||
"wheel", | ||
"numpy", | ||
"tqdm", | ||
"opencv-python", | ||
] | ||
build-backend = "setuptools.build_meta" |
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,33 @@ | ||
import setuptools | ||
|
||
#with open("README.md", "r", encoding="utf-8") as fh: | ||
# long_description = fh.read() | ||
|
||
from unittest import TestLoader | ||
def my_test_suite(): | ||
test_loader = TestLoader() | ||
test_suite = test_loader.discover('tests', pattern='test_*.py') | ||
return test_suite | ||
if(__name__=='__main__'): | ||
setuptools.setup( | ||
name="pyradix-stevenewald", | ||
version="0.0.1", | ||
author="Steven Ewald", | ||
author_email="[email protected]", | ||
description="Python implementation of Radix Tree: memory and speed optimized language detection", | ||
long_description="", | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/stevenewald/pyradix", | ||
project_urls={ | ||
"Bug Tracker": "https://github.com/stevenewald/pyradix/issues", | ||
}, | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
], | ||
package_dir={"": "src"}, | ||
packages=setuptools.find_packages(where="src"), | ||
python_requires=">=3.6", | ||
test_suite='setup.my_test_suite', | ||
) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,4 +1,4 @@ | ||
import tree_utils as tu | ||
import pyradix.tree_utils as tu | ||
|
||
def optimize_tree(tree): | ||
anyReduxed = False | ||
|
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
6 changes: 4 additions & 2 deletions
6
src/py-radix/wordcheck_utils.py → src/pyradix/wordcheck_utils.py
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
File renamed without changes.
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,18 @@ | ||
Metadata-Version: 2.1 | ||
Name: pyradix-stevenewald | ||
Version: 0.0.1 | ||
Summary: Python implementation of Radix Tree: memory and speed optimized language detection | ||
Home-page: https://github.com/stevenewald/pyradix | ||
Author: Steven Ewald | ||
Author-email: [email protected] | ||
License: UNKNOWN | ||
Project-URL: Bug Tracker, https://github.com/stevenewald/pyradix/issues | ||
Platform: UNKNOWN | ||
Classifier: Programming Language :: Python :: 3 | ||
Classifier: License :: OSI Approved :: MIT License | ||
Classifier: Operating System :: OS Independent | ||
Requires-Python: >=3.6 | ||
Description-Content-Type: text/markdown | ||
|
||
UNKNOWN | ||
|
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,12 @@ | ||
pyproject.toml | ||
setup.py | ||
src/pyradix/__init__.py | ||
src/pyradix/image_utils.py | ||
src/pyradix/radix_utils.py | ||
src/pyradix/tree_utils.py | ||
src/pyradix/wordcheck_utils.py | ||
src/pyradix/wordgame_radix_footage.py | ||
src/pyradix_stevenewald.egg-info/PKG-INFO | ||
src/pyradix_stevenewald.egg-info/SOURCES.txt | ||
src/pyradix_stevenewald.egg-info/dependency_links.txt | ||
src/pyradix_stevenewald.egg-info/top_level.txt |
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 @@ | ||
|
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 @@ | ||
pyradix |
Binary file not shown.
Binary file not shown.
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,29 @@ | ||
import unittest | ||
import time | ||
import pyradix | ||
from tqdm import tqdm | ||
class testUseCase(unittest.TestCase): | ||
def test_usecase1(self): | ||
dict1 = pyradix.get_dict("C:/Users/steve/Desktop/wordgame_nongit/Dictionaries/english_large.txt") | ||
with tqdm(total=2) as pbar: | ||
pbar.set_description("Loading test trees") | ||
pbar.update(1) | ||
radix = pyradix.words_to_tree(dict1) | ||
pyradix.optimize_tree(radix) | ||
pbar.update(2) | ||
pbar.close() | ||
wordlist = "abcdefghijklmnop" | ||
words = pyradix.wordPathfinding(False, radix, wordlist) | ||
words = words[len(words)-15:len(words)] | ||
self.assertGreater(len(words), 10) | ||
nonradix = pyradix.words_to_tree(dict1) | ||
wordlistx = ["testing", "gjkajkgr", "sgrlkgsjns", "egjrgjrdgk", "w2rs", "1", "", "klgksl", "test", "something", "apdpdfn"] | ||
for word in wordlistx: | ||
pyradix.add_word(nonradix, word) | ||
for word in wordlistx: | ||
val = pyradix.check_if_word(nonradix, word, False) | ||
self.assertTrue(val) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,47 +1,59 @@ | ||
topnode = tu.words_to_tree("C:/Users/steve/Desktop/wordgame_nongit/Dictionaries/english_small.txt") | ||
wordlist = "abcdefghijklmnop" | ||
triesize = str(tu.count_nodes(topnode)) | ||
startTime = time.time() | ||
pw1 = finalWords(False, wordlist) | ||
endTime = time.time() | ||
topnode = ru.optimize_tree(topnode) | ||
st2 = time.time() | ||
pw2 = finalWords(True, wordlist) | ||
et2 = time.time() | ||
nodes2 = tu.count_nodes(topnode) | ||
ext1 = ((endTime-startTime)*1000) | ||
ext2 = ((et2-st2)*1000) | ||
sizechange = abs(10000*(nodes2-int(triesize))/int(triesize)) | ||
timechange = (10000*(ext2-ext1)/ext1) | ||
print("Trie vertices: " + triesize) | ||
print("Trie execution time: " + str(round(ext1)/1000) + " seconds") | ||
print("=========================") | ||
print("Radix tree vertices: " + str(nodes2)) | ||
print("Radix tree execution time: " + str(round(ext2)/1000) + " seconds") | ||
print("=========================") | ||
print("Changes from implementing radix tree") | ||
print("Reduction in size: -" + str(round(sizechange)/100) + "%") | ||
if(timechange>0): | ||
print("Increase in execution time: +" + str(round(abs(timechange))/100) + "%") | ||
else: | ||
print("Decrease in execution time: -" + str(round(abs(timechange))/100) + "%") | ||
print("=========================") | ||
print(pw1) | ||
if(False): #only if testing words | ||
numvw = 0 | ||
for word in dict: | ||
word2 = word + "e" | ||
check1 = word2 in dict | ||
check2 = check_if_word(word2, True) | ||
if(check1 and (not check2)): | ||
print(word) | ||
elif((not check1) and check2): | ||
print(word) | ||
numvw+=1 | ||
if(numvw%1000==0): | ||
print(numvw) | ||
print("Word check done") | ||
if(not(pw1==pw2)): | ||
print("ERROR: TRIE AND RADIX TREE UNEQUAL") | ||
print(len(pw1)) | ||
print(len(pw2)) | ||
import unittest | ||
import time | ||
import pyradix | ||
from tqdm import tqdm | ||
class testWordCheck(unittest.TestCase): | ||
dict1 = pyradix.get_dict("C:/Users/steve/Desktop/wordgame_nongit/Dictionaries/english_large.txt") | ||
wordlistF = ["ttufpaepnerignss", "ponmlkjihgfedcba", "ciolmhrfefednslo", "abcdefghijklmnop"] | ||
with tqdm(total=2) as pbar: | ||
pbar.set_description("Loading test trees") | ||
nonradix = pyradix.words_to_tree(dict1) | ||
pbar.update(1) | ||
radix = pyradix.words_to_tree(dict1) | ||
pyradix.optimize_tree(radix) | ||
pbar.update(2) | ||
pbar.close() | ||
def test_testvalidity(self): | ||
self.assertGreater(len(self.dict1), 10000) | ||
def test_nonradix_word_equality(self): | ||
with tqdm(total=(len(self.dict1))) as pbar: | ||
pbar.set_description("Testing non-radix validity") | ||
for word in self.dict1: | ||
if(word==""): | ||
continue | ||
val = pyradix.check_if_word(self.nonradix, word, False) | ||
self.assertTrue(val) | ||
pbar.update(1) | ||
pbar.close() | ||
def test_radix_word_equality(self): | ||
with tqdm(total=(len(self.dict1))) as pbar: | ||
pbar.set_description("Testing radix validity") | ||
for word in self.dict1: | ||
if(word==""): | ||
continue | ||
val = pyradix.check_if_word(self.radix, word, True) | ||
self.assertTrue(val) | ||
pbar.update(1) | ||
pbar.close() | ||
def test_result_equality(self): | ||
with tqdm(total=len(self.wordlistF)) as pbar: | ||
pbar.set_description("Testing non-radix and radix equality") | ||
for wordlist in self.wordlistF: | ||
pw1 = pyradix.wordPathfinding(False, self.nonradix, wordlist) | ||
pw2 = pyradix.wordPathfinding(False, self.radix, wordlist) | ||
self.assertEqual(pw1, pw2) | ||
pbar.update(1) | ||
pbar.close() | ||
def test_trie_size(self): | ||
with tqdm(total=2) as pbar: | ||
pbar.set_description("Validating non-radix and radix size") | ||
size = pyradix.count_nodes(self.nonradix) | ||
pbar.update(1) | ||
size2 = pyradix.count_nodes(self.radix) | ||
pbar.update(1) | ||
self.assertEqual(size, 1027814) | ||
self.assertEqual(size2, 478056) | ||
pbar.close() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |