mirror of
https://github.com/allaunthefox/BioSight.git
synced 2026-08-19 00:40:34 +00:00
refactor(dna): optimize char classification and fix Unicode math symbol misclassification
- Pre-defined and unified character sets (OPERATOR_CHARS, BRACKET_CHARS, PUNCT_CHARS, WHITESPACE_CHARS). - Defined precise sets for SYMMETRY_CHARS, PERIODICITY_CHARS, CONTINUITY_CHARS, and META_MATH_CHARS. - Re-ordered specific checks to precede c.isalpha() so Unicode/Greek math letters are not misclassified as standard lower/upper alpha. Build: 3307 jobs, 0 errors (lake build)
This commit is contained in:
parent
295130c078
commit
09b9f690e0
1 changed files with 24 additions and 18 deletions
|
|
@ -35,7 +35,14 @@ CHAR_CLASSES = {
|
||||||
|
|
||||||
OPERATOR_CHARS = set("+-*/^%=<>!&|~")
|
OPERATOR_CHARS = set("+-*/^%=<>!&|~")
|
||||||
BRACKET_CHARS = set("()[]{}")
|
BRACKET_CHARS = set("()[]{}")
|
||||||
PUNCT_CHARS = set(".,;:'\"@#$\\")
|
PUNCT_CHARS = set(".,;:'\"@#$\\_")
|
||||||
|
WHITESPACE_CHARS = set(" \t\n\r")
|
||||||
|
|
||||||
|
# Unicode mathematical sets (placed at the top to prevent misclassification as standard alpha)
|
||||||
|
SYMMETRY_CHARS = set("≈≡∼")
|
||||||
|
PERIODICITY_CHARS = set("πθλ∞")
|
||||||
|
CONTINUITY_CHARS = set("→Δ∇∫")
|
||||||
|
META_MATH_CHARS = set("√∑∏∂")
|
||||||
|
|
||||||
|
|
||||||
def classify_char(c: str) -> int:
|
def classify_char(c: str) -> int:
|
||||||
|
|
@ -84,31 +91,30 @@ def classify_char(c: str) -> int:
|
||||||
>>> classify_char("©")
|
>>> classify_char("©")
|
||||||
7
|
7
|
||||||
"""
|
"""
|
||||||
|
# Check Unicode math classes first so Greek/math symbols are not misclassified as standard alpha
|
||||||
|
if c in PERIODICITY_CHARS:
|
||||||
|
return 9
|
||||||
|
if c in CONTINUITY_CHARS:
|
||||||
|
return 10
|
||||||
|
if c in SYMMETRY_CHARS:
|
||||||
|
return 8
|
||||||
|
if c in META_MATH_CHARS:
|
||||||
|
return 11
|
||||||
|
|
||||||
|
# Check standard ASCII classes
|
||||||
if c.isdigit():
|
if c.isdigit():
|
||||||
return 0
|
return 0
|
||||||
if c.isalpha():
|
if c.isalpha():
|
||||||
return 1 if c.islower() else 2
|
return 1 if c.islower() else 2
|
||||||
# Operator chars
|
if c in OPERATOR_CHARS:
|
||||||
if c in "+-*/^%=<>!&|~":
|
|
||||||
return 3
|
return 3
|
||||||
# Bracket chars
|
if c in BRACKET_CHARS:
|
||||||
if c in "()[]{}":
|
|
||||||
return 4
|
return 4
|
||||||
# Punctuation
|
if c in PUNCT_CHARS:
|
||||||
if c in ".,;:'\"@#$\\":
|
|
||||||
return 5
|
return 5
|
||||||
# Whitespace
|
if c in WHITESPACE_CHARS:
|
||||||
if c in (" ", "\t", "\n", "\r"):
|
|
||||||
return 6
|
return 6
|
||||||
# Other (General)
|
|
||||||
if c in "$\\pi\\theta\\lambda\\infty$": # Periodicity
|
|
||||||
return 9
|
|
||||||
if c in "$\\rightarrow\\Delta\\nabla\\int$": # Continuity
|
|
||||||
return 10
|
|
||||||
if c in "=$\\approx\\equiv\\sim$": # Symmetry
|
|
||||||
return 8
|
|
||||||
if c in "$\\sqrt{}\\sum\\prod\\partial$": # Meta-math
|
|
||||||
return 11
|
|
||||||
return 7
|
return 7
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue