From 0a8dfb2cb16c1f02face1c22c3c9b40e6b22b371 Mon Sep 17 00:00:00 2001 From: Alex Alvarado Date: Mon, 22 Jun 2020 05:19:16 -0500 Subject: [PATCH 1/4] Use correct path (non-cwd) to homographs.json for library --- homograph/homograph.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/homograph/homograph.py b/homograph/homograph.py index 788ea2e..03a2cd7 100644 --- a/homograph/homograph.py +++ b/homograph/homograph.py @@ -1,20 +1,21 @@ import json import string +import pathlib -# The simchar data from ShamFinder could be structured -# waaay more efficiently & less redundantly +libdir = pathlib.Path(__file__).parent.absolute() +hgdb_file = open(str(libdir) + '/homographs.json') hgdb_file = open('homographs.json') hgdb = json.load(hgdb_file) hgdb_file.close # Checks whether two individual characters are equivalent -def homoglyphic(letter1, letter2): +def is_homoglyph(letter1, letter2): if letter1 == letter2: return True return letter2 in [entry['char'] for entry in hgdb[letter1]['similar_char']] -def homographic(domain1, domain2): +def is_homograph(domain1, domain2): """ Determine whether two domains are homographic (visually equivalent or nearly so) """ @@ -26,7 +27,7 @@ def homographic(domain1, domain2): for letter1, letter2 in zip(domain1, domain2): - if not homoglyphic(letter1, letter2): + if not is_homoglyph(letter1, letter2): return False return True From a93ebf406501d0eacef17e25ef4f026bb552a3f0 Mon Sep 17 00:00:00 2001 From: Alex Alvarado Date: Mon, 22 Jun 2020 05:26:18 -0500 Subject: [PATCH 2/4] forgot to delete old line --- homograph/homograph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homograph/homograph.py b/homograph/homograph.py index 03a2cd7..c1a4c55 100644 --- a/homograph/homograph.py +++ b/homograph/homograph.py @@ -4,7 +4,6 @@ libdir = pathlib.Path(__file__).parent.absolute() hgdb_file = open(str(libdir) + '/homographs.json') -hgdb_file = open('homographs.json') hgdb = json.load(hgdb_file) hgdb_file.close From 20353e1cbfcd9b01770af8076fcf708aaf4b41f1 Mon Sep 17 00:00:00 2001 From: Alex Alvarado Date: Mon, 22 Jun 2020 05:27:33 -0500 Subject: [PATCH 3/4] rename functions in __init__.py to match changes --- homograph/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homograph/__init__.py b/homograph/__init__.py index 6471e89..d7de5cb 100644 --- a/homograph/__init__.py +++ b/homograph/__init__.py @@ -1,3 +1,3 @@ -from homograph.homograph import homographic -from homograph.homograph import homographs +from homograph.homograph import is_homoglyph +from homograph.homograph import is_homograph from homograph.homograph import homoglyphs From 0425728787a10198fcbc66ddb8040758a97e31f6 Mon Sep 17 00:00:00 2001 From: Alex Alvarado Date: Mon, 22 Jun 2020 05:28:22 -0500 Subject: [PATCH 4/4] export homographs() function --- homograph/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homograph/__init__.py b/homograph/__init__.py index d7de5cb..9533503 100644 --- a/homograph/__init__.py +++ b/homograph/__init__.py @@ -1,3 +1,4 @@ from homograph.homograph import is_homoglyph from homograph.homograph import is_homograph from homograph.homograph import homoglyphs +from homograph.homograph import homographs