Class 3: Searching by lemma and pattern

Tuesday, October 20, 2026

Have your class 2 story.txt, worksheet, and homework notes at hand.

What you use From class 2 Today
Text story.txt The same text, and a prepared corpus of 103 works by Akutagawa
Search grep with an exact string Regular expressions in grep, lemma patterns in ling
Record Worksheet rows 1–7 and your homework notes Class notes and CSV rows 8–10 (homework)

If you missed class 2, use the seven worksheet rows with example labels (CSV) in place of your own annotations.

1. Set up the prepared corpora

On the computer you use, install the search tool ling (lingrep 0.5.0) once by following Set up ling.

  1. Save the prepared corpora (ZIP, about 18 MB) into your class 2 working folder dh-b-2026 and extract it.
  2. Open a terminal and run these commands one line at a time.
cd dh-b-2026/class3-prepared
ling --version
ling corpus inspect story-unidic-novel.lingcorpus

A prepared corpus (.lingcorpus) is a text whose analysis by an analyzer and a dictionary has been saved. ling reads it with --corpus and does not require a dictionary.

If inspect reports one document and finishes with complete:, continue to the next section. If the command is unavailable, follow Set up ling and run ling --version again.

In the ZIP Contents
story.txt The class 2 text of 「蜘蛛の糸」 (“The Spider’s Thread”)
story-*.lingcorpus The same text analyzed by six analyzer and dictionary combinations (table in section 4)
tokens-*.tsv Each analysis as a table; a spreadsheet can open it
story-ginza.conllu, story-spacy.conllu The original GiNZA and spaCy output (CoNLL-U format)
akutagawa-unidic-novel.lingcorpus, akutagawa-works.csv A prepared corpus of 103 works by Akutagawa Ryūnosuke and the list of works (section 8)
class3.lx, compare.lx Today’s pattern files
README.txt Versions of the tools and dictionaries used
How do I analyze the text myself with a dictionary?

Follow the novel dictionary setup before running these commands; it sets 近現代口語小説UniDic 202512 in LINGREP_DICTIONARY_PATH. If ling doctor prints ling readiness: ready, you can pass story.txt instead of --corpus story-unidic-novel.lingcorpus and search while analyzing the text.

ling doctor
ling matches --pattern '[lemma=上る].' --context 2 --color never story.txt

The results match those from the prepared corpus. Other dictionaries and analyzers are passed differently, depending on their format.

Dictionary or analyzer How to pass it
UniDic as a Vibrato .dic file Name the file with --dict-path
UniDic as a MeCab-format folder Not readable as is. Convert it to a Vibrato .dic with lingrep’s Nix packages, then name that file with --dict-path
Sudachi --analyzer sudachi --sudachi-dict system_core.dic; use SudachiDict v20261015 or later from its GitHub releases. Split mode C and built-in resources are the defaults
GiNZA and spaCy Read saved CoNLL-U with --input-format conllu (story-ginza.conllu in the ZIP is such an output). Direct analysis also supports a configured adapter via --analyzer-config; see lingrep’s analyzer setup
How do I follow along without a terminal?

Read these outputs, saved from the same source, dictionary, and pattern files. You cannot change their patterns, but you can compare the outputs and check them against the source. The README lists the commands and versions used.

Section Saved output
3 Tokenizer output (TSV) · Matches for 上る
4 Lemmas by analyzer and dictionary
5 Summary of the pattern file
6 Matches for the imperative, the conditional, and verb plus negation
7 Matches for 来る and 行く
8 Summary over 103 works · Counts by work · Matches in 「杜子春」
Homework Matches for 落ちる

2. Widen a string search into a pattern

Class 2 used -F, which matches the exact string. A regular expression is a search pattern in which symbols stand for any one character or for one of several characters. With -E, grep reads its argument as a pattern.

grep -oE 'のぼ.' story.txt | sort | uniq -c
grep -oE 'のぼ[っりるれ]' story.txt | wc -l
Symbol or command Meaning
. Any one character
[っりるれ] One character from inside the brackets
sort | uniq -c Group identical lines and print each count first

A pipe (|) makes the output of the command on its left the input of the command on its right. The diagram below extends the first command with sort -rn | head from section 8 and shows the output after each stage.

Output after each of the five commands joined by pipes (|)
grep -oE 'のぼ.' story.txt →| sort →| uniq -c →| sort -rn →| head -3
Print each match on its own line Order the lines so that identical ones are adjacent Merge adjacent identical lines and prefix the count Order by the leading number, largest first Keep the first 3 lines
  1. のぼっ
  2. のぼり
  3. のぼる
  4. のぼれ
  5. のぼっ
  6. のぼん
  7. のぼっ
  8. のぼっ
  9. のぼっ
  10. のぼっ
  11. のぼっ
  12. のぼっ
  1. のぼっ
  2. のぼっ
  3. のぼっ
  4. のぼっ
  5. のぼっ
  6. のぼっ
  7. のぼっ
  8. のぼっ
  9. のぼり
  10. のぼる
  11. のぼれ
  12. のぼん
  1. 8のぼっ
  2. のぼっ
  3. のぼっ
  4. のぼっ
  5. のぼっ
  6. のぼっ
  7. のぼっ
  8. のぼっ
  9. 1のぼり
  10. 1のぼる
  11. 1のぼれ
  12. 1のぼん
  1. 8のぼっ
  2. 1のぼん
  3. 1のぼれ
  4. 1のぼる
  5. 1のぼり
  1. 8のぼっ
  2. 1のぼん
  3. 1のぼれ
  4. 1のぼる
  5. 1のぼり
12 lines 12 lines 5 lines 5 lines 3 lines

Highlighted: where のぼん (part of あのぼんやり) moves at each stage

Text: the distributed story.txt (the Soranoha plaintext of 「蜘蛛の糸」).

のぼん is part of あのぼんやり, which is not a movement expression. The second command yields 11 matches, excluding のぼん. よじのぼっ is counted among the 11 as のぼっ. To separate and count compound verbs, use the analysis in the next section.

3. Read the UniDic analysis and search by lemma

UniDic is a dictionary for morphological analysis published by the National Institute for Japanese Language and Linguistics. The analyzer splits the text into short-unit tokens and gives each token a lemma, a part of speech, and an inflected form. Today’s main dictionary is 近現代口語小説UniDic, the variant prepared for Meiji and Taishō fiction.

A lemma (UniDic 語彙素) is the dictionary headword that groups inflected forms and spelling variants; it is the lemma column in the output. のぼっ, のぼり, のぼる, and のぼれ share the lemma 上る, while よじのぼっ belongs to the compound verb 攀じ登る.

ling tokenize --corpus story-unidic-novel.lingcorpus --tsv | less

TSV means tab-separated values. The same table is in tokens-unidic-novel.tsv.

Column Contents
6 Surface form
7 Lemma
8 Part of speech
9 Inflected form

In less, type / followed by a string to search, and q to quit. Find のぼっ and よじのぼっ and check their lemma and part of speech.

ling check --pattern '[lemma=上る].'
ling matches --corpus story-unidic-novel.lingcorpus --pattern '[lemma=上る].' --context 2 --color never
Notation Meaning
[lemma=上る] One token whose lemma is 上る
[upos=VERB] One token whose part of speech is verb
[unidic.cform ~ 命令] One token whose inflected form contains 命令
[lemma=上る] [lemma=て] Written in sequence, a run of consecutive tokens
Final . End of the definition; keep it inside the quotes

check verifies the syntax, and matches shows each match with two tokens of context on each side. In the distributed story.txt with today’s dictionary, expect 10 token matches.

Class 2’s grep -oF 'のぼ' returned 12 matches, the pattern in section 2 returned 11, and the lemma search returned 10. Explain in your notes how あのぼんやり and よじのぼっ account for the differences among these counts.

4. Read the same text under other analyzers and dictionaries

The dictionary defines the lemma. The ZIP archive contains the same text analyzed by these six combinations.

Corpus Analyzer Dictionary
story-unidic-novel Vibrato 近現代口語小説UniDic 202512
story-unidic-cwj Vibrato 現代書き言葉UniDic 202512
story-unidic-kindai-bungo Vibrato 近代文語UniDic 202512
story-sudachi-core-c Sudachi (split C) SudachiDict core
story-ginza GiNZA 5.3 (spaCy) SudachiDict core
story-spacy spaCy ja_core_news_sm 3.8 SudachiDict core

Four surface forms from the text are analyzed across the corpora as follows:

Surface form Three UniDics (Vibrato) Sudachi and GiNZA spaCy
のぼっ 上る のぼる のぼる
よじのぼっ 攀じ登る (one token) よじのぼる (one token) Split into よじ and のぼっ
のぼれ 上る のぼれる のぼれる
這い上っ 這い上る 這い上る Split into 這い and 上っ

A lemma value depends on the dictionary’s definitions, so a pattern written for one dictionary does not carry over to another. In this text the three UniDics return the same lemmas, but in another text the dictionary’s period and register change the results.

  1. Run the [lemma=上る] pattern from section 3 on story-ginza and story-spacy as well and compare the counts. In the distributed story.txt they are 10, 0, and 2.
  2. Which analyzer and dictionary would you choose to count 攀じ登る and 這い上る each as one verb? Write your reason in your notes.
How were the lemmas in the table counted?

compare.lx counts the tokens containing のぼ, 落ち, 下り, or 上っ by surface form, lemma, and part of speech. These commands run it on each corpus.

ling summarize --corpus story-unidic-novel.lingcorpus --patterns compare.lx --top all
ling summarize --corpus story-ginza.lingcorpus --patterns compare.lx --top all
ling summarize --corpus story-spacy.lingcorpus --patterns compare.lx --top all

5. Find the movement that string search missed

The class 2 and homework searches found only the places containing のぼ and 落ち. With lemmas and parts of speech you can count every verb in the text. In class3.lx, each name := pattern. is one definition, key: [lemma] makes the lemma the unit of counting, and lines starting with # are notes.

less class3.lx
ling check --patterns class3.lx
ling summarize --corpus story-unidic-novel.lingcorpus --patterns class3.lx --top all > summary.txt
less summary.txt

The verbs table displays verb lemmas sorted by frequency. In the distributed story.txt, 上る and 言う each occur 10 times, and 落ちる and 光る each occur 5 times. vertical is a set of 12 lemmas chosen by the instructor. 垂れる and ぶら下がる denote the physical state of the thread and of Kandata.

  1. From verbs, write down every lemma that expresses vertical movement, and mark those that the のぼ and 落ち searches could not find.
  2. Compare your list with vertical and choose one lemma to add or one to remove. Decide with the rule you revised in class 2 whether 垂れる and ぶら下がる count as movement expressions.
  3. Change the set in class3.lx, rerun check and summarize, and record why you changed it.

6. Find the word forms that cue the judgments

In class 2 you judged “Does the movement happen?” by reading the paragraph. Imperative, conditional, and negated forms are cues for that judgment.

ling matches --corpus story-unidic-novel.lingcorpus --pattern '[unidic.cform ~ 命令].' --context 3 --color never
ling matches --corpus story-unidic-novel.lingcorpus --pattern '[unidic.cform ~ 仮定].' --context 3 --color never
ling matches --corpus story-unidic-novel.lingcorpus --pattern '[upos=VERB] [lemma in {ない, ぬ}].' --context 3 --color never
Pattern Matches in the distributed story.txt Corresponding class 2 judgment
Imperative 下りろ, 2 matches Not stated whether it happens (Uu)
Conditional 10 matches, including のぼって行けば twice Not stated whether it happens (Uu)
Verb plus negation のぼれなく once and 云えない twice Does not happen / did not happen (CT-)

A word form is a cue, not the judgment itself. 落ちてしまわなければなりません matches the conditional, yet the narrator presents the fall as unavoidable. unidic.cform exists only in UniDic output and is unavailable in the other corpora of section 4.

  1. Keep only the matches that are movement expressions and compare them with your worksheet judgments.
  2. Choose one passage with no imperative, conditional, or negated form (most of “Happens / happened” (CT+)) and write down what evidence its judgment rested on.

7. Read the narrator’s viewpoint from 来る and 行く

After a movement verb, 来る and 行く indicate the narrator’s viewpoint on the movement.

ling matches --corpus story-unidic-novel.lingcorpus --pattern '[upos=VERB] [lemma=て] [lemma in {来る, 行く}].' --context 3 --color never

In the distributed story.txt there are 7 matches. The deixis table in summary.txt records counts for each combination of verb and 来る or 行く.

  1. For each match, record who moves and whether it is told with 来る or 行く.
  2. Which word is used for Kandata’s climb, and which for the sinners’ climb? Where is the viewpoint in part 二? Compare this with the actor column of your worksheet and the narrator’s-perspective judgment.

8. Widen to 103 works by Akutagawa

akutagawa-unidic-novel.lingcorpus is a prepared corpus of 103 works by Akutagawa Ryūnosuke from Soranoha, analyzed with the same dictionary. akutagawa-works.csv records Soranoha’s titles and first-publication information, with source links to the work information and reader links to the text. Run the same pattern file and check whether the observations from one story hold in the other works.

ling summarize --corpus akutagawa-unidic-novel.lingcorpus --patterns class3.lx --top all > akutagawa-summary.txt
grep vertical akutagawa-summary.txt
grep deixis akutagawa-summary.txt | grep -E '上る|落ちる|下りる'

grep pulls from the saved summary only the rows that contain a table name or a lemma.

Table Counts
vertical 上る 183, 落ちる 178, 下りる 103, 垂れる 62, 沈む 54
deixis 上る with 行く 19 and 来る 18; 落ちる with 来る 14 and 行く 4

Counts by work come from the tabular output of matches.

ling matches --corpus akutagawa-unidic-novel.lingcorpus --tsv --patterns class3.lx | grep -w vertical | cut -f3 | sort | uniq -c | sort -rn | head
ling matches --corpus akutagawa-unidic-novel.lingcorpus --where '@document.title = 杜子春' --pattern '[lemma in {上る, 落ちる, 下りる}].' --context 4 --color never
Command or option Meaning
grep -w vertical Keep only the lines containing the word vertical
cut -f3 Keep only tab-separated column 3, the work’s file name
sort | uniq -c | sort -rn | head Count identical works, order by count, and show the first 10 lines (figure in section 2)
--where '@document.title = 杜子春' Narrow the search by information such as the title (@document.title)

The diagram below traces the output after each stage of the first command.

Output after each stage from --tsv to counts by work

ling matches --corpus akutagawa-unidic-novel.lingcorpus --tsv --patterns class3.lx

Print each match as one line of 10 tab-separated fields

  1. 12345678910
  2. 138verbsAkutagawa_R_Aguninokami.md01111113637落ち
  3. 139verticalAkutagawa_R_Aguninokami.md01111113637落ち
  4. 140verbsAkutagawa_R_Aguninokami.md011211234勇み立っ
  5. 53244verbsAkutagawa_R_Toshishun.md9298308111011落ち
  6. 53245verticalAkutagawa_R_Toshishun.md9298308111011落ち
  7. 53256verbsAkutagawa_R_Toshishun.md92103308161112見下し
  8. 53257verticalAkutagawa_R_Toshishun.md92103308161112見下し

7 lines

↓| grep -w vertical

Keep only the lines containing the word vertical

  1. 12345678910
  2. 138verbsAkutagawa_R_Aguninokami.md01111113637落ち
  3. 139verticalAkutagawa_R_Aguninokami.md01111113637落ち
  4. 140verbsAkutagawa_R_Aguninokami.md011211234勇み立っ
  5. 53244verbsAkutagawa_R_Toshishun.md9298308111011落ち
  6. 53245verticalAkutagawa_R_Toshishun.md9298308111011落ち
  7. 53256verbsAkutagawa_R_Toshishun.md92103308161112見下し
  8. 53257verticalAkutagawa_R_Toshishun.md92103308161112見下し

3 lines

↓| cut -f3

Keep only field 3

  1. 12345678910
  2. 139verticalAkutagawa_R_Aguninokami.md01111113637落ち
  3. 53245verticalAkutagawa_R_Toshishun.md9298308111011落ち
  4. 53257verticalAkutagawa_R_Toshishun.md92103308161112見下し

3 lines

↓| sort | uniq -c | sort -rn | head

Count as in the figure in section 2

  1. 2Akutagawa_R_Toshishun.md
  2. 1Akutagawa_R_Aguninokami.md

2 lines

Highlighted: field 3 (the work’s file name), which cut -f3 keeps. Field 9 is empty

Text: akutagawa-unidic-novel.lingcorpus. Stage 1 shows 7 of its 59,817 output lines.

In 「杜子春」, 登って来た matches the lemma 上る. The lemma also groups kanji spellings, so a string search for のぼ cannot find this passage. The counts over 103 works depend on the length of each work, its year, and the dictionary’s decisions.

  1. Choose one work with many matches, show its matches with --where, and read two passages in full paragraphs.
  2. Classify them with the same three judgments as for 「蜘蛛の糸」 and record whose viewpoint 来る and 行く mark.
  3. Write one claim the counts support and one they cannot establish.
What do the results over 103 works show?

If the class did not reach section 8, check these results in the saved outputs: the summary over 103 works, counts by work, and the matches in 「杜子春」. 「蜘蛛の糸」 is not among the 103 works.

  • Counts for the set: 11 of the 12 lemmas in vertical occur, 660 matches in all. 上る 183, 落ちる 178, and 下りる 103 make up about seven tenths of them. 這い上る has 3 and 追い上げる 0.
  • A lemma outside the set: the deixis table shows 下る with 来る 18 and 行く 9, but 下る is outside the vertical set. It is a candidate to add in section 5.
  • The 来る and 行く bias: in 「蜘蛛の糸」, climbing is told with both words, as in のぼって行け and のぼって来た, and falling once, as 落ちて来る. Over 103 works, 上る splits between 行く 19 and 来る 18, while 落ちる leans to 来る 14 against 行く 4. 下りる has 行く 19 and 来る 9.
  • Counts by work: 98 works have a match, from 45 in 「素戔嗚尊」 down to 1. 61 works have 5 or fewer. The counts depend on the length of each work, so class 4 compares works with a rate per 10,000 verbs.
  • Counts are not movements: of the 6 matches for the three lemmas in 「杜子春」, 竹杖が一本落ちている and 畜生道に落ちている describe states, not movement. 下りる occurs in the same work as both 下りて来る and 下りて行きました, so the viewpoint is decided passage by passage, not per work.

Exit note

Record these five items. You will also use class3.lx in class 4 on prepared corpora of other authors, so keep the class3-prepared folder and summary.txt in your working folder.

What to save Contents
Revised pattern The set you changed in class3.lx and why (section 5)
Missed lemma One movement lemma that string search missed (section 5)
Judgment cue One word form that cued a judgment (section 6)
Dictionary difference One lemma that changed under another analyzer (section 4)
Limit of the output One claim the output cannot establish (section 8)

Homework: record three passages you found as CSV rows 8–10

Allow 20–30 minutes. The class 2 worksheet is limited to seven rows, so add the three passages to the CSV. You will extend this CSV in class 4 (rows 11–12) and use it for the class 5 evidence assignment.

  1. Save the seven worksheet rows with example labels (CSV) into your working folder and open it in a plain-text editor.
  2. Choose one movement lemma from section 5, one match from section 6, and one match from section 7 or 8, and read the full paragraph of each passage. For a section 8 passage, write the work’s title in part.
  3. Add the three passages as rows 8–10 with the same columns and the values in the table below.
  4. Note the corpus, pattern, and count used for each row. Submit the CSV, your saved worksheet file dh-b-movement.json (if you attended class 2), and the notes before class 4 at the location in the submissions table. In class 4, you will compare the labels for rows 2–7 on the submission page.
Column Value
id, part, expression Row number, part or work title, and the source wording
actor Who moves; blank if unresolved
direction up, down, or other; unresolved when deferred
perspective narrator
factuality CT+, CT-, or Uu; blank when deferred
annotation_status labelled; deferred when you defer the judgment

Classification reference: column meanings and judgment criteria.

Search the course pages