Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use language codes in HEAD_TAG_RE pattern #409

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/wiktextract/extractor/en/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from .unsupported_titles import unsupported_title_map

# Matches head tag
head_tag_re = None
HEAD_TAG_RE = None

FLOATING_TABLE_TEMPLATES = {
# az-suffix-form creates a style=floatright div that is otherwise
Expand Down Expand Up @@ -535,14 +535,15 @@ def parse_sense_linkage(wxr, data, name, ht):
data_append(data, field, dt)


def init_head_tag_re(wxr):
global head_tag_re
if head_tag_re is None:
head_tag_re = re.compile(
def init_head_tag_re():
global HEAD_TAG_RE
if HEAD_TAG_RE is None:
HEAD_TAG_RE = re.compile(
r"^(head|Han char|arabic-noun|arabic-noun-form|"
r"hangul-symbol|syllable-hangul)$|" +
r"^(latin|" +
"|".join(lang_name for _, lang_name in get_all_names("en")) + r")-(" +
"|".join(lang_code for lang_code, *_ in get_all_names("en")) +
r")-(" +
"|".join([
"abbr",
"adj",
Expand Down Expand Up @@ -720,7 +721,7 @@ def parse_language(wxr, langnode, language, lang_code):
assert isinstance(lang_code, str)
# print("parse_language", language)

init_head_tag_re(wxr)
init_head_tag_re()
is_reconstruction = False
word = wxr.wtp.title
unsupported_prefix = "Unsupported titles/"
Expand Down Expand Up @@ -879,8 +880,7 @@ def head_post_template_fn(name, ht, expansion):
data_append(pos_data, "tags", "Pinyin")
elif t == "romanization":
data_append(pos_data, "tags", "romanization")
m = re.search(head_tag_re, name)
if m:
if HEAD_TAG_RE.fullmatch(name) is not None:
args_ht = clean_template_args(wxr, ht)
cleaned_expansion = clean_node(wxr, None, expansion)
dt = {"name": name, "args": args_ht, "expansion": cleaned_expansion}
Expand Down
12 changes: 12 additions & 0 deletions tests/test_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,15 @@ def test_head35(self):
"plural"
]
})


def test_head_templates_regex(self):
# GitHub issue 405
import re

from wiktextract.extractor.en.page import init_head_tag_re

init_head_tag_re()
from wiktextract.extractor.en.page import HEAD_TAG_RE

self.assertTrue(HEAD_TAG_RE.fullmatch("ru-noun+") is not None)