阅读文本 / Reading text
This paper uses synthetic samples to demonstrate the processing method. The code has been verified using examples in an isolated environment; this does not guarantee effectiveness for all real files or products. Before processing important files, please retain the original copies and verify them against the boundaries and acceptance criteria specified in the text.
The glossary contains
API
, does not mean that every word in the document containing these three letters should be replaced.
APIs
is morphological variation,
api_gateway
may be a code identifier, and Chinese terminology cannot simply follow English word boundaries. First identify candidates, then decide whether to translate—this approach is more reliable than global substitution.
Each language requires its own matching convention
This paper provides a deliberately conservative English example: an independent
API
ignores case-sensitive matching; letters, digits, and underscores are not matched when they appear consecutively. This convention is not a complete word-segmentation rule for natural language, nor does it handle plurals, genitives, or contextual disambiguation.
Test with a string that is close but should not match.
import re
def english_candidates(text, term):
if not term:
raise ValueError("empty term")
pattern = re.compile(r"(?<!\w)" + re.escape(term) + r"(?!\w)", re.IGNORECASE)
return [(m.start(), m.end(), m.group()) for m in pattern.finditer(text)]
text = "API and api; APIs, rapid, api_gateway."
found = english_candidates(text, "API")
assert [item[2] for item in found] == ["API", "api"]
assert all(text[start:end] == raw for start, end, raw in found)
assert english_candidates("api_gateway", "API") == []
assert english_candidates("APIs", "API") == []
assert english_candidates("(API)", "API")[0][2] == "API"
try:
english_candidates(text, "")
except ValueError:
pass
else:
raise AssertionError("empty glossary term accepted")
match candidate is not the replacement command
code retains its original position and text, without directly modifying the content. This approach allows reviewers to distinguish between body text, links, and code sections, and to determine whether original terms should be preserved. Candidate positions in HTML or Word must also be mapped to structural nodes; it is not sufficient to simply write back the entire concatenated string based on position.
scenario
This example selects
further strategy
independent API
as a candidate
reviewed according to the glossary and context
APIs
does not match
explicitly maintains morphological rules
api_gateway
does not match
identifiers are generally protected
Chinese term
does not claim to cover
employs Chinese-specific tokenization or rules
is case-insensitive and also has a boundary
Unicode case and linguistic conventions do not always correspond one-to-one. This paper focuses on simple English terminology and should not be generalized into a term recognizer that works correctly for all languages. Large-scale term lists must also address overlapping candidates, longest-match parsing, and version management to prevent repeated conflicts within the same paragraph.
makes the glossary a verifiable convention
OmniDoc (Product Entry)
’s official website introduces the terminology list feature. During evaluation, one can select de-identified samples containing main text, code identifiers, and morphological variations, and compare them with the translation to determine whether the terms are used in the correct context. The value of a terminology list lies not in mechanically replacing more words, but in ensuring that the team’s lexical conventions remain more consistent.
Reference:
Python re
。
- 1 -
Updated 2026-10-08