MCPcopy Create free account
hub / github.com/SooLab/CGFormer / _is_punctuation

Function _is_punctuation

bert/tokenization_utils.py:71–83  ·  view source on GitHub ↗

Checks whether `chars` is a punctuation character.

(char)

Source from the content-addressed store, hash-verified

69
70
71def _is_punctuation(char):
72 """Checks whether `chars` is a punctuation character."""
73 cp = ord(char)
74 # We treat all non-letter/number ASCII as punctuation.
75 # Characters such as "^", "$", and "`" are not in the Unicode
76 # Punctuation class but we treat them as punctuation anyways, for
77 # consistency.
78 if (cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or (cp >= 91 and cp <= 96) or (cp >= 123 and cp <= 126):
79 return True
80 cat = unicodedata.category(char)
81 if cat.startswith("P"):
82 return True
83 return False
84
85
86def _is_end_of_word(text):

Callers 3

_run_split_on_puncMethod · 0.85
_is_end_of_wordFunction · 0.85
_is_start_of_wordFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected