Skip to content

lingrep 0.9.0

Choose a tag to compare

@github-actions github-actions released this 20 Nov 07:28
· 214 commits to main since this release

lingrep 0.9.0

lingrep 0.9.0 keeps the exact spelling of every token and matches patterns on
a folded spelling. Variant characters common in Japanese text, such as
half-width katakana, full-width letters, ideographic variation selectors and
the wave dash, no longer split words or hide matches, and results show the
text exactly as the source wrote it. Every prepared corpus and count table must
be rebuilt.

curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSLO https://github.com/borh/lingrep/releases/download/v0.9.0/install.sh
sh install.sh

Python and corpus queries

Install the bindings with python -m pip install lingrep==0.9.0. Run
ling dictionary install once to use the default Japanese dictionary.
Tokenizer(workers=4).pipe(sentences) tokenizes batches in input order.
Use from_spacy or from_stanza to match documents you have already analyzed.
Install lingrep[polars,arrow] for lazy Polars queries and Arrow token batches.

Patterns can follow annotated span dependencies, count dependents and bind
measurements within an occurrence. Saved questions and shared links can pin
the vector table used by a query.

surface and text

Each token now has two spellings:

  • surface (表層形) is the exact source text of the token. For CoNLL-U it is
    the FORM column as written.
  • text (照合形, match form) is surface folded for matching: variation
    selectors removed, half-width katakana widened (ガラス → ガラス), the
    full-width tilde ~ written as the wave dash 〜, Unicode NFC composition, and
    full-width ASCII written as ASCII (NHK → NHK). The ideographic space
    U+3000 is kept.

In 0.8, text was UniDic's orthography column for Vibrato and the analyzer's
own text for other analyzers, and no attribute kept the source spelling.

Every analyzer (Vibrato, Sudachi, GiNZA, and other spaCy or Stanza adapters)
now reads the folded text, and ling maps its words back to the source. Vibrato
and Sudachi keep a CJK compatibility ideograph where the dictionary lists a
word that contains it, such as 臭氣 written with U+FA5C.

Patterns

  • A text value is folded before matching, so [text=ガラス] and
    [text=ガラス] find the same tokens. This applies to =, !=, in,
    not in, ~, !~, inline and named sets, lexicon members read
    by [text], and the values a near test compares with text. A value
    that the fold changes is reported:

    warning[literal_folded]: q.lx:2:20: In definition `garasu_hw`, the `text` literal `ガラス` (U+FF76 U+FF9E U+FF97 U+FF7D) matches as its folded key `ガラス` (U+30AC U+30E9 U+30B9). Test `surface` to match the exact spelling
    
  • [surface=…] matches the exact spelling and nothing else. Use it to find
    one variant, such as [surface=ガラス] for the half-width spelling only.

  • A regular expression on text is used as written. If it contains a
    character that the fold removes or replaces, it can never match that
    character, and ling reports regex_not_folded with the folded spelling.

  • lemma, norm and analyzer-specific attributes such as unidic.* are
    compared as written.

  • A corpus prepared by 0.8 has no surface and an unfolded text. Querying
    it with text values reports text_unfolded and names the definitions
    affected; rebuild the corpus.

ling check and the lingrep-web pattern editor, in English and Japanese,
report literal_folded and regex_not_folded as you write.

What changes in your results

These examples come from running ling 0.8.2 and 0.9.0 with the default
UniDic dictionary over these lines:

ガラスの靴を買った。
NHKの番組を見た。
葛󠄀城市に行く。            (葛 + U+E0100)
今日圖󠄃らずも會つた。      (圖 + U+E0103)
Source 0.8.2 0.9.0
ガラス one PROPN token ガラス, lemma ガラス; found only by [text=ガラス] NOUN, lemma ガラス-glas, text ガラス, surface ガラス; found by [text=ガラス] and [text=ガラス]
NHK text NHK; found only by [text=NHK] text NHK, surface NHK; found by [text=NHK] and [text=NHK]
葛 + U+E0100 城市 葛 / variation selector as a SYM token / 城市 葛城 (PROPN, lemma カツラギ) / 市; [text=葛城] matches, and the match shows 葛 + U+E0100 城
圖 + U+E0103 らずも 圖 / variation selector as a SYM token / ら (AUX) / ず / も 圖ら (VERB, lemma 図る) / ず / も; the result shows 圖 with its selector

In 0.8.2 a match on 圖 reported the surface 圖 without the selector and a
char_span one character short. In 0.9.0 the surface and char_span cover
the selector.

Text without these characters gives the same results as before. Over the 373
Akutagawa Ryūnosuke documents of the Soranoha corpus, the 14 catalogs in
patterns/ that do not need dependency annotations produced the same match
records in 0.8.2 and 0.9.0, including spans, captures, char_span and the
matched text.

Other changes

  • --normalization defaults to none for every analyzer, so surface and
    char_span address the source text exactly. --normalization nfc still
    composes the source before analysis.
  • Highlights in the reading view of ling serve and lingrep-web cover the
    exact source characters of a match, including variation selectors,
    half-width katakana and decomposed kana. In 0.8 such a match could
    highlight the whole sentence or miss the word.
  • lingrep-web shows surface in KWIC lines, the inspector, frequency lines
    and Excel exports, and labels the two attributes 表層形 and 照合形. A
    frequency row grouped by text is labelled with the match form; its lines
    show each occurrence as written.
  • lingrep-web and the KWIC view of ling explore show one space wherever
    the source has whitespace between two tokens, as human ling matches
    output does: I saw NHK news, where 0.8 showed IsawNHKnews or, in the
    workbench, N H K for a word the dictionary splits into letters. Text
    without whitespace between tokens is shown as before.
  • Multi-token surfaces in JSONL, TSV and count tables preserve gaps between
    tokens as one space. Rebuild earlier count tables with
    ling summarize --write-table for the new keys.
  • ling summarize fails with error[missing_surface_offsets] when it groups
    a multi-token surface in a sentence without character offsets, such as a
    CoNLL-U sentence whose forms do not occur in its # text comment. 0.8 counted
    such a match under its tokens joined with nothing. Correct or delete the
    # text line, or give the pattern a key:.
  • ling loads Sudachi without its input-text plugins, so rewrite.def and
    sudachi.json do not affect analysis; the folded text takes their place.
    The 0.8 documentation said they were used.

Known limits

  • GiNZA and Stanza receive the unified form of a compatibility ideograph, as
    with NFC in 0.8, so GiNZA splits SudachiDict words such as 臭氣 with U+FA5C
    into 臭 / 氣.
  • A displayed space stands for any whitespace between two tokens, so a tab or
    a run of spaces is shown as one space.

Upgrading

Rebuild every prepared corpus and every count table. A corpus built by 0.8
still opens, but its text is unfolded and it has no surface, so a query
reports text_unfolded and its results differ from a rebuilt corpus. A count
table written by 0.8 fails with "built with a different matcher revision".

Rebuild with the same options as before:

ling corpus build --input-format soranoha corpora/works.zip
ling summarize --corpus corpora/works.zip.g3.a1.<identity>.locally-executed.lingcorpus \
  --patterns catalog.lx --write-table corpora/works.lingtable

corpus build writes the new corpus beside the 0.8 one, under a new
identity. Then list and delete the 0.8 corpora and their count tables:

ling corpus disk corpora/ --input-format soranoha --current   # 0.8 corpora are "superseded"
ling corpus prune corpora/ --input-format soranoha             # lists what would be deleted
ling corpus prune corpora/ --input-format soranoha --execute   # deletes them

prune lists a 0.8 corpus of the same source as superseded, because it
differs in reader, analyzer and token schema, and deletes it without
--include-all-superseded. It also deletes a count table bound only to
corpora it deletes. Pass prune the -d, --input-format or
--analyzer-config options used for corpus build, as in 0.8.2. A
lingrep-web deployment needs the new corpus directory in its path and
count tables rebuilt over it.

Adapter wheels use version 0.9.0. See the
changelog for the complete list of changes.