mirror of
https://github.com/qurator-spk/dinglehopper.git
synced 2025-06-07 19:05:13 +02:00
ADD os path join and unique hashname
This commit is contained in:
parent
eb70510271
commit
4ae2425e5a
2 changed files with 7 additions and 6 deletions
|
@ -44,13 +44,13 @@ def gen_diff_report(gt_things, ocr_things, css_prefix, joiner, none, align):
|
||||||
|
|
||||||
def delete_tempcache():
|
def delete_tempcache():
|
||||||
# Delete all tempfiles and the directory (if empty)
|
# Delete all tempfiles and the directory (if empty)
|
||||||
tempdir = tempfile.gettempdir() + "/dinglehopper/"
|
tempdir = os.path.join(tempfile.gettempdir(), "dinglehopper/")
|
||||||
if os.path.exists(tempdir):
|
if os.path.exists(tempdir):
|
||||||
tempfiles = glob.glob(tempdir+"*.np*")
|
tempfiles = glob.glob(tempdir+"*.np*")
|
||||||
for tempfilename in tempfiles:
|
for tempfilename in tempfiles:
|
||||||
os.remove(tempfilename)
|
os.remove(tempfilename)
|
||||||
if not os.listdir(tempdir):
|
if not os.listdir(tempdir):
|
||||||
shutil.rmtree(os.path.normpath(tempdir))
|
shutil.rmtree(tempdir)
|
||||||
|
|
||||||
|
|
||||||
def process(gt, ocr, report_prefix):
|
def process(gt, ocr, report_prefix):
|
||||||
|
|
|
@ -23,11 +23,12 @@ def levenshtein_matrix(seq1, seq2, tempcache=True):
|
||||||
strings, e.g. lists of grapheme clusters or lists of word strings.
|
strings, e.g. lists of grapheme clusters or lists of word strings.
|
||||||
"""
|
"""
|
||||||
if tempcache:
|
if tempcache:
|
||||||
hashname = hashlib.sha1(("".join(seq1) + "".join(seq2)).encode("utf-8")).hexdigest()
|
hashseq1 = hashlib.sha1(("؟".join(seq1)).encode("utf-8")).hexdigest()
|
||||||
tempdir = os.path.normpath(tempfile.gettempdir() + "/dinglehopper/")
|
hashseq2 = hashlib.sha1(("؟".join(seq2)).encode("utf-8")).hexdigest()
|
||||||
|
tempdir = os.path.join(tempfile.gettempdir(), "dinglehopper/")
|
||||||
if not os.path.exists(tempdir):
|
if not os.path.exists(tempdir):
|
||||||
os.makedirs(tempdir + "/dinglehopper/")
|
os.makedirs(tempdir)
|
||||||
tempfilename = os.path.normpath(tempdir + "/" + hashname + ".npy")
|
tempfilename = os.path.join(tempdir, hashseq1 + "." + hashseq2 + ".npy")
|
||||||
if os.path.exists(tempfilename):
|
if os.path.exists(tempfilename):
|
||||||
return np.load(tempfilename)
|
return np.load(tempfilename)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue