Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Better cloze cousins detection #3

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,20 @@ def _similarityTest(a: str, b: str, percent_match: float) -> bool:
>>> _similarityTest('hello', 'hello this is a test', 0.5)
False
"""
#// removing the extra parts in cloze deletions to maximize accuracy
#// turns 'this is a {{c1::cloze::whaaaat??}} {{c2::test:what did you say}}'
# into this is a cloze test
texta = a.replace('}}', '::a}}')
texta2 = re.sub('{{.+?::', '', texta)
texta3 = re.sub('::.+?}}', '', texta2)
textb = b.replace('}}', '::a}}')
textb2 = re.sub('{{.+?::', '', textb)
textb3 = re.sub('::.+?}}', '', textb2)
# don't accidentally run on empty cards. rather be safe
if max(len(a), len(b)) < 4:
return False

return difflib.SequenceMatcher(None, a, b).ratio() > percent_match
return difflib.SequenceMatcher(None, texta3.lower(), textb3.lower()).ratio() > percent_match


def _contained_by(a: str, b: str, threshold: float):
Expand Down