sinonym 0.6.2__tar.gz → 0.6.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sinonym-0.6.2 → sinonym-0.6.3}/PKG-INFO +1 -1
- {sinonym-0.6.2 → sinonym-0.6.3}/pyproject.toml +2 -1
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/name_punctuation.py +194 -17
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/person_name_normalization.py +3 -2
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/text_processing/text_preprocessor.py +2 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_s2and_review_regressions.py +200 -2
- {sinonym-0.6.2 → sinonym-0.6.3}/.gitignore +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/LICENSE +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/README.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/docs/batch_processing.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/docs/canonical_name_evaluation.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/docs/scalar_source_surname_repartition_evaluation.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/docs/timo.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/docs/unicode_hyphen_policy_review.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/README.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/build_east_asian_name_lexicons.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/check_test_status.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/data/reviewed_japanese_possible_surnames.csv +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/generate_name_statistics.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/generate_surname_romanizations.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/name_order_routing_rules.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/train_ml_classifier_for_chinese_vs_japanese.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/scripts/verify_multiprocess.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/__init__.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/chinese_names_data.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/coretypes/__init__.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/coretypes/config.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/coretypes/results.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/coretypes/routing_resolution.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/COMPOUND_SURNAMES.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/EAST_ASIAN_NAME_LEXICONS.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/README.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/acl_2025_authors.txt +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/chinese_japanese_classifier.skops +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/compound_surnames.csv.gz +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/east_asian_roman_lexicons.json.gz +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/familyname_orcid.csv +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/given_position.csv +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/givenname_orcid.csv +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/japanese_native_lexicons.json.gz +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/model_features.json +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/name_order_routing/README.md +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/name_order_routing/pp_abstain_labels.jsonl +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/name_order_routing/pp_vys_abstain_labels.jsonl +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/surname_first_words.csv.gz +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/surname_romanizations.csv +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/token_role_prior.csv.gz +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/data/two_token_order_prior.csv.gz +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/detector.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/ml_fast_scorer.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/ml_flag_data.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/ml_model_components.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/patterns/__init__.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/patterns/compiled_patterns.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/patterns/regex_builders.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/pipeline/__init__.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/pipeline/name_order_routing.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/resources.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/__init__.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/batch_analysis.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/cache.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/compound_surnames.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/east_asian_name_order.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/ethnicity.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/formatting.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/initialization.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/name_lookup.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/non_person.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/normalization.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/order_metadata.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/order_prior.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/parsing.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/process_pool.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/slavic_initials.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/surname_first_words.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/services/token_order_prior.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/text_processing/__init__.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/text_processing/compound_detector.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/text_processing/text_normalizer.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/timo/__init__.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/timo/_resolution.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/timo/config.yaml +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/timo/integration_test.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/timo/interface.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/utils/__init__.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/utils/string_manipulation.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/sinonym/utils/thread_cache.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/_case_assertions.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/_korean_atomic_cases.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/conftest.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/data/hangul_name_order_gold.json +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/data/manufactured_initials_cohorts.json +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/data/reviewed_korean_source_assignments.tsv +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/data/reviewed_source_pattern_assignments.jsonl +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/data/spaced_cjk_name_order_gold.json +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/data/timo_parity/manifest.json +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/data/timo_parity/requests.jsonl +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/data/vietnamese_name_order_gold.json +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_acl.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_all_chinese_inputs.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_basic_chinese_names.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_batch.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_batch_crash_guard.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_batch_scalar_parity.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_bug_report_fixes.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_canonical_name_integration.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_canonical_results.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_check_test_status.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_chinese_classification_evidence_gates.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_chinese_compound_surname_provenance.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_cjk_component_leaks.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_compound_names.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_compound_surname_formats.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_config_immutability.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_detector_initialization_and_validation.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_east_asian_lexicon_builder.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_east_asian_name_order.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_fixability_proposal_fixes.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_han_surname_readings.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_hangul_name_order_gold.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_initial_policy_chinese.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_initial_policy_non_chinese.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_initial_policy_routing.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_manufactured_initials.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_middle_names.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_misc.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_mixed_production_cases.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_mixed_scripts.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_ml_fast_scorer.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_ml_japanese_detection.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_multiprocess_pool.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_name_formatting.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_name_order_routing_label_fixtures.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_name_order_routing_rules.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_name_statistics_data.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_non_chinese_exact_source_fixes.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_non_chinese_rejection.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_package_metadata.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_performance.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_person_name_normalization.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_pr29_pr30_paper_context_repairs.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_reference_scripts.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_regional_variants.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_regression_proposals.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_review_finding_regressions.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_reviewed_non_person_patterns.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_reviewed_structured_source_repairs.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_scalar_clean_source_surname_repartition.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_spaced_cjk_name_order_gold.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_strict_spaced_japanese_routing.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_surname_romanizations.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_timo_contract.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_timo_interface.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_timo_parity_fixture.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_timo_performance.py +0 -0
- {sinonym-0.6.2 → sinonym-0.6.3}/tests/test_vietnamese_name_order_gold.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sinonym"
|
|
7
|
-
version = "0.6.
|
|
7
|
+
version = "0.6.3"
|
|
8
8
|
description = "Chinese Name Detection and Normalization Module"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -106,6 +106,7 @@ ignore = ["S101", "T201"] # Allow assert statements and print statements
|
|
|
106
106
|
"sinonym/chinese_names_data.py" = ["ERA001"]
|
|
107
107
|
"sinonym/coretypes/config.py" = ["E501", "RUF001", "RUF003"]
|
|
108
108
|
"sinonym/ml_fast_scorer.py" = ["PLR0913", "PLR2004"]
|
|
109
|
+
"sinonym/name_punctuation.py" = ["C901", "PLR0911", "PLR0912", "PLR0915", "RUF003"]
|
|
109
110
|
"sinonym/ml_model_components.py" = ["ARG002", "N803", "PLR2004", "UP038"]
|
|
110
111
|
"sinonym/patterns/regex_builders.py" = ["N806", "PLR2004", "RUF001"]
|
|
111
112
|
"sinonym/resources.py" = ["PLC0415", "TC003"]
|
|
@@ -216,20 +216,29 @@ def fold_spaced_transliteration_apostrophes(value: str) -> str:
|
|
|
216
216
|
return _DUTCH_T_SPACING_RE.sub(" 't", value)
|
|
217
217
|
|
|
218
218
|
|
|
219
|
+
# spacing diacritics; ASCII ^ and backtick are not marks here (a caret between a vowel and a consonant is handled
|
|
220
|
+
# on its own in ``_reattach_in_token``)
|
|
219
221
|
_SPACING_TO_COMBINING = {
|
|
220
|
-
"\u00a8": "\u0308", "\u02da": "\u030a", "\u00b4": "\u0301",
|
|
222
|
+
"\u00a8": "\u0308", "\u02da": "\u030a", "\u00b4": "\u0301",
|
|
221
223
|
"\u02dc": "\u0303", "\u00b8": "\u0327", "\u02c7": "\u030c", "\u00af": "\u0304", "\u02d8": "\u0306",
|
|
222
|
-
"\u02dd": "\u030b", "\u02d9": "\u0307",
|
|
224
|
+
"\u02dd": "\u030b", "\u02d9": "\u0307", "\u02db": "\u0328",
|
|
223
225
|
}
|
|
224
|
-
_APOSTROPHE_LIKE_MARKS = frozenset({"\u00b4"
|
|
226
|
+
_APOSTROPHE_LIKE_MARKS = frozenset({"\u00b4"})
|
|
225
227
|
_COMBINING_TO_SPACING = {combining: spacing for spacing, combining in _SPACING_TO_COMBINING.items()}
|
|
226
|
-
|
|
228
|
+
# a combining mark right after a letter or another mark is ordinary NFD text (``Iba\u0301n\u0303ez``, ``İ\u0307\u0307``) and
|
|
229
|
+
# is never moved; only spacing marks and combining marks that follow no letter are detached
|
|
230
|
+
_DETACHED_MARK = "(?:[" + "".join(_SPACING_TO_COMBINING) + "]|(?<![^\\W\\d_]|[\\u0300-\\u036f])[\\u0300-\\u036f])"
|
|
231
|
+
_ANY_DETACHED_MARK_RE = re.compile(_DETACHED_MARK)
|
|
227
232
|
_TOKEN_MARK_RE = re.compile(
|
|
228
|
-
"(?P<prev>[^\\W\\d_])?(?P<mark>
|
|
233
|
+
"(?P<prev>[^\\W\\d_])?(?P<mark>" + _DETACHED_MARK + ")(?P<next>[^\\W\\d_])?",
|
|
229
234
|
re.UNICODE,
|
|
230
235
|
)
|
|
231
236
|
|
|
232
237
|
|
|
238
|
+
def _base(ch: str) -> str:
|
|
239
|
+
return unicodedata.normalize("NFD", ch)[:1] if ch else ""
|
|
240
|
+
|
|
241
|
+
|
|
233
242
|
def _compose(base: str, combining: str) -> str | None:
|
|
234
243
|
if not base:
|
|
235
244
|
return None
|
|
@@ -268,8 +277,53 @@ def _attach_caron(prev: str, nxt: str, *, mark_before_letter: bool = False) -> s
|
|
|
268
277
|
return None
|
|
269
278
|
|
|
270
279
|
|
|
280
|
+
# letters and clusters that mark a Polish word (Turkish and Romanian names, the other cedilla users, have none):
|
|
281
|
+
# a cedilla after a or e there is the ogonek of ą ę (ie¸ is ę in 15 of 15 corpus words, a¸/e¸ elsewhere 73 of 276)
|
|
282
|
+
# (case-sensitive and anchored, so ``Ta¸skıran`` with its Turkish ı does not look Polish)
|
|
283
|
+
_POLISH_WORD_RE = re.compile("[łśżźćńŁŚŻŹĆŃwW]|[cC]z|[sS]z|[rR]z|[sScC]k[ia]$|ie\u00b8|i\u02dbe")
|
|
284
|
+
_ROMANIAN_WORD_RE = re.compile("escu$|eanu$|[şţșțâî]|^Dr[aeiou]\u02d8?g", re.IGNORECASE)
|
|
285
|
+
# a Czech or Slovak word: a caron letter or a detached caron, or a -sky/-cky ending (ý is extracted as y´ there)
|
|
286
|
+
_CZECH_WORD_RE = re.compile("[řšČčžěůďťňŘŠŽĚŮĎŤŇ]|\u02c7|[sScC][kK][yY]\u00b4$")
|
|
287
|
+
_MAX_REPAIRED_TOKEN = 200
|
|
288
|
+
_STRONG_POLISH_WORD_RE = re.compile("[łśżźćńŁŚŻŹĆŃ]|[cC]z|[sS]z|[rR]z|[sScC]k[ia]$|ie\u00b8|i\u02dbe")
|
|
289
|
+
_CARET_CIRCUMFLEX_RE = re.compile("([aeiouAEIOU])\\^(?=[b-df-hj-np-tv-z])")
|
|
290
|
+
_MARKUP_BEFORE_MARK_RE = re.compile("[" + "".join(sorted(INVISIBLE_MARKUP)) + "]+(?=[\\u0300-\\u036f])")
|
|
291
|
+
# à and  before a spacing mark are UTF-8 read as Latin-1 (``Antônio``, ``Søren``); such a word is decoded when it
|
|
292
|
+
# round-trips exactly
|
|
293
|
+
_MOJIBAKE_BEFORE_MARK_RE = re.compile("[ÃÂ][" + "".join(_SPACING_TO_COMBINING) + "]")
|
|
294
|
+
# Ä and Å before a spacing mark are other mojibake (cp1250 ``Ä˝ubica`` for Ľubica): such a word is left as written
|
|
295
|
+
_OTHER_MOJIBAKE_BEFORE_MARK_RE = re.compile("[ÄÅ][" + "".join(_SPACING_TO_COMBINING) + "]")
|
|
296
|
+
# a mid-word ´ after a letter with one of these marks is the next letter's acute (``Dvoř´ak``, ``Sagü´es``, ``Szczȩ´sniak``);
|
|
297
|
+
# after an acute, macron, tilde, circumflex or breve it is an apostrophe (``Sā´id``, ``Marí´a``, ``Iñ´aki``, ``Quô´c``)
|
|
298
|
+
_ACUTE_AFTER_MARKS = frozenset({"\u030c", "\u0308", "\u0327", "\u0328"})
|
|
299
|
+
|
|
300
|
+
|
|
271
301
|
def _reattach_in_token(token: str) -> str:
|
|
272
|
-
"""
|
|
302
|
+
"""Repair the detached marks of one token; a mark that composes with neither neighbour leaves the token as it was."""
|
|
303
|
+
if "`" in token:
|
|
304
|
+
return token # a backtick there makes ´ an apostrophe variant (``Le Bloc´`'h``), never an accent
|
|
305
|
+
if "^" in token:
|
|
306
|
+
# a caret between a vowel and a consonant is that vowel's circumflex (``Lemai^tre`` → ``Lemaître``, ``Jéro^me``);
|
|
307
|
+
# between two vowels it is ambiguous (``Beno^it`` is Benoît), and elsewhere (``Smith^1``, ``^hiyi``,
|
|
308
|
+
# ``Gomes^Neto``) it is a separator or footnote, so any other caret leaves the word alone
|
|
309
|
+
fixed = _CARET_CIRCUMFLEX_RE.sub(lambda m: unicodedata.normalize("NFC", m.group(1) + "\u0302"), token)
|
|
310
|
+
return token if "^" in fixed else _reattach_in_token(fixed)
|
|
311
|
+
if (len(token) > 1 and token[0] == token[-1] == "\u00b4") or "\u00b4\u00b4" in token:
|
|
312
|
+
return token # ``´Iñaki´`` and ``Ángel´´`` use ´ as quote marks, not accents
|
|
313
|
+
if _MOJIBAKE_BEFORE_MARK_RE.search(token):
|
|
314
|
+
# UTF-8 read as Latin-1 (``Søren``, ``Antônio``): decode it only when that round-trips exactly, else leave it
|
|
315
|
+
try:
|
|
316
|
+
decoded = token.encode("latin-1").decode("utf-8")
|
|
317
|
+
except UnicodeError:
|
|
318
|
+
return token
|
|
319
|
+
return _reattach_in_token(decoded) # ``STOJANOVIC´`` → ``STOJANOVIC´`` → ``STOJANOVIĆ``
|
|
320
|
+
if _OTHER_MOJIBAKE_BEFORE_MARK_RE.search(token):
|
|
321
|
+
return token
|
|
322
|
+
if len(token) > _MAX_REPAIRED_TOKEN:
|
|
323
|
+
return token # no name word is this long, and the per-mark repair is quadratic in the token length
|
|
324
|
+
original = token
|
|
325
|
+
# a spacing mark doubled by the extractor is one mark (``Mu¨¨ller``); a doubled ´ is a quote mark (``Ángel´´``)
|
|
326
|
+
token = re.sub("([" + "".join(m for m in _SPACING_TO_COMBINING if m != "\u00b4") + "])\\1+", "\\1", token)
|
|
273
327
|
failed = False
|
|
274
328
|
caron_before = 0
|
|
275
329
|
for m in _TOKEN_MARK_RE.finditer(token):
|
|
@@ -283,29 +337,148 @@ def _reattach_in_token(token: str) -> str:
|
|
|
283
337
|
failed = True
|
|
284
338
|
return match.group(0)
|
|
285
339
|
|
|
340
|
+
current = token
|
|
341
|
+
all_caps = token.upper() == token
|
|
342
|
+
polish_word = _POLISH_WORD_RE.search(token) is not None
|
|
343
|
+
strong_polish_word = _STRONG_POLISH_WORD_RE.search(token) is not None
|
|
344
|
+
czech_word = _CZECH_WORD_RE.search(token) is not None
|
|
345
|
+
romanian_word = _ROMANIAN_WORD_RE.search(token) is not None
|
|
346
|
+
|
|
286
347
|
def fix(match):
|
|
287
348
|
nonlocal failed
|
|
288
349
|
prev, nxt, mark = match.group("prev") or "", match.group("next") or "", match.group("mark")
|
|
289
350
|
combining = _SPACING_TO_COMBINING.get(mark, mark)
|
|
351
|
+
start = match.start("mark")
|
|
352
|
+
if mark in _APOSTROPHE_LIKE_MARKS and not prev and nxt and start and unicodedata.combining(current[start - 1]):
|
|
353
|
+
# NFD text: the letter before ´ carries combining marks of its own (``Mari\u0301´a``); judge those marks as below
|
|
354
|
+
base_at = start
|
|
355
|
+
while base_at and unicodedata.combining(current[base_at - 1]):
|
|
356
|
+
base_at -= 1
|
|
357
|
+
if base_at and set(current[base_at:start]) & _ACUTE_AFTER_MARKS and (nxt in "aeiou" or nxt in "cnsz"):
|
|
358
|
+
out = _compose(nxt, combining)
|
|
359
|
+
if out is not None:
|
|
360
|
+
return out
|
|
361
|
+
return match.group(0)
|
|
290
362
|
if mark in _APOSTROPHE_LIKE_MARKS and prev and nxt:
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
363
|
+
# a mid-word ´ is an acute or an apostrophe (José, Maz'ya, Ken'ichi, Ćosić), so it is left as written, except
|
|
364
|
+
# right after a letter that already carries a mark, where it is the next vowel's acute (``Dvoř´ak``, ``Sagü´es``)
|
|
365
|
+
vowel_next = nxt in "aeiou" or (all_caps and nxt in "AEIOU")
|
|
366
|
+
prev_marks = set(unicodedata.normalize("NFD", prev)[1:])
|
|
367
|
+
# a letter takes one accent, so after a marked vowel the acute is the consonant's (``Szczȩ´sniak``, ``ˇS´CETA``)
|
|
368
|
+
consonant_next = nxt in "cnsz" or (all_caps and nxt in "CNSZ")
|
|
369
|
+
if prev_marks & _ACUTE_AFTER_MARKS and (vowel_next or consonant_next):
|
|
370
|
+
out = _compose(nxt, combining)
|
|
371
|
+
if out is not None:
|
|
372
|
+
return prev + out
|
|
373
|
+
return match.group(0)
|
|
374
|
+
prev_base = _base(prev).lower()
|
|
375
|
+
polish_ending = current.lower().endswith(("ien\u00b4", "yn\u00b4")) # Bień, Kwiecień, Horyń
|
|
376
|
+
# a bare w is too weak a sign here (``Brown´``, ``Owen´``)
|
|
377
|
+
polish_letter = (prev_base in "nsz" and strong_polish_word) or (prev_base == "n" and polish_ending)
|
|
378
|
+
czech_y = prev_base == "y" and czech_word
|
|
379
|
+
if mark == "\u00b4" and not nxt and prev_base not in "aeiouc" and not polish_letter and not czech_y:
|
|
380
|
+
# a word-final ´ is an accent only on a vowel or c (``Jose´``, ``Ružic´``), on y in a Czech or Slovak word
|
|
381
|
+
# (``Sechovsky´``), or on n/s/z in a Polish word (``Grzes´``); otherwise it is an elision, a soft sign or stray
|
|
382
|
+
# left as written (``Dell´``, ``Igor´``, ``Vasyl´``, ``Fernandes´``, ``Nancy´``, ``Istvan´``)
|
|
383
|
+
return match.group(0)
|
|
384
|
+
after_next = current[match.end() : match.end() + 1]
|
|
385
|
+
polish_s_cluster = nxt in "sS" and after_next in "wlrcmnpWLRCMNP" # Św Śl Śr Śc (``´Swia¸tek``, ``´Sliwa``)
|
|
386
|
+
if mark == "\u00b4" and not prev and nxt and not (
|
|
387
|
+
nxt in "aeiouAEIOU" or (nxt in "cnszCNSZ" and polish_word) or polish_s_cluster
|
|
388
|
+
):
|
|
389
|
+
# a word-initial ´ goes on a vowel, on ś before a consonant, or on ć ń ś ź in a Polish word; before any other
|
|
390
|
+
# consonant it is stray (``´Pedraza``, ``´Castro``, ``´Silva``)
|
|
391
|
+
return match.group(0)
|
|
392
|
+
if mark == combining and start and current[start - 1] not in "-\u2010":
|
|
393
|
+
# a combining mark after any other mark (``Mu\u1dc4\u0301ller``) or after punctuation (``O.\u0301scar``) is not a
|
|
394
|
+
# detached accent we can place; only one at a word start or after a hyphen is
|
|
295
395
|
return match.group(0)
|
|
296
396
|
if combining == "\u030c":
|
|
297
397
|
return _attach_caron(prev, nxt, mark_before_letter=caron_before > 0) or _fail(match)
|
|
298
|
-
|
|
299
|
-
|
|
398
|
+
# a tilde next to n is the Spanish ñ on either side (``Ya˜nez`` → ``Yañez``, ``Mun˜oz`` → ``Muñoz``): of the
|
|
399
|
+
# corpus's 1,795 such mentions only ``N˜ao-Linear`` (not a name) wanted ã; Portuguese ã/õ sit between vowels
|
|
400
|
+
tilde = combining == "\u0303"
|
|
401
|
+
after = current[match.end() : match.end() + 1].lower()
|
|
402
|
+
dot = combining == "\u0307"
|
|
403
|
+
# next to a lowercase i, a z or e on the other side takes the dot (``Gi˙zewska``); a capital I is always İ (``I˙zzet``)
|
|
404
|
+
dot_base_other = ((nxt and nxt in "zeZE") or (prev and prev in "zeZE")) and polish_word # Turkish Fi˙li˙z keeps i's dot
|
|
405
|
+
capital_i = prev == "I" or nxt == "I"
|
|
406
|
+
if dot and ((prev and prev in "iI") or (nxt and nxt in "iI")) and (capital_i or not dot_base_other):
|
|
407
|
+
# a dot next to i is the i's own dot: dropped on a lowercase i (``Meli˙ha``), İ on a capital (``I˙nci``)
|
|
408
|
+
if prev and prev in "iI":
|
|
409
|
+
return ("\u0130" if prev == "I" else prev) + nxt
|
|
410
|
+
return prev + ("\u0130" if nxt == "I" else nxt)
|
|
411
|
+
g_before = prev and prev in "gG" and match.start("prev") > 0 # Turkish words never start with ğ (``G˘ain˘a``)
|
|
412
|
+
g_after = nxt and nxt in "gG" and prev and prev.lower() in "aeiou"
|
|
413
|
+
romanian = romanian_word # ă before g in Drăgan, Călugăreanu
|
|
414
|
+
if combining == "\u0306" and not prev and nxt and nxt in "gG":
|
|
415
|
+
failed = True # a breve before a word-initial g is not ğ (Turkish words never start with ğ)
|
|
416
|
+
return match.group(0)
|
|
417
|
+
if combining == "\u0306" and (g_after or g_before) and not romanian:
|
|
418
|
+
# a breve next to g is the Turkish ğ (``Do˘gan``, ``Ça˘glar``: 343 corpus mentions, none on the vowel)
|
|
419
|
+
out = _compose(nxt if nxt in "gG" else prev, combining)
|
|
420
|
+
if out is not None:
|
|
421
|
+
return prev + out if nxt in "gG" else out + nxt
|
|
422
|
+
if tilde and prev and prev in "oO" and nxt and nxt in "nN" and after in ("u", "i"):
|
|
423
|
+
out = _compose(prev, combining) # Estonian õ before n (``To˜nu`` → ``Tõnu``), not Spanish ñ
|
|
424
|
+
if out is not None:
|
|
425
|
+
return out + nxt
|
|
426
|
+
portuguese = ("ao", "ae", "oe")
|
|
427
|
+
if tilde and nxt and (nxt + after).lower() in portuguese and (prev + nxt).lower() not in portuguese:
|
|
428
|
+
order = ((nxt, True), (prev, False)) # the tilde opens an ão/ãe/õe diphthong (``Jo˜ao`` → ``João``)
|
|
429
|
+
elif tilde and prev and nxt and prev in "nN" and nxt.lower() in "aeiou":
|
|
430
|
+
order = ((prev, False), (nxt, True))
|
|
431
|
+
elif tilde and prev and nxt and nxt in "nN" and prev.lower() in "aeiou":
|
|
432
|
+
order = ((nxt, True), (prev, False))
|
|
433
|
+
else:
|
|
434
|
+
vowel_next = nxt.lower() in "aeiouy" and prev.lower() not in "aeiouy"
|
|
435
|
+
order = ((nxt, True), (prev, False)) if vowel_next or not prev else ((prev, False), (nxt, True))
|
|
436
|
+
next_is_accented = match.end() < len(current) and "\u0300" <= current[match.end()] <= "\u036f"
|
|
437
|
+
if dot:
|
|
438
|
+
# names take a dot above only on ż ė (``Z˙ylicz`` → ``Żylicz``); ċ ġ are rare, and a dot by c or g is more often a
|
|
439
|
+
# misread dot below (``Ngo˙c`` is Ngọc), so it is left
|
|
440
|
+
order = tuple((base, is_next) for base, is_next in order if base and base in "zeZE")
|
|
441
|
+
elif combining == "\u0327":
|
|
442
|
+
if prev and prev in "aeAE" and polish_word:
|
|
443
|
+
# in a Polish word a cedilla after a or e is a misread ogonek (``Wie¸cek`` → ``Więcek``, ``Wa¸s`` → ``Wąs``)
|
|
444
|
+
out = _compose(prev, "\u0328")
|
|
445
|
+
if out is not None:
|
|
446
|
+
return out + nxt
|
|
447
|
+
# otherwise it is ç ş ţ far more often than ȩ or a Latvian ņ (``Güne¸s`` → ``Güneş``, ``Du¨zgu¨n¸cınar``)
|
|
448
|
+
order = tuple(sorted(order, key=lambda o: o[0] not in "cstCST"))
|
|
449
|
+
elif combining == "\u0328" and not prev:
|
|
450
|
+
failed = True # no Polish word starts with ą or ę (``B | ˛aczkowska`` lost its B to another field)
|
|
451
|
+
return match.group(0)
|
|
452
|
+
elif combining == "\u0328":
|
|
453
|
+
# an ogonek goes only on a or e, the Polish ą ę (``Pi˛ekos`` → ``Piękos``); with neither neighbour the word is
|
|
454
|
+
# left as it was rather than composing ǫ į ų onto a misread cedilla (``Franc˛ois``)
|
|
455
|
+
polish = polish_word # before its vowel only in a Polish word (``S˛ahin`` is Şahin)
|
|
456
|
+
order = tuple(
|
|
457
|
+
(b, n) for b, n in sorted(order, key=lambda o: not o[1]) if b and b in "aeAE" and ((not n and nxt) or polish)
|
|
458
|
+
) # after its vowel at a word end also only in a Polish word (``SUKHORUKOVA˛``)
|
|
300
459
|
for base, is_next in order:
|
|
460
|
+
if is_next and next_is_accented:
|
|
461
|
+
continue # a letter that already carries a combining mark takes no second one (``Oz˙óg`` → ``Ożóg``)
|
|
301
462
|
out = _compose(base, combining)
|
|
302
463
|
if out is not None:
|
|
303
464
|
return prev + out if is_next else out + nxt
|
|
304
465
|
failed = True
|
|
305
466
|
return match.group(0)
|
|
306
467
|
|
|
307
|
-
repaired
|
|
308
|
-
|
|
468
|
+
# one mark at a time on the text repaired so far, so a letter between two marks is seen by both
|
|
469
|
+
# (``Conceic¸a˜o`` → ``Conceição``; a single substitution pass handed the a to the cedilla match and put the tilde on o)
|
|
470
|
+
pos = 0
|
|
471
|
+
while (match := _TOKEN_MARK_RE.search(current, pos)) is not None:
|
|
472
|
+
replacement = fix(match)
|
|
473
|
+
if failed:
|
|
474
|
+
return original
|
|
475
|
+
nxt = match.group("next") or ""
|
|
476
|
+
if replacement == match.group(0):
|
|
477
|
+
pos = match.end() - len(nxt)
|
|
478
|
+
continue
|
|
479
|
+
current = current[: match.start()] + replacement + current[match.end() :]
|
|
480
|
+
pos = match.start() + max(len(replacement) - 1, 0)
|
|
481
|
+
return current
|
|
309
482
|
|
|
310
483
|
|
|
311
484
|
def strip_soft_hyphens(text: str) -> str:
|
|
@@ -327,12 +500,16 @@ def attach_detached_diacritics(text: str) -> str:
|
|
|
327
500
|
composes with, the vowel first (``¨ovel`` → ``övel``, ``Jose´`` → ``José``); a bare
|
|
328
501
|
combining mark after a space is the NFKC rendering of such a mark and joins the next
|
|
329
502
|
token. A token with a mark that composes with nothing is left exactly as it was
|
|
330
|
-
(``S˘c˘epin``)
|
|
503
|
+
(``S˘c˘epin``). A combining mark after a letter or another mark is ordinary NFD text and is never moved.
|
|
331
504
|
"""
|
|
332
|
-
|
|
505
|
+
# invisible markup between a letter and its accent would make the accent look detached (``Iba\u0301n\u200e\u0303ez``);
|
|
506
|
+
# only that markup is removed here, so names without a detached-looking mark are untouched
|
|
507
|
+
text = _MARKUP_BEFORE_MARK_RE.sub("", text)
|
|
508
|
+
if not _ANY_DETACHED_MARK_RE.search(text) and "^" not in text:
|
|
333
509
|
return text
|
|
334
510
|
# a combining mark after a space is the NFKC remnant of a spacing mark: restore the spacing form so the
|
|
335
|
-
# token repair may move it to the letter it composes with (an attached combining mark is never moved)
|
|
511
|
+
# token repair may move it to the letter it composes with (an attached combining mark is never moved); between
|
|
512
|
+
# spaces it stays a spacing mark (``O ́ connor``), which later reads as an apostrophe
|
|
336
513
|
text = re.sub("(?<=[^\\W\\d_]) ([\\u0300-\\u036f])", lambda m: " " + _COMBINING_TO_SPACING.get(m.group(1), m.group(1)), text)
|
|
337
514
|
text = re.sub("(?<=\\s)([\\u0300-\\u036f])(?=[^\\W\\d_])", lambda m: _COMBINING_TO_SPACING.get(m.group(1), m.group(1)), text)
|
|
338
515
|
parts = re.split(r"(\s+)", text)
|
|
@@ -23,6 +23,7 @@ from sinonym.coretypes import CanonicalName, NameComponents
|
|
|
23
23
|
from sinonym.name_punctuation import (
|
|
24
24
|
INVISIBLE_MARKUP_DELETE_TRANSLATION,
|
|
25
25
|
PERSON_JOINER_FOLD_TRANSLATION,
|
|
26
|
+
attach_detached_diacritics,
|
|
26
27
|
fold_internal_name_joiners,
|
|
27
28
|
fold_spaced_transliteration_apostrophes,
|
|
28
29
|
strip_soft_hyphens,
|
|
@@ -693,7 +694,7 @@ class PersonNameNormalizationService:
|
|
|
693
694
|
"""Normalize one raw name string into semantic canonical components."""
|
|
694
695
|
if not isinstance(raw_name, str):
|
|
695
696
|
return self._invalid("name must be a string")
|
|
696
|
-
raw_name = strip_soft_hyphens(raw_name)
|
|
697
|
+
raw_name = attach_detached_diacritics(strip_soft_hyphens(raw_name))
|
|
697
698
|
if reviewed_non_person_text_pattern(raw_name) is not None:
|
|
698
699
|
return self._non_person("reviewed non-person input")
|
|
699
700
|
|
|
@@ -837,7 +838,7 @@ class PersonNameNormalizationService:
|
|
|
837
838
|
if any(value is not None and not isinstance(value, str) for value in values.values()):
|
|
838
839
|
return self._invalid("name components must be strings or null")
|
|
839
840
|
values = {
|
|
840
|
-
role: strip_soft_hyphens(value) if value else value for role, value in values.items()
|
|
841
|
+
role: attach_detached_diacritics(strip_soft_hyphens(value)) if value else value for role, value in values.items()
|
|
841
842
|
}
|
|
842
843
|
first_name, middle_name, last_name, suffix = values["given"], values["middle"], values["surname"], values["suffix"]
|
|
843
844
|
source_surface = " ".join(value for value in (first_name, middle_name, last_name) if value)
|
|
@@ -15,6 +15,7 @@ from __future__ import annotations
|
|
|
15
15
|
import re
|
|
16
16
|
from typing import TYPE_CHECKING
|
|
17
17
|
|
|
18
|
+
from sinonym.name_punctuation import attach_detached_diacritics
|
|
18
19
|
from sinonym.utils.string_manipulation import StringManipulationUtils
|
|
19
20
|
|
|
20
21
|
if TYPE_CHECKING:
|
|
@@ -49,6 +50,7 @@ class TextPreprocessor:
|
|
|
49
50
|
"""
|
|
50
51
|
|
|
51
52
|
surname_first_parenthetical = bool(self._surname_first_parenthetical_re.match(raw))
|
|
53
|
+
raw = attach_detached_diacritics(raw)
|
|
52
54
|
|
|
53
55
|
# Single pass for most cleaning operations
|
|
54
56
|
raw = self._config.clean_pattern.sub(self._clean_replacement, raw)
|
|
@@ -68,9 +68,207 @@ def test_scalar_baseline_still_canonicalizes_initials_without_moving_boundary(pr
|
|
|
68
68
|
assert resolve(predictor, "J", None, "Smith") == ("J.", "", "Smith")
|
|
69
69
|
|
|
70
70
|
|
|
71
|
+
DETACHED_DIACRITIC_CASES = [
|
|
72
|
+
# inspire: a spacing diaeresis/ring left by PDF extraction split the surname
|
|
73
|
+
(("H", None, "Arenh¨ovel"), ("H.", "", "Arenhövel")),
|
|
74
|
+
(("M.", None, "B¨oge"), ("M.", "", "Böge")),
|
|
75
|
+
(("H.", None, "Pru˚chová"), ("H.", "", "Průchová")),
|
|
76
|
+
(("Emine", "S¸ule", "Yazıcı"), ("Emine", "Şule", "Yazıcı")),
|
|
77
|
+
# a mark that composes with nothing is left alone
|
|
78
|
+
(("Nicolas", None, "D´ Amelio"), ("Nicolas", "", "D' Amelio")),
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@pytest.mark.parametrize(("source", "expected"), DETACHED_DIACRITIC_CASES)
|
|
83
|
+
def test_detached_diacritic_rejoins_its_letter(predictor, source, expected):
|
|
84
|
+
assert resolve(predictor, *source) == expected
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.parametrize(("source", "expected"), [
|
|
88
|
+
# a detached mark next to NFD text joins only an unaccented letter (Ożóg, Urnėžius), never stacks on an accent
|
|
89
|
+
(("Mariola", None, "Oz˙o\u0301g"), ("Mariola", "", "Ożóg")),
|
|
90
|
+
(("Eugenijus", None, "Urne˙žius"), ("Eugenijus", "", "Urnėžius")),
|
|
91
|
+
(("Elçin", None, "\u0308O\u0308lmezer-Öztürk"), ("Elçin", "", "\u0308Ölmezer-Öztürk")),
|
|
92
|
+
# with an ASCII backtick in the word, ´ stays an apostrophe variant
|
|
93
|
+
(("Yves", None, "Le Bloc´`'h"), ("Yves", "", "Le Bloc'h")),
|
|
94
|
+
(("Nerea", None, "L´`ópez-Bouzas"), ("Nerea", "", "L'ópez-Bouzas")),
|
|
95
|
+
])
|
|
96
|
+
def test_detached_mark_next_to_other_marks(predictor, source, expected):
|
|
97
|
+
assert tuple(unicodedata.normalize("NFC", part) for part in resolve(predictor, *source)) == tuple(
|
|
98
|
+
unicodedata.normalize("NFC", part) for part in expected
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@pytest.mark.parametrize(("source", "expected"), [
|
|
103
|
+
# a tilde next to n is ñ on either side; Portuguese ã between vowels is unchanged
|
|
104
|
+
(("R.", None, "Ya˜nez"), ("R.", "", "Yañez")),
|
|
105
|
+
(("A.", None, "Mun˜oz"), ("A.", "", "Muñoz")),
|
|
106
|
+
(("Joa˜o", None, "Magalha˜es"), ("João", "", "Magalhães")),
|
|
107
|
+
# marks one letter apart each see that letter
|
|
108
|
+
(("Maria", None, "Conceic¸a˜o"), ("Maria", "", "Conceição")),
|
|
109
|
+
# a mid-word ´ is an acute or an apostrophe, so it is left as written; right after a repaired letter it is the
|
|
110
|
+
# next vowel's acute
|
|
111
|
+
(("Jos´e", None, "Dvoˇr´ak"), ("Jos'e", "", "Dvořák")),
|
|
112
|
+
(("JIˇR´I", None, "NOVAK"), ("Jiří", "", "Novak")),
|
|
113
|
+
(("Carlos", None, "Sag¨u´es"), ("Carlos", "", "Sagüés")),
|
|
114
|
+
(("Ana", None, "L´´opez"), ("Ana", "", "L'opez")),
|
|
115
|
+
# elisions and apostrophes stay apostrophes; an ambiguous acute is left alone
|
|
116
|
+
(("Gina", None, "D´Angelo"), ("Gina", "", "D'Angelo")),
|
|
117
|
+
(("Pietro", None, "Dall´aglio"), ("Pietro", "", "Dall'aglio")),
|
|
118
|
+
(("Solange", None, "L´Abbate"), ("Solange", "", "L'Abbate")),
|
|
119
|
+
(("Rosane", None, "Sant´ana"), ("Rosane", "", "Sant'ana")),
|
|
120
|
+
# a transliterated Russian soft sign is an apostrophe (Vladimir G. Maz'ya), not an acute
|
|
121
|
+
(("Vladimir", "G.", "Maz´ya"), ("Vladimir", "G.", "Maz'ya")),
|
|
122
|
+
(("V.", "G.", "Vasil´ev"), ("V.", "G.", "Vasil'ev")),
|
|
123
|
+
(("Konstantin", None, "Il´in"), ("Konstantin", "", "Il'in")),
|
|
124
|
+
# a mid-word ´ after ng stays an apostrophe; a breve next to g is the Turkish ğ
|
|
125
|
+
(("James", "B.", "Kung´u"), ("James", "B.", "Kung'u")),
|
|
126
|
+
(("Bora", None, "C¸a˘glayan"), ("Bora", "", "Çağlayan")),
|
|
127
|
+
(("A.", None, "Do˘gan"), ("A.", "", "Doğan")),
|
|
128
|
+
# a mid-word ´ is left as written: an apostrophe here, and in Ren´e as 0.6.1 had it
|
|
129
|
+
(("Xin´e", None, "Shi"), ("Xin'e", "", "Shi")),
|
|
130
|
+
(("Ren´e", None, "Kok"), ("Ren'e", "", "Kok")),
|
|
131
|
+
# an acute after an accented vowel is the consonant's; elisions after a hyphen or at a word end stay apostrophes
|
|
132
|
+
(("K.", "M.", "Szcz¸e´sniak"), ("K.", "M.", "Szczȩśniak")),
|
|
133
|
+
(("Helena", None, "Pinheiro-Sant´ana"), ("Helena", "", "Pinheiro-Sant'ana")),
|
|
134
|
+
(("I.", "A.", "Il´inskaya"), ("I.", "A.", "Il'inskaya")),
|
|
135
|
+
# a caret between a vowel and a consonant is a circumflex; any other caret leaves the word alone
|
|
136
|
+
(("Jéro^me", None, "Lemai^tre"), ("Jérôme", "", "Lemaître")),
|
|
137
|
+
(("John", None, "Smith^1"), ("John", "", "Smith^1")),
|
|
138
|
+
# ogonek
|
|
139
|
+
(("Anna", None, "Ste˛pień"), ("Anna", "", "Stępień")),
|
|
140
|
+
])
|
|
141
|
+
def test_detached_mark_placement(predictor, source, expected):
|
|
142
|
+
assert tuple(unicodedata.normalize("NFC", part) for part in resolve(predictor, *source)) == expected
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@pytest.mark.parametrize("invisible", ["\u200e", "\u200f", "\u2060", "\ufeff"])
|
|
146
|
+
def test_invisible_markup_does_not_detach_an_accent(predictor, invisible):
|
|
147
|
+
decomposed = unicodedata.normalize("NFD", "Ibáñez").replace("n\u0303", f"n{invisible}\u0303")
|
|
148
|
+
result = tuple(unicodedata.normalize("NFC", part) for part in resolve(predictor, "José", None, decomposed))
|
|
149
|
+
assert result == ("José", "", "Ibáñez")
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@pytest.mark.parametrize(("raw", "expected"), [
|
|
153
|
+
# a mid-word ´ that is an apostrophe stays one (Natal'ia, Ken'ichi, Mas'ud), and so does one inside mojibake
|
|
154
|
+
("Natal´ia", "Natal´ia"),
|
|
155
|
+
("Ken´ichi", "Ken´ichi"),
|
|
156
|
+
("Mas´ud", "Mas´ud"),
|
|
157
|
+
("Antônio", "Antônio"),
|
|
158
|
+
# quote marks
|
|
159
|
+
("´Iñaki´", "´Iñaki´"),
|
|
160
|
+
("Ángel´´", "Ángel´´"),
|
|
161
|
+
# a word-final ´ after an elision word is its apostrophe; after another word it is the last letter's acute
|
|
162
|
+
("Dell´", "Dell´"),
|
|
163
|
+
("Nikolic´", "Nikolić"),
|
|
164
|
+
# the tilde opens an ão diphthong
|
|
165
|
+
("Jo˜ao", "João"),
|
|
166
|
+
# the dot above: an i's own dot, else only ż ė ċ ġ
|
|
167
|
+
("Meli˙ha", "Meliha"),
|
|
168
|
+
("I˙nci", "İnci"),
|
|
169
|
+
("Z˙ylicz", "Żylicz"),
|
|
170
|
+
("Grublyt˙", "Grublyt˙"),
|
|
171
|
+
# a cedilla prefers c s t, an ogonek a e, and no word starts with ğ
|
|
172
|
+
("Du¨zgu¨n¸cınar", "Düzgünçınar"),
|
|
173
|
+
("Güne¸s", "Güneş"),
|
|
174
|
+
("Ta¸skıran", "Taşkıran"),
|
|
175
|
+
("ˇS´CETA", "ŠĆETA"),
|
|
176
|
+
# after an acute, macron, tilde or circumflex a mid-word ´ is an apostrophe, not a second accent
|
|
177
|
+
("Sā´id", "Sā´id"),
|
|
178
|
+
("Marí´a", "Marí´a"),
|
|
179
|
+
("Iñ´aki", "Iñ´aki"),
|
|
180
|
+
# an ogonek goes only on a or e, and before its vowel only in a Polish word
|
|
181
|
+
("Franc˛ois", "Franc˛ois"),
|
|
182
|
+
("S˛ahin", "S˛ahin"),
|
|
183
|
+
("˛aczkowska", "˛aczkowska"),
|
|
184
|
+
# a dot between i and z is the z's (Giżewska)
|
|
185
|
+
("Gi˙zewska", "Giżewska"),
|
|
186
|
+
("I˙zzet", "İzzet"),
|
|
187
|
+
("SEZG˙IN", "SEZGİN"),
|
|
188
|
+
# no ğ in a Romanian word or at a word start
|
|
189
|
+
("C˘alug˘areanu", "Călugăreanu"),
|
|
190
|
+
("Dra˘gan", "Drăgan"),
|
|
191
|
+
("˘gain", "˘gain"),
|
|
192
|
+
# a word-final ´ after r l m s z p k is a soft sign or stray, not an accent
|
|
193
|
+
("Igor´", "Igor´"),
|
|
194
|
+
("Vasyl´", "Vasyl´"),
|
|
195
|
+
("Fernandes´", "Fernandes´"),
|
|
196
|
+
# ... but on y in a Czech word it is ý, and on s/z in a Polish word the ś/ź; without such a sign y´ is left
|
|
197
|
+
("Sechovsky´", "Sechovský"),
|
|
198
|
+
("Sˇedivy´", "Šedivý"),
|
|
199
|
+
("Nancy´", "Nancy´"),
|
|
200
|
+
("Grzes´", "Grześ"),
|
|
201
|
+
# UTF-8 read as Latin-1 is decoded when it round-trips exactly, and left as written when it does not
|
|
202
|
+
("Søren", "Søren"),
|
|
203
|
+
("RISTIC´", "RISTIĆ"),
|
|
204
|
+
("Ľubica", "Ľubica"),
|
|
205
|
+
# a word-initial ´ goes on a vowel, or on ć ń ś ź in a Polish word; a word-final n´ is ń only in a Polish word
|
|
206
|
+
("´Pedraza", "´Pedraza"),
|
|
207
|
+
("´Swia¸tek", "Świątek"),
|
|
208
|
+
("Istvan´", "Istvan´"),
|
|
209
|
+
("Kwiecien´", "Kwiecień"),
|
|
210
|
+
("Brown´", "Brown´"),
|
|
211
|
+
("To˜nu", "Tõnu"),
|
|
212
|
+
("Fi˙li˙z", "Filiz"),
|
|
213
|
+
("SUKHORUKOVA˛", "SUKHORUKOVA˛"),
|
|
214
|
+
("STOJANOVIC´", "STOJANOVIĆ"),
|
|
215
|
+
("MĨKINEN", "MĨKINEN"),
|
|
216
|
+
("Bien´", "Bień"),
|
|
217
|
+
("Leon´", "Leon´"),
|
|
218
|
+
("´Sciana", "Ściana"),
|
|
219
|
+
("´Silva", "´Silva"),
|
|
220
|
+
("O \u0301 connor", "O ´ connor"),
|
|
221
|
+
# a dot by c or g is left (more often a misread dot below)
|
|
222
|
+
("Ngo˙c", "Ngo˙c"),
|
|
223
|
+
# in NFD, an acute already on the letter before ´ makes it an apostrophe, a caron makes it the next vowel's acute
|
|
224
|
+
("Mari\u0301´a", "Mari\u0301´a"),
|
|
225
|
+
("Dvor\u030c´ak", "Dvořák"),
|
|
226
|
+
# a word longer than any name is left as written
|
|
227
|
+
("Mu¨ller" * 30, "Mu¨ller" * 30),
|
|
228
|
+
# invisible markup is removed only before an accent
|
|
229
|
+
("Li\u200eWei", "Li\u200eWei"),
|
|
230
|
+
# doubled marks count once, and a word whose repair fails is returned exactly as written
|
|
231
|
+
("Mu¨¨ller", "Müller"),
|
|
232
|
+
("Ab¨¨1", "Ab¨¨1"),
|
|
233
|
+
# an elision word after a hyphen keeps its apostrophe; a combining mark after a hyphen is placed
|
|
234
|
+
("Pinheiro-Dell´", "Pinheiro-Dell´"),
|
|
235
|
+
("Jean-\u0301Eric", "Jean-Éric"),
|
|
236
|
+
# the Polish-word markers: anchored -ski/-cki, and ie¸ on its own
|
|
237
|
+
("Eski¸sehir", "Eskişehir"),
|
|
238
|
+
("Ba¸skin", "Başkin"),
|
|
239
|
+
("Zie¸tara", "Ziętara"),
|
|
240
|
+
# a mark left alone still lets the next mark see its own neighbour (Fran´çois)
|
|
241
|
+
("Fran´c¸ois", "Fran´çois"),
|
|
242
|
+
("Kata¸tski", "Katątski"),
|
|
243
|
+
("Oświe¸cimka", "Oświęcimka"),
|
|
244
|
+
("Wa¸s", "Wąs"),
|
|
245
|
+
("Pi˛ekos", "Piękos"),
|
|
246
|
+
("G˘ain˘a", "Găină"),
|
|
247
|
+
("Do˘gan", "Doğan"),
|
|
248
|
+
# a combining mark after punctuation is not placed
|
|
249
|
+
("O.\u0301scar", "O.\u0301scar"),
|
|
250
|
+
])
|
|
251
|
+
def test_detached_mark_rules(raw, expected):
|
|
252
|
+
from sinonym.name_punctuation import attach_detached_diacritics # noqa: PLC0415
|
|
253
|
+
|
|
254
|
+
assert unicodedata.normalize("NFC", attach_detached_diacritics(raw)) == unicodedata.normalize("NFC", expected)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def test_invisible_markup_is_removed_before_the_repair():
|
|
258
|
+
from sinonym.name_punctuation import attach_detached_diacritics # noqa: PLC0415
|
|
259
|
+
|
|
260
|
+
decomposed = unicodedata.normalize("NFD", "Ibáñez").replace("n\u0303", "n\u200e\u0303")
|
|
261
|
+
assert attach_detached_diacritics(decomposed) == unicodedata.normalize("NFD", "Ibáñez")
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def test_leading_combining_mark_does_not_glue_words(predictor):
|
|
265
|
+
# ``Mithat ̈unsal`` (NFKC remnant of a spacing diaeresis before the surname) stays two words
|
|
266
|
+
assert resolve(predictor, "Mithat", None, "\u0308unsal") == ("Mithat", "", "Ünsal")
|
|
267
|
+
|
|
268
|
+
|
|
71
269
|
DECOMPOSED_ACCENT_CASES = [
|
|
72
|
-
# names written in NFD (each accent a combining mark after its letter)
|
|
73
|
-
# marks
|
|
270
|
+
# names written in NFD (each accent a combining mark after its letter) keep their accents where they are, also
|
|
271
|
+
# when accented letters are adjacent or marks are stacked; 0.6.0 moved them onto the neighbouring letter
|
|
74
272
|
(("Antonín", None, "Dvořák"), ("Antonín", "", "Dvořák")),
|
|
75
273
|
(("José", None, "Núñez"), ("José", "", "Núñez")),
|
|
76
274
|
(("Jiří", None, "Kořínek"), ("Jiří", "", "Kořínek")),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|