Skip to content

Commit 4c576ec

Browse files
committed
Fixing a regex
1 parent 779477a commit 4c576ec

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Recogniser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,12 @@ def anonymise_uncached(user_input, anonymise_names, anonymise_numbers, ner_model
608608
NER = spacy.load(ner_model) # TODO: config setting
609609

610610

611+
# try:
611612
entities = NER(user_input)
613+
# except ValueError as ex: # for some content, NER fails with message like "ValueError: Shape mismatch for blis.gemm: (1, 0), (768, 49)"
614+
# result = "NER error" # TODO: make the error message configurable
615+
# return result
616+
612617
letters = string.ascii_uppercase if not use_only_numeric_replacements else ""
613618

614619
next_available_replacement_letter_index = 0
@@ -631,7 +636,7 @@ def anonymise_uncached(user_input, anonymise_names, anonymise_numbers, ner_model
631636
# detect any pre-existing anonymous entities like Person A, Person B in the input text and reserve these letters in the dict so that they are not reused
632637

633638
# TODO: match also strings like "Person 123"
634-
re_matches = re.findall(r"(^|\s)(" + active_replacements + ")(\s+)([" + re.escape(letters) + "]|[0-9]+)(\s|:|$)", user_input) # NB! capture also numbers starting with 0 so that for example number 09 still ends up reserving number 9.
639+
re_matches = re.findall(r"(^|\s)(" + active_replacements + r")(\s+)([" + re.escape(letters) + r"]|[0-9]+)(\s|:|$)", user_input) # NB! capture also numbers starting with 0 so that for example number 09 still ends up reserving number 9.
635640

636641
for re_match in re_matches:
637642

0 commit comments

Comments
 (0)