Skip to content

Commit

Permalink
fix #46
Browse files Browse the repository at this point in the history
  • Loading branch information
sth2018 committed Aug 30, 2018
1 parent fd30a5c commit 5931fc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions addons/fastwq/query/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ def query_flds(note, fileds=None):
return result, -1 if len(tasks) == 0 else success_num, missed_css


def cloze_deletion(text, term):
def cloze_deletion(text, cloze):
'''create cloze deletion text'''
text = text.replace('’', '\'')
result = text
offset = 0
term = _stemmer.stemWord(term).lower()
term = _stemmer.stemWord(cloze).lower()

terms = re.finditer(r"\b[\w'-]*\b", text)
tags = re.finditer(r"<[^>]+>", text)
Expand All @@ -283,7 +283,12 @@ def cloze_deletion(text, term):
continue
word = text[s:e]
if _stemmer.stemWord(word).lower() == term:
result = result[:s+offset] + "{{c1::" + word + "}}" + result[e+offset:]
l = len(cloze)
w = word
if w[:l].lower() == cloze.lower():
e = s + l
w = word[:l]
result = result[:s+offset] + "{{c1::" + w + "}}" + result[e+offset:]
offset += 8
return result

Expand Down
11 changes: 8 additions & 3 deletions addons21/fastwq/query/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ def query_flds(note, fileds=None):
return result, -1 if len(tasks) == 0 else success_num, missed_css


def cloze_deletion(text, term):
def cloze_deletion(text, cloze):
'''create cloze deletion text'''
text = text.replace('’', '\'')
result = text
offset = 0
term = _stemmer.stemWord(term).lower()
term = _stemmer.stemWord(cloze).lower()

terms = re.finditer(r"\b[\w'-]*\b", text)
tags = re.finditer(r"<[^>]+>", text)
Expand All @@ -284,7 +284,12 @@ def cloze_deletion(text, term):
continue
word = text[s:e]
if _stemmer.stemWord(word).lower() == term:
result = result[:s+offset] + "{{c1::" + word + "}}" + result[e+offset:]
l = len(cloze)
w = word
if w[:l].lower() == cloze.lower():
e = s + l
w = word[:l]
result = result[:s+offset] + "{{c1::" + w + "}}" + result[e+offset:]
offset += 8
return result

Expand Down

0 comments on commit 5931fc6

Please sign in to comment.