wp2txt 2.3.4 → 2.5.0
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.
- checksums.yaml +4 -4
- data/.dockerignore +0 -4
- data/.github/workflows/ci.yml +16 -1
- data/.github/workflows/publish-image.yml +8 -4
- data/.gitignore +3 -6
- data/CHANGELOG.md +32 -0
- data/DEVELOPMENT.md +63 -93
- data/DEVELOPMENT_ja.md +61 -93
- data/Dockerfile +1 -1
- data/README.md +93 -8
- data/README_ja.md +84 -8
- data/Rakefile +10 -21
- data/bin/wp2txt +84 -15
- data/bin/wp2txt-mcp +1 -1
- data/docs/INDEXES.md +61 -1
- data/lib/wp2txt/article.rb +2 -3
- data/lib/wp2txt/bz2_stream.rb +63 -0
- data/lib/wp2txt/cli.rb +90 -26
- data/lib/wp2txt/config.rb +2 -11
- data/lib/wp2txt/constants.rb +13 -1
- data/lib/wp2txt/corpus.rb +10 -23
- data/lib/wp2txt/data/template_aliases.json +4 -1
- data/lib/wp2txt/data/template_patterns.json +61643 -0
- data/lib/wp2txt/dump_snapshot.rb +99 -0
- data/lib/wp2txt/extraction_run.rb +272 -0
- data/lib/wp2txt/extractor.rb +481 -327
- data/lib/wp2txt/formatter.rb +14 -12
- data/lib/wp2txt/fts_index.rb +1 -1
- data/lib/wp2txt/index_cache.rb +144 -55
- data/lib/wp2txt/index_commands.rb +109 -18
- data/lib/wp2txt/langlinks_importer.rb +19 -35
- data/lib/wp2txt/lead_terms.rb +228 -0
- data/lib/wp2txt/link_counter.rb +171 -0
- data/lib/wp2txt/magic_words.rb +44 -28
- data/lib/wp2txt/metadata_index.rb +82 -13
- data/lib/wp2txt/multistream.rb +911 -824
- data/lib/wp2txt/output_writer.rb +3 -1
- data/lib/wp2txt/page_props_importer.rb +170 -0
- data/lib/wp2txt/parser_functions.rb +23 -5
- data/lib/wp2txt/ractor_worker.rb +6 -4
- data/lib/wp2txt/regex.rb +24 -4
- data/lib/wp2txt/site_info.rb +123 -0
- data/lib/wp2txt/sql_dump_reader.rb +57 -0
- data/lib/wp2txt/stream_processor.rb +9 -2
- data/lib/wp2txt/stream_store.rb +91 -0
- data/lib/wp2txt/template_args.rb +111 -0
- data/lib/wp2txt/template_expander.rb +110 -124
- data/lib/wp2txt/template_patterns.rb +182 -0
- data/lib/wp2txt/utils.rb +164 -127
- data/lib/wp2txt/version.rb +1 -1
- data/lib/wp2txt/wikitext_regions.rb +66 -0
- data/spec/auto_download_spec.rb +9 -6
- data/spec/category_fetcher_spec.rb +135 -463
- data/spec/cli_targeted_spec.rb +60 -0
- data/spec/config_spec.rb +2 -15
- data/spec/constants_spec.rb +0 -4
- data/spec/docs_sync_spec.rb +3 -3
- data/spec/dump_fetch_spec.rb +293 -0
- data/spec/extraction_run_spec.rb +520 -0
- data/spec/index_build_spec.rb +113 -0
- data/spec/index_commands_version_spec.rb +17 -0
- data/spec/langlinks_importer_spec.rb +27 -0
- data/spec/lead_terms_edge_cases_spec.rb +194 -0
- data/spec/lead_terms_links_qids_spec.rb +204 -0
- data/spec/multistream_reader_spec.rb +140 -0
- data/spec/multistream_spec.rb +8 -214
- data/spec/output_integrity_spec.rb +45 -2
- data/spec/p1_correctness_spec.rb +12 -9
- data/spec/page_properties_spec.rb +161 -0
- data/spec/regex_spec.rb +30 -0
- data/spec/region_semantics_spec.rb +71 -0
- data/spec/spec_helper.rb +3 -3
- data/spec/support/dump_status.rb +34 -0
- data/spec/support/multistream_fixture.rb +26 -8
- data/spec/template_args_spec.rb +133 -0
- data/spec/template_expander_spec.rb +29 -111
- data/spec/template_passthrough_spec.rb +58 -0
- data/spec/template_patterns_spec.rb +253 -0
- data/spec/tracked_paths_spec.rb +168 -0
- data/spec/utils_spec.rb +7 -1
- metadata +45 -5
- data/lib/wp2txt/category_cache.rb +0 -313
- data/spec/category_cache_spec.rb +0 -226
data/DEVELOPMENT_ja.md
CHANGED
|
@@ -39,10 +39,14 @@ WP2TXTはWikipediaダンプを処理するためにストリーミングアー
|
|
|
39
39
|
| `StreamProcessor` | `lib/wp2txt/stream_processor.rb` | 適応的バッファリングで圧縮ダンプからページをストリーミング |
|
|
40
40
|
| `Article` | `lib/wp2txt/article.rb` | MediaWikiマークアップをパース |
|
|
41
41
|
| `OutputWriter` | `lib/wp2txt.rb` | 出力ファイルローテーションを管理 |
|
|
42
|
-
| `DumpManager` | `lib/wp2txt/multistream.rb` |
|
|
42
|
+
| `DumpManager` | `lib/wp2txt/multistream.rb` | ダンプの版を選び、ファイルをダウンロードして照合 |
|
|
43
|
+
| `DumpSnapshot` | `lib/wp2txt/dump_snapshot.rb` | Wikimediaの`dumpstatus.json`による、完了したダンプの一つの版 |
|
|
44
|
+
| `StreamStore` | `lib/wp2txt/stream_store.rb` | 対象を絞った抽出で取得したダンプの範囲 |
|
|
43
45
|
| `MultistreamIndex` | `lib/wp2txt/multistream.rb` | ランダムアクセス用に記事をインデックス化 |
|
|
44
|
-
| `MultistreamReader` | `lib/wp2txt/multistream.rb` |
|
|
45
|
-
| `
|
|
46
|
+
| `MultistreamReader` | `lib/wp2txt/multistream.rb` | 記事を読み、要求されたすべてのエントリの結果を報告 |
|
|
47
|
+
| `ExtractionRun` | `lib/wp2txt/extraction_run.rb` | 対象を絞った抽出の、題名ごとの結果、終了コード、マニフェスト |
|
|
48
|
+
| `SiteInfo` / `TitleNormalizer` | `lib/wp2txt/site_info.rb` | ウィキの名前空間と題名の規則 |
|
|
49
|
+
| `CategoryFetcher` | `lib/wp2txt/multistream.rb` | Wikipedia APIからカテゴリメンバーを一覧(すべて読めた場合だけ使う) |
|
|
46
50
|
| `MemoryMonitor` | `lib/wp2txt/memory_monitor.rb` | クロスプラットフォームメモリ監視 |
|
|
47
51
|
| `Bz2Validator` | `lib/wp2txt/bz2_validator.rb` | bz2ファイルの整合性を検証 |
|
|
48
52
|
| `CLI` | `lib/wp2txt/cli.rb` | コマンドラインオプションのパース |
|
|
@@ -52,7 +56,6 @@ WP2TXTはWikipediaダンプを処理するためにストリーミングアー
|
|
|
52
56
|
| クラス | ファイル | 目的 |
|
|
53
57
|
|--------|----------|------|
|
|
54
58
|
| `GlobalDataCache` | `lib/wp2txt/global_data_cache.rb` | パース済みJSONデータファイルのSQLiteキャッシュ |
|
|
55
|
-
| `CategoryCache` | `lib/wp2txt/category_cache.rb` | Wikipediaカテゴリ階層のSQLiteキャッシュ |
|
|
56
59
|
| `IndexCache` | `lib/wp2txt/index_cache.rb` | マルチストリームインデックスエントリのSQLiteキャッシュ |
|
|
57
60
|
|
|
58
61
|
### 要素タイプ
|
|
@@ -96,13 +99,22 @@ MARKER_TYPES = %i[math code chem table score timeline graph ipa].freeze
|
|
|
96
99
|
| テンプレートタイプ | 例 | 出力 |
|
|
97
100
|
|--------------------|-----|------|
|
|
98
101
|
| 生年月日/没年月日 | `{{birth date|1990|5|15}}` | "May 15, 1990" |
|
|
99
|
-
| 単位変換 | `{{convert|100|km|mi}}` | "100 km
|
|
102
|
+
| 単位変換 | `{{convert|100|km|mi}}` | "100 km"(書かれたとおり。換算値は計算しない) |
|
|
100
103
|
| 座標 | `{{coord|35|41|N|139|41|E}}` | "35°41′N 139°41′E" |
|
|
101
104
|
| 言語タグ | `{{lang|ja|日本語}}` | "日本語" |
|
|
102
105
|
| 仮名 | `{{nihongo|Tokyo|東京|Tōkyō}}` | "Tokyo (東京, Tōkyō)" |
|
|
103
106
|
|
|
104
107
|
テンプレート展開はデフォルトで有効です。`--no-expand-templates`または`expand_templates: false`で無効化できます。
|
|
105
108
|
|
|
109
|
+
引数は`TemplateArgs`(`lib/wp2txt/template_args.rb`)がMediaWikiと同じように読みます。設定でウィキを指定すると(`lang:`)、その版での表示が分かっているテンプレートは、まず`TemplatePatterns`が`lib/wp2txt/data/template_patterns.json`から表示します。引用と、規則で取り除くテンプレートは取り除いたままです。データは、各版のパーサーに、よく使われるテンプレートの表示を訊く保守用スクリプトで作ります:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
bundle exec ruby scripts/fetch_template_patterns.rb # すべての版
|
|
113
|
+
bundle exec ruby scripts/fetch_template_patterns.rb ja ko # 一部の版(ほかの版は残す)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
型は、表示された文字列に引数の枠を入れたものです(`"ドイツ語: {1}"`)。引数が一つまたは二つのときの変種(`p1`、`p2`)、言語コードの引数があるときのコードごとの型(`code_arg`、`by_code`)、名前のない引数の代わりに表示される名前付き引数(`replaces`)、空のときにテンプレートが別の引数で埋める引数(`fallback`)を持ちます。数を取るテンプレートは、学習した引数の数(`n`)を記録します。それより多い呼び出しや、最初が数でない呼び出しは、型がその表示を示さないので、ほかの規則に任せます。試したどの言語コードでも書かれたとおりに表示される引数は、コードではなく普通の引数です。どのコードでも何も変えない引数は、言語コードの書き方をしている場合(示す文字列の前にあり、ほかの引数がすべて表示される場合)に限ってコードとみなします。このとき型は、試した引数の数(`n`)と、別の表示になったり失敗したりしたコードがあれば型どおりに表示したコード(`codes`)を記録し、その形で、すべての引数があり、それらのコードのどれかを持つ呼び出しにだけ使います。それ以外の場合や、すでに見た呼び出しを型が別の表示にする場合は、ほかの形で試し、どれにも合わなければ未知とします。言語コードは数ではないので、コードの位置に数がある呼び出しにはコードの型を使いません。型が省く引数は表示を変えてはならず(日付として読める二組の数で試します)、変える場合は型を使いません。年だけを表示する日付テンプレートでは、残りが落ちるためです。テンプレート名の数字の並びにない固有の数字(どの文字体系でも)を持つ型(学習した日の日付、画像の大きさ)は使いません。`{{2e|voix}}`のように名前にある数字は、呼び出しに書かれています。読者に隠された文字列(`display:none`)と、編集プレビューでだけ出る警告は、型に含めません。波括弧を含む表示は、枠と読まれるので型にしません。試したどの引数でも、引数を一つも表示しないブロックだけで表示されるテンプレートは、空の型として記録します。ブロックが引数を表示するもの(リスト、中央寄せの行)や、何も表示しなかったものは未知とします。書かれた文字列を持つか、ほかの引数では文字列を表示しうるためです。名前付き引数は名前ごとに学びます。テンプレートのソースが読む名前(`{{{name|...}}}`)とTemplateDataに記された名前に、`label`、`lt`、`text`を加えた最大40個を、型を学んだ呼び出しに、目印、`y`、`no`のそれぞれ単独で与えます。どれでも表示を変えない名前は何も変えません(`ignores`)。目印が表示される名前は表示されます(`shows`)。名前のない引数の代わりに表示されるか(`replaces`)、独自の型を持ちます(`with`。`y`、数を取る引数では数も、同じ位置に表示される場合)。目印と`y`で同じように表示を変え、`no`でも同じように変えるか何も変えない名前も独自の型を持ち、何も変えない値(`no`と、`n`、`NO`、`No`、`false`、`0`、`off`のうち何も変えないもの)はオフと読みます(`off`)。続いて、すべての名前を一度に、名前のない引数ありとなしで与えます(失敗したら、何も変えなかった名前を一つずつ単独で与えます)。そこで表示された名前は、ほかの名前と並べたときだけ表示されるものとして、表示されるとみなします。呼び出しは、名前付き引数が何も変えないか、引数の代わりに立つか(引数ごとに最初に与えられたもの)、オフと読まれるか、未知である場合は型で表示します。ほかに既知の名前を与えず、その名前で学んだ型が呼び出し自身の型の引数を保ち(名前付き引数をその位置に表示する場合を除く)、呼び出しが空にした引数に文字列が接しない場合は、その名前で学んだ型で表示します。それ以外は、呼び出しの型に続けて、テンプレートが表示する名前付き引数のうち語か数を含む値を、呼び出しの順に一度ずつ表示します。ブロックのマーカー(`[INFOBOX]`、`[REFERENCES]`)で表すテンプレートのうち、型が何も表示しないものはマーカーに任せます。値は、本文がすでにそれを表示していれば表示済みとみなします(リンクは表示される文字列として読みます)。n個の引数から学んだコードの型は、未知の名前付き引数を持つ呼び出しには使いません。既知でも規則で扱うものでもないテンプレートはクリーナーに任せ、クリーナーは最初の名前のない引数を残します(別の引数の前にある言語コードは飛ばします)。テンプレートが表示するものの「=」は、format_wikiが終わるまで置き換え文字で保ち、外側のテンプレートが引数名の区切りと読まないようにします。全体の実行には、毎秒1リクエストで数時間かかります。
|
|
117
|
+
|
|
106
118
|
### マジックワード展開
|
|
107
119
|
|
|
108
120
|
`MagicWordExpander`クラス(`lib/wp2txt/magic_words.rb`)はMediaWikiマジックワードを実際の値に展開します:
|
|
@@ -139,28 +151,6 @@ Wp2txt::GlobalDataCache.stats # キャッシュ統計を取得
|
|
|
139
151
|
|
|
140
152
|
キャッシュ検証:ソースファイルの変更時刻とサイズをチェックします。ソースファイルが変更されると自動的にキャッシュは無効化されます。
|
|
141
153
|
|
|
142
|
-
### CategoryCache
|
|
143
|
-
|
|
144
|
-
Wikipedia APIからのカテゴリ階層をキャッシュし、カテゴリベースの記事抽出を高速化:
|
|
145
|
-
|
|
146
|
-
```ruby
|
|
147
|
-
cache = Wp2txt::CategoryCache.new("en", cache_dir: "/path/to/cache")
|
|
148
|
-
|
|
149
|
-
# カテゴリデータを保存
|
|
150
|
-
cache.save("カテゴリ名", ["記事1", "記事2"], ["サブカテゴリ1"])
|
|
151
|
-
|
|
152
|
-
# カテゴリデータを取得
|
|
153
|
-
data = cache.get("カテゴリ名") # { pages: [...], subcats: [...] }
|
|
154
|
-
|
|
155
|
-
# カテゴリツリー内のすべてのページを取得
|
|
156
|
-
pages = cache.get_all_pages("ルートカテゴリ", max_depth: 2)
|
|
157
|
-
|
|
158
|
-
# 統計とメンテナンス
|
|
159
|
-
cache.stats # キャッシュ統計
|
|
160
|
-
cache.cleanup_expired! # 古いエントリを削除
|
|
161
|
-
cache.clear! # すべてクリア
|
|
162
|
-
```
|
|
163
|
-
|
|
164
154
|
### IndexCache
|
|
165
155
|
|
|
166
156
|
パース済みマルチストリームインデックスエントリをキャッシュし、記事の高速検索を実現:
|
|
@@ -171,12 +161,12 @@ cache = Wp2txt::IndexCache.new("/path/to/index.txt", cache_dir: "/path/to/cache"
|
|
|
171
161
|
# キャッシュの有効性を確認
|
|
172
162
|
cache.valid? # キャッシュが存在しソースファイルと一致する場合 true
|
|
173
163
|
|
|
174
|
-
#
|
|
175
|
-
cache.
|
|
176
|
-
data = cache.load # { entries_by_title: {}, entries_by_id: {}, stream_offsets: [] }
|
|
164
|
+
# インデックスファイルから1行ずつ一時ファイルに作り、置き換える
|
|
165
|
+
cache.build!
|
|
177
166
|
|
|
178
167
|
# バッチ検索
|
|
179
168
|
results = cache.find_by_titles(["記事1", "記事2"])
|
|
169
|
+
results = cache.find_by_ids([12345])
|
|
180
170
|
```
|
|
181
171
|
|
|
182
172
|
### キャッシュの場所
|
|
@@ -185,10 +175,13 @@ results = cache.find_by_titles(["記事1", "記事2"])
|
|
|
185
175
|
|
|
186
176
|
```
|
|
187
177
|
~/.wp2txt/cache/
|
|
188
|
-
├── global_data.sqlite3
|
|
189
|
-
├──
|
|
190
|
-
├──
|
|
191
|
-
└──
|
|
178
|
+
├── global_data.sqlite3 # GlobalDataCache
|
|
179
|
+
├── enwiki-<date>-multistream-index.txt.bz2 # 使用中の版のファイル(ハードリンク)
|
|
180
|
+
├── enwiki-<date>-multistream-index.txt_*.sqlite3 # IndexCache(インデックスファイルごと)
|
|
181
|
+
└── enwiki-<date>-<snapshot>/ # ダンプの一つの版
|
|
182
|
+
├── dumpstatus.json
|
|
183
|
+
├── <公式のファイル名> # 照合済みのファイル(ハードリンク)
|
|
184
|
+
└── streams/ # StreamStoreの範囲
|
|
192
185
|
```
|
|
193
186
|
|
|
194
187
|
## テストシステム
|
|
@@ -232,81 +225,42 @@ WP2TXTは効率的な記事抽出のためにWikipediaのマルチストリー
|
|
|
232
225
|
1. **インデックスファイル** (`-multistream-index.txt.bz2`): 記事タイトルをバイトオフセットにマッピング
|
|
233
226
|
2. **マルチストリームファイル** (`-multistream.xml.bz2`): 連結されたbz2ストリーム
|
|
234
227
|
|
|
235
|
-
###
|
|
228
|
+
### 記事の読み取り
|
|
236
229
|
|
|
237
|
-
`MultistreamReader
|
|
230
|
+
`MultistreamReader#each_entry_result`は、要求されたすべてのエントリについて結果を報告し、黙って欠けることがないようにします:
|
|
238
231
|
|
|
239
232
|
```ruby
|
|
240
|
-
reader = MultistreamReader.new(multistream_path,
|
|
241
|
-
|
|
242
|
-
#
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
# 並列処理でイテレート
|
|
246
|
-
reader.each_article_parallel(entries, num_processes: 4) do |page|
|
|
247
|
-
process(page)
|
|
233
|
+
reader = MultistreamReader.new(multistream_path, index)
|
|
234
|
+
reader.each_entry_result(entries, num_processes: 4) do |entry, page, error|
|
|
235
|
+
# page: 読んだページ(ns、redirect、text_availableを持つ)。範囲にそのページが無ければnil
|
|
236
|
+
# error: 範囲を読めなかったときの { reason:, message: }
|
|
248
237
|
end
|
|
249
238
|
```
|
|
250
239
|
|
|
251
|
-
|
|
240
|
+
エントリはストリームオフセットでまとめるので、各bz2ストリームは一度だけ解凍します。最後まで解凍できないストリームは、短くなったページを返さず`StreamError`を発生させます。
|
|
252
241
|
|
|
253
|
-
###
|
|
242
|
+
### ダンプの版と部分ダウンロード
|
|
254
243
|
|
|
255
|
-
|
|
244
|
+
`DumpManager`は一つの`DumpSnapshot`を使います。`dump_date:`で指定した日付、なければ完了した最新の版(ネットワークでの確認は`dump_expiry_days`ごとに最大1回)、オフラインならキャッシュにある最新の版です。すべてのファイルを、その版の`dumpstatus.json`にあるサイズとSHA-1で照合し、`<cache>/<lang>wiki-<date>-<snapshot>/`にハードリンクで保存します。
|
|
256
245
|
|
|
257
|
-
|
|
258
|
-
# 最初のNストリームのみダウンロード
|
|
259
|
-
manager.download_multistream(max_streams: 10)
|
|
260
|
-
|
|
261
|
-
# 必要なバイト範囲のみダウンロード
|
|
262
|
-
download_file_range(url, path, start_byte, end_byte)
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
### 差分ダウンロード
|
|
266
|
-
|
|
267
|
-
部分ダンプが存在する場合、`download_multistream_full`はダウンロードを再開できます:
|
|
246
|
+
対象を絞った抽出では、ダンプの必要な範囲だけを取得します:
|
|
268
247
|
|
|
269
248
|
```ruby
|
|
270
249
|
manager = DumpManager.new("ja")
|
|
271
|
-
|
|
272
|
-
# 既存の部分ダンプを確認
|
|
273
|
-
partial = manager.find_any_partial_cache
|
|
274
|
-
# => { path: "...", dump_date: "20260101", stream_count: 100, size: 1000000, mtime: ... }
|
|
275
|
-
|
|
276
|
-
# 差分ダウンロードが可能か確認
|
|
277
|
-
resume_info = manager.can_resume_from_partial?(partial)
|
|
278
|
-
# => { possible: true, current_streams: 100, total_streams: 5000, current_size: 1000000 }
|
|
279
|
-
# => { possible: false, reason: :date_mismatch, partial_date: "20250101", latest_date: "20260101" }
|
|
280
|
-
|
|
281
|
-
# 差分ダウンロードサポート付きでフルダンプをダウンロード(対話式プロンプト)
|
|
282
|
-
path = manager.download_multistream_full(interactive: true)
|
|
283
|
-
|
|
284
|
-
# 非対話モード(ユーザープロンプトをスキップ、必要に応じて常に新規ダウンロード)
|
|
285
|
-
path = manager.download_multistream_full(interactive: false)
|
|
250
|
+
store = manager.fetch_streams([[offset, end_offset]]) # HTTPのRange要求、同時に最大2つ
|
|
286
251
|
```
|
|
287
252
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
1. **同一日付の部分ダンプが存在:**
|
|
291
|
-
- `[Y]` ダウンロードを再開(残りのデータのみダウンロード)
|
|
292
|
-
- `[n]` 既存の部分ダンプをそのまま使用
|
|
293
|
-
- `[f]` 新規フルダンプをダウンロード
|
|
294
|
-
|
|
295
|
-
2. **古い部分ダンプが存在:**
|
|
296
|
-
- `[D]` 古い部分を削除して最新をダウンロード(推奨)
|
|
297
|
-
- `[k]` 古い部分を保持、最新を別途ダウンロード
|
|
298
|
-
- `[u]` 古い部分をそのまま使用(内容が古い可能性あり)
|
|
253
|
+
各範囲は`StreamStore`に、バイト範囲とSHA-1を名前にした個別のファイルとして、最後まで解凍できた場合だけ保存します。取得できなかった範囲は保存せず、読もうとすると`StreamUnavailableError`を発生させます。
|
|
299
254
|
|
|
300
255
|
### 記事抽出フロー
|
|
301
256
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
```
|
|
257
|
+
1. ダンプの版を選び、そのインデックスをダウンロード
|
|
258
|
+
2. インデックスキャッシュ(SQLite)をインデックスファイルごとに一度だけ作成
|
|
259
|
+
3. 要求された題名をウィキのサイト情報で正規化して検索
|
|
260
|
+
4. 転送を1段階たどる
|
|
261
|
+
5. 記事を含む範囲を取得
|
|
262
|
+
6. すべてのエントリを読み、結果を`ExtractionRun`に記録
|
|
263
|
+
7. 出力ファイルとマニフェストをまとめて公開
|
|
310
264
|
|
|
311
265
|
## メモリ管理
|
|
312
266
|
|
|
@@ -397,12 +351,26 @@ docs/INDEXES.md の MCP ツール表は spec/docs_sync_spec.rb が実際のサ
|
|
|
397
351
|
- RuboCop設定は`.rubocop.yml`
|
|
398
352
|
- 全体でUTF-8エンコーディング
|
|
399
353
|
|
|
354
|
+
## 追跡するファイル
|
|
355
|
+
|
|
356
|
+
追跡するファイルはすべて `scripts/tracked_paths.allow` のどれかの行に合い、各行もどれかの
|
|
357
|
+
追跡ファイルに合う必要がある。gem は `git ls-files` から作られるので、コミットは公開の第一歩になる。
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
ruby scripts/check_tracked_paths.rb # index(次のコミットの中身)を検査
|
|
361
|
+
ruby scripts/check_tracked_paths.rb --tree HEAD # コミットを、その中の許可リストで検査
|
|
362
|
+
ln -s ../../scripts/pre-push .git/hooks/pre-push # push する各コミットを送信前に検査
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
CI も最初にこの検査を走らせる。新しいファイルを追跡するときは、その場所と種類を表す
|
|
366
|
+
最も狭い行を足し(Markdown は 1 本ずつ名前で書く)、許可リストも一緒にステージする。
|
|
367
|
+
|
|
400
368
|
## Docker
|
|
401
369
|
|
|
402
370
|
Dockerイメージのビルドとプッシュ:
|
|
403
371
|
|
|
404
372
|
```bash
|
|
405
|
-
rake check_image #
|
|
373
|
+
rake check_image # 最新のコミットのクリーンな複製からビルドし、CI と同じゲートを走らせる
|
|
406
374
|
```
|
|
407
375
|
|
|
408
376
|
## リリースプロセス
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
|
@@ -110,7 +110,11 @@ This automatically downloads the English Wikipedia dump and extracts plain text.
|
|
|
110
110
|
|
|
111
111
|
$ wp2txt --lang=en --articles="Cognitive linguistics,Generative grammar" -o ./articles
|
|
112
112
|
|
|
113
|
-
Only the index file and
|
|
113
|
+
Only the index file and the parts of the dump that hold the requested articles are downloaded, a few megabytes wherever the articles sit. They are kept in the cache for later runs.
|
|
114
|
+
|
|
115
|
+
Titles are matched the way Wikipedia writes them: underscores, a lower-case first letter, and namespace prefixes in English or in the wiki's language are accepted. A redirect is followed one step and its article is written under the title you asked for; `--no-follow-redirects` extracts the redirect page itself. For titles that contain commas, list them one per line in a file:
|
|
116
|
+
|
|
117
|
+
$ wp2txt --lang=en --articles-file=titles.txt -o ./articles
|
|
114
118
|
|
|
115
119
|
### Extract articles from a category
|
|
116
120
|
|
|
@@ -124,6 +128,39 @@ Preview without downloading (shows article counts):
|
|
|
124
128
|
|
|
125
129
|
$ wp2txt --lang=en --from-category="Cities in Japan" --dry-run
|
|
126
130
|
|
|
131
|
+
A category that cannot be listed in full stops the extraction. Add `--allow-incomplete-category` to extract what was listed; the manifest then records the listing as incomplete.
|
|
132
|
+
|
|
133
|
+
### Results of a targeted extraction
|
|
134
|
+
|
|
135
|
+
With `--articles`, `--articles-file`, or `--from-category`, every requested title ends in one of three ways: written, skipped by `--skip-empty`, or failed with a reason. The exit code tells which:
|
|
136
|
+
|
|
137
|
+
| Exit code | Meaning |
|
|
138
|
+
|-----------|---------|
|
|
139
|
+
| 0 | Every requested title was written or skipped |
|
|
140
|
+
| 2 | Some titles failed; the others were written |
|
|
141
|
+
| 1 | Nothing could be written, or the run stopped |
|
|
142
|
+
|
|
143
|
+
A manifest is written next to the output files: `enwiki_articles.manifest.json` for `--articles` on English Wikipedia, or the category name in place of `articles` for `--from-category`. It gives the dump version used (`source`), the result of each requested title (`requests`, with the title it was found under), the counts, and the files written. A title that reaches an article already written for another title is marked `same_as` that title, and `records` counts each article once:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"run_id": "…",
|
|
148
|
+
"wp2txt_version": "2.5.0",
|
|
149
|
+
"template_patterns": "…",
|
|
150
|
+
"exit_code": 2,
|
|
151
|
+
"source": {"lang": "en", "date": "20261101", "snapshot": "…", "chosen": "recent"},
|
|
152
|
+
"counts": {"requested": 3, "located": 2, "retrieved": 2, "written": 2, "records": 2, "skipped_empty": 0, "failed": 1},
|
|
153
|
+
"requests": [
|
|
154
|
+
{"requested_title": "tokyo", "status": "written", "title": "Tokyo"},
|
|
155
|
+
{"requested_title": "NYC", "status": "written", "title": "New York City"},
|
|
156
|
+
{"requested_title": "No such page", "status": "failed", "reason": "not_found"}
|
|
157
|
+
],
|
|
158
|
+
"output_files": ["enwiki_articles.txt"]
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Failure reasons: `not_found` (no such title in the dump), `redirect_unresolved` (a redirect whose target is missing, another redirect, or on another wiki), `text_unavailable` (the dump holds no text for the page), `truncated` or `stream_unavailable` (the part of the dump holding the page could not be read or fetched), and `index_mismatch` or `identity_mismatch` (the index and the dump disagree). Rerunning to the same output replaces the files the previous manifest lists. A run that fails leaves no manifest.
|
|
163
|
+
|
|
127
164
|
### Process local dump file
|
|
128
165
|
|
|
129
166
|
$ wp2txt -i ./enwiki-20220801-pages-articles.xml.bz2 -o ./text
|
|
@@ -177,6 +214,45 @@ Each line contains one JSON object:
|
|
|
177
214
|
|
|
178
215
|
`page_id` and `revision_id` are the dump's own `<id>` values for the page and its
|
|
179
216
|
revision, so a record can be traced back to the exact version of the article it came from.
|
|
217
|
+
If page properties have been imported into the dump's metadata index
|
|
218
|
+
(`--import-page-props`, see [docs/INDEXES.md](docs/INDEXES.md)), three fields always
|
|
219
|
+
follow the source IDs: `qid`, `sort_key`, and `disambiguation`. Missing QIDs and sort
|
|
220
|
+
keys are `null`; an absent disambiguation flag is `false`. Before import, all three
|
|
221
|
+
fields are omitted.
|
|
222
|
+
|
|
223
|
+
`disambiguation` is MediaWiki's own flag, which identifies pages that a title-based
|
|
224
|
+
check would miss. `sort_key` is the stored sorting key, whose meaning varies by wiki:
|
|
225
|
+
Japanese Wikipedia commonly uses normalized readings without voicing marks and with
|
|
226
|
+
small kana enlarged; English Wikipedia may use "surname, given name". It is not a
|
|
227
|
+
reading itself, but can be used to compare reading candidates. WP2TXT returns the
|
|
228
|
+
stored value without interpreting it.
|
|
229
|
+
|
|
230
|
+
With `--lead-terms`, each record also lists the terms the article introduces in its lead:
|
|
231
|
+
|
|
232
|
+
```json
|
|
233
|
+
"lead_terms": [
|
|
234
|
+
{"index": 0, "text": "東京", "notes": ["とうきょう", "Tokyo"], "notes_text": "とうきょう、Tokyo",
|
|
235
|
+
"source": "bold", "span": {"bold": [0, 8], "paren": [8, 21]}}
|
|
236
|
+
]
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
- `source: "bold"` — a bold term in the first lead paragraph that has one (up to five),
|
|
240
|
+
with the parenthesized text written right after it, split at top-level commas and
|
|
241
|
+
semicolons into `notes` (`notes_text` keeps it unsplit). Bold text inside templates,
|
|
242
|
+
image captions, references, literal regions such as `nowiki` and `pre`, and
|
|
243
|
+
`gallery`/`timeline` content is not counted. `code` is an ordinary formatting tag:
|
|
244
|
+
bold text inside it can be a lead term.
|
|
245
|
+
- `source: <template name>` — a reading template such as `{{読み仮名}}`, reported as
|
|
246
|
+
`text` and `reading`.
|
|
247
|
+
- `span` gives character offsets `[start, end)` into the article's wikitext as stored in
|
|
248
|
+
the dump (XML entities decoded, nothing else changed), so the source of each term can be
|
|
249
|
+
cut out and checked later.
|
|
250
|
+
- Nothing is interpreted: whether a note is a reading, a native spelling, or a date is left
|
|
251
|
+
to you.
|
|
252
|
+
|
|
253
|
+
`--lead-terms` cannot be combined with `--ractor`. The experimental Ractor JSON path
|
|
254
|
+
also omits page IDs and revision IDs; the CLI warns when it is selected. Imported
|
|
255
|
+
page properties are attached in the parent process on this path too.
|
|
180
256
|
|
|
181
257
|
For redirect articles:
|
|
182
258
|
|
|
@@ -189,9 +265,13 @@ For redirect articles:
|
|
|
189
265
|
$ wp2txt --cache-status # Show cache status
|
|
190
266
|
$ wp2txt --cache-clear # Clear all cache
|
|
191
267
|
$ wp2txt --cache-clear --lang=en # Clear cache for English only
|
|
192
|
-
$ wp2txt --update-cache #
|
|
268
|
+
$ wp2txt --update-cache # Check for a newer dump version now
|
|
269
|
+
|
|
270
|
+
wp2txt uses the newest dump that Wikimedia marks finished. It checks for a newer version at most once per `dump_expiry_days` (default: 30); `--update-cache` checks at once. `--dump-date YYYYMMDD` uses a given version instead:
|
|
193
271
|
|
|
194
|
-
|
|
272
|
+
$ wp2txt --lang=en --dump-date=20261101 --articles="Tokyo" -o ./articles
|
|
273
|
+
|
|
274
|
+
Cached files are checked against the sizes and SHA-1 digests Wikimedia publishes for that version. A cached file that does not match is set aside as `<name>.bad-<time>` and fetched again. Without a network connection, the newest version in the cache is used. Each version's files are kept in their own directory by hard link, so the cache directory must be on a file system that allows hard links.
|
|
195
275
|
|
|
196
276
|
## Advanced Options
|
|
197
277
|
|
|
@@ -234,12 +314,14 @@ Configure with `--markers`:
|
|
|
234
314
|
|
|
235
315
|
### Template Expansion
|
|
236
316
|
|
|
237
|
-
|
|
317
|
+
Templates are expanded by default. On the Japanese, English, German, French, Spanish, Italian, Russian, Chinese, Portuguese, Dutch, Polish, Arabic, and Korean editions, the most used inline templates are shown the way that edition shows them, from patterns learned from its own output: `{{lang-de|Wort}}` comes out as "ドイツ語: Wort" on the Japanese edition and "German: Wort" on the English one. Templates that compute their output (unit conversions, ages, coordinates) are not reproduced; the values written in the article are kept. Ages count from the dump's date. A template wp2txt does not know is replaced by its first unnamed argument, passing over a language code before another argument.
|
|
318
|
+
|
|
319
|
+
Other common templates are expanded by wp2txt's own rules:
|
|
238
320
|
|
|
239
321
|
| Template | Output |
|
|
240
322
|
|----------|--------|
|
|
241
323
|
| `{{birth date\|1990\|5\|15}}` | May 15, 1990 |
|
|
242
|
-
| `{{convert\|100\|km\|mi}}` | 100 km
|
|
324
|
+
| `{{convert\|100\|km\|mi}}` | 100 km |
|
|
243
325
|
| `{{coord\|35\|41\|N\|139\|41\|E}}` | 35°41′N 139°41′E |
|
|
244
326
|
| `{{lang\|ja\|日本語}}` | 日本語 |
|
|
245
327
|
| `{{nihongo\|Tokyo\|東京\|Tōkyō}}` | Tokyo (東京, Tōkyō) |
|
|
@@ -288,11 +370,15 @@ full-text search, interlanguage links, cross-language SQL, and the full MCP tool
|
|
|
288
370
|
-i, --input=<s> Path to compressed file (bz2) or XML file
|
|
289
371
|
-L, --lang=<s> Wikipedia language code (e.g., ja, en, de)
|
|
290
372
|
-A, --articles=<s> Specific article titles (comma-separated)
|
|
373
|
+
--articles-file=<s> File of article titles, one per line
|
|
374
|
+
-w, --no-follow-redirects Extract redirect pages themselves
|
|
291
375
|
-G, --from-category=<s> Extract articles from Wikipedia category
|
|
292
376
|
-D, --depth=<i> Subcategory recursion depth (default: 0)
|
|
293
377
|
-y, --yes Skip confirmation prompt
|
|
294
378
|
--dry-run Preview category extraction
|
|
295
|
-
|
|
379
|
+
--allow-incomplete-category Extract what was listed when a category cannot be listed in full
|
|
380
|
+
-U, --update-cache Check for the newest dump version now
|
|
381
|
+
--dump-date=<s> Use the dump of this date (YYYYMMDD)
|
|
296
382
|
|
|
297
383
|
Output options:
|
|
298
384
|
-o, --output-dir=<s> Output directory (default: current)
|
|
@@ -372,8 +458,7 @@ This creates `~/.wp2txt/config.yml`:
|
|
|
372
458
|
|
|
373
459
|
```yaml
|
|
374
460
|
cache:
|
|
375
|
-
dump_expiry_days: 30 # Days
|
|
376
|
-
category_expiry_days: 7 # Category cache expiry (1-90)
|
|
461
|
+
dump_expiry_days: 30 # Days between checks for a newer dump version (1-365)
|
|
377
462
|
directory: ~/.wp2txt/cache
|
|
378
463
|
|
|
379
464
|
defaults:
|
data/README_ja.md
CHANGED
|
@@ -94,7 +94,11 @@ docker run -it -v /path/to/localdata:/data ghcr.io/yohasebe/wp2txt
|
|
|
94
94
|
|
|
95
95
|
$ wp2txt --lang=ja --articles="認知言語学,生成文法" -o ./articles
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
インデックスファイルと、指定した記事を含むダンプの部分だけをダウンロードします。記事がダンプのどこにあっても数メガバイトで済み、取得した部分は次回以降のためにキャッシュに残ります。
|
|
98
|
+
|
|
99
|
+
タイトルはWikipediaの書き方どおりに照合します。アンダースコア、先頭の小文字、英語または各言語の名前空間接頭辞を受け付けます。リダイレクトは一段たどり、その記事を指定したタイトルで書き出します。`--no-follow-redirects` を付けるとリダイレクトのページそのものを抽出します。カンマを含むタイトルは、1行に1つずつファイルに書いて渡します:
|
|
100
|
+
|
|
101
|
+
$ wp2txt --lang=ja --articles-file=titles.txt -o ./articles
|
|
98
102
|
|
|
99
103
|
### カテゴリから記事を抽出
|
|
100
104
|
|
|
@@ -108,6 +112,39 @@ docker run -it -v /path/to/localdata:/data ghcr.io/yohasebe/wp2txt
|
|
|
108
112
|
|
|
109
113
|
$ wp2txt --lang=ja --from-category="日本の都市" --dry-run
|
|
110
114
|
|
|
115
|
+
カテゴリの一覧を最後まで取得できなかったときは抽出を中止します。`--allow-incomplete-category` を付けると取得できた分を抽出し、一覧が不完全だったことをマニフェストに記録します。
|
|
116
|
+
|
|
117
|
+
### 記事・カテゴリ指定の抽出結果
|
|
118
|
+
|
|
119
|
+
`--articles`、`--articles-file`、`--from-category` では、指定したタイトルはそれぞれ「書き出し」「`--skip-empty` による省略」「理由つきの失敗」のいずれかで終わります。終了コードでどれだったかが分かります:
|
|
120
|
+
|
|
121
|
+
| 終了コード | 意味 |
|
|
122
|
+
|-----------|------|
|
|
123
|
+
| 0 | 指定したタイトルはすべて書き出しまたは省略 |
|
|
124
|
+
| 2 | 一部のタイトルが失敗し、残りは書き出し |
|
|
125
|
+
| 1 | 何も書き出せなかった、または途中で止まった |
|
|
126
|
+
|
|
127
|
+
出力ファイルの隣にマニフェストを書き出します(日本語版の `--articles` なら `jawiki_articles.manifest.json`、`--from-category` では `articles` の代わりにカテゴリ名)。使ったダンプの版(`source`)、指定した各タイトルの結果(`requests`、見つかったタイトルを含む)、件数、書き出したファイルを記録します。別のタイトルですでに書き出した記事に行き着いたタイトルには `same_as` でそのタイトルを示し、`records` は記事を1件ずつ数えます:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"run_id": "…",
|
|
132
|
+
"wp2txt_version": "2.5.0",
|
|
133
|
+
"template_patterns": "…",
|
|
134
|
+
"exit_code": 2,
|
|
135
|
+
"source": {"lang": "ja", "date": "20261101", "snapshot": "…", "chosen": "recent"},
|
|
136
|
+
"counts": {"requested": 3, "located": 2, "retrieved": 2, "written": 2, "records": 2, "skipped_empty": 0, "failed": 1},
|
|
137
|
+
"requests": [
|
|
138
|
+
{"requested_title": "東京", "status": "written", "title": "東京"},
|
|
139
|
+
{"requested_title": "京都", "status": "written", "title": "京都"},
|
|
140
|
+
{"requested_title": "存在しないページ", "status": "failed", "reason": "not_found"}
|
|
141
|
+
],
|
|
142
|
+
"output_files": ["jawiki_articles.txt"]
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
失敗の理由: `not_found`(ダンプにそのタイトルがない)、`redirect_unresolved`(リダイレクト先がない、さらにリダイレクト、または別のウィキ)、`text_unavailable`(ダンプにそのページの本文がない)、`truncated` と `stream_unavailable`(そのページを含むダンプの部分を読めない、または取得できない)、`index_mismatch` と `identity_mismatch`(索引とダンプが食い違う)。同じ出力先で再実行すると、前回のマニフェストに載っているファイルを置き換えます。失敗した実行はマニフェストを残しません。
|
|
147
|
+
|
|
111
148
|
### ローカルダンプファイルを処理
|
|
112
149
|
|
|
113
150
|
$ wp2txt -i ./jawiki-20220801-pages-articles.xml.bz2 -o ./text
|
|
@@ -161,6 +198,36 @@ CATEGORIES: カテゴリ1, カテゴリ2, カテゴリ3
|
|
|
161
198
|
|
|
162
199
|
`page_id` と `revision_id` はダンプに記録されたページと版の `<id>` です。各レコードが
|
|
163
200
|
どの記事のどの版から取り出されたかを後から辿れます。
|
|
201
|
+
そのダンプのメタデータ索引にページ属性を取り込んである場合(`--import-page-props`、
|
|
202
|
+
[docs/INDEXES.md](docs/INDEXES.md) 参照)、その後に `qid`・`sort_key`・`disambiguation` の3項目が常に続きます。
|
|
203
|
+
QID・並べ替えの鍵がなければ `null`、曖昧さ回避の印がなければ `false`。未取り込みなら3項目とも出しません。
|
|
204
|
+
|
|
205
|
+
`disambiguation` は MediaWiki 自身の印で、題名の形だけでは拾えない曖昧さ回避ページも識別できます。
|
|
206
|
+
`sort_key` の意味は言語版ごとに異なります。日本語版では通常、濁点・半濁点を落とし、小書きの仮名を
|
|
207
|
+
大書きにした並べ替え用の読み(例: 言語→「けんこ」)、英語版では「姓, 名」の形などです。
|
|
208
|
+
読みそのものではありませんが、読みの候補の照合に使えます。WP2TXT は値を解釈せず、そのまま渡します。
|
|
209
|
+
|
|
210
|
+
`--lead-terms` を付けると、記事の導入部で示される語の一覧も出力します:
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
"lead_terms": [
|
|
214
|
+
{"index": 0, "text": "東京", "notes": ["とうきょう", "Tokyo"], "notes_text": "とうきょう、Tokyo",
|
|
215
|
+
"source": "bold", "span": {"bold": [0, 8], "paren": [8, 21]}}
|
|
216
|
+
]
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
- `source: "bold"` — 導入部で太字を含む最初の段落の太字(最大5個)と、その直後の括弧の中身。
|
|
220
|
+
括弧の中身は最上位の読点・カンマ・セミコロンで区切って `notes` に入れる(`notes_text` は区切る前)。
|
|
221
|
+
テンプレート・画像の説明文・脚注、`nowiki`・`pre` などの字義どおりの領域、および
|
|
222
|
+
`gallery`・`timeline` の太字は対象外。`code` は通常の書式タグなので、中の太字も対象
|
|
223
|
+
- `source: <テンプレート名>` — `{{読み仮名}}` などの読みのテンプレート。`text` と `reading` の組
|
|
224
|
+
- `span` はダンプに記録された記事の wikitext(XML の実体参照を戻しただけのもの)での文字位置
|
|
225
|
+
`[開始, 終了)`。各語の根拠をあとから切り出して確かめられる
|
|
226
|
+
- 解釈はしない。括弧の中のどれが読みで、どれが原語や日付かの判断は利用側に任せる
|
|
227
|
+
|
|
228
|
+
`--lead-terms` と `--ractor` は併用できません。実験的な Ractor 経路の JSON には
|
|
229
|
+
ページ ID・リビジョン ID が含まれないため、選択時に警告します。取り込み済みの属性3項目は、
|
|
230
|
+
この経路でも親プロセス側で付与します。
|
|
164
231
|
|
|
165
232
|
リダイレクト記事の場合:
|
|
166
233
|
|
|
@@ -173,9 +240,13 @@ CATEGORIES: カテゴリ1, カテゴリ2, カテゴリ3
|
|
|
173
240
|
$ wp2txt --cache-status # キャッシュ状態を表示
|
|
174
241
|
$ wp2txt --cache-clear # 全キャッシュをクリア
|
|
175
242
|
$ wp2txt --cache-clear --lang=ja # 日本語のみクリア
|
|
176
|
-
$ wp2txt --update-cache #
|
|
243
|
+
$ wp2txt --update-cache # 新しいダンプの版を今すぐ確認
|
|
244
|
+
|
|
245
|
+
wp2txtはWikimediaが完了としている最新のダンプを使います。新しい版の確認は `dump_expiry_days`(デフォルト: 30日)に1回までで、`--update-cache` を付けるとすぐに確認します。`--dump-date YYYYMMDD` で版を指定することもできます:
|
|
177
246
|
|
|
178
|
-
|
|
247
|
+
$ wp2txt --lang=ja --dump-date=20261101 --articles="東京" -o ./articles
|
|
248
|
+
|
|
249
|
+
キャッシュしたファイルは、Wikimediaがその版について公開しているサイズとSHA-1ダイジェストで照合します。一致しないファイルは `<name>.bad-<time>` として退避し、取得し直します。ネットワークにつながらないときは、キャッシュにある最新の版を使います。版ごとのファイルはハードリンクで専用のディレクトリに置くため、キャッシュディレクトリはハードリンクを作れるファイルシステム上に置いてください。
|
|
179
250
|
|
|
180
251
|
## 詳細オプション
|
|
181
252
|
|
|
@@ -218,12 +289,14 @@ CATEGORIES: カテゴリ1, カテゴリ2, カテゴリ3
|
|
|
218
289
|
|
|
219
290
|
### テンプレート展開
|
|
220
291
|
|
|
221
|
-
|
|
292
|
+
テンプレートはデフォルトで展開します。日本語、英語、ドイツ語、フランス語、スペイン語、イタリア語、ロシア語、中国語、ポルトガル語、オランダ語、ポーランド語、アラビア語、韓国語の各版では、よく使われるインラインのテンプレートを、その版の表示から学んだパターンでその版と同じように表示します。たとえば `{{lang-de|Wort}}` は日本語版では「ドイツ語: Wort」、英語版では「German: Wort」になります。出力を計算するテンプレート(単位換算、年齢、座標)は再現せず、記事に書かれた値を残します。年齢はダンプの日付から数えます。wp2txtが知らないテンプレートは、最初の名前なし引数に置き換えます(その引数が言語コードで後に別の引数があれば、そちらを使います)。
|
|
293
|
+
|
|
294
|
+
その他の一般的なテンプレートはwp2txt独自の規則で展開します:
|
|
222
295
|
|
|
223
296
|
| テンプレート | 出力 |
|
|
224
297
|
|--------------|------|
|
|
225
298
|
| `{{birth date\|1990\|5\|15}}` | May 15, 1990 |
|
|
226
|
-
| `{{convert\|100\|km\|mi}}` | 100 km
|
|
299
|
+
| `{{convert\|100\|km\|mi}}` | 100 km |
|
|
227
300
|
| `{{coord\|35\|41\|N\|139\|41\|E}}` | 35°41′N 139°41′E |
|
|
228
301
|
| `{{lang\|ja\|日本語}}` | 日本語 |
|
|
229
302
|
| `{{nihongo\|Tokyo\|東京\|Tōkyō}}` | Tokyo (東京, Tōkyō) |
|
|
@@ -250,11 +323,15 @@ CATEGORIES: カテゴリ1, カテゴリ2, カテゴリ3
|
|
|
250
323
|
-i, --input=<s> 圧縮ファイル(bz2)またはXMLファイルへのパス
|
|
251
324
|
-L, --lang=<s> Wikipedia言語コード(例: ja, en, de)
|
|
252
325
|
-A, --articles=<s> 特定の記事タイトル(カンマ区切り)
|
|
326
|
+
--articles-file=<s> 記事タイトルのファイル(1行に1つ)
|
|
327
|
+
-w, --no-follow-redirects リダイレクトのページそのものを抽出
|
|
253
328
|
-G, --from-category=<s> Wikipediaカテゴリから記事を抽出
|
|
254
329
|
-D, --depth=<i> サブカテゴリ再帰深度(デフォルト: 0)
|
|
255
330
|
-y, --yes 確認プロンプトをスキップ
|
|
256
331
|
--dry-run カテゴリ抽出をプレビュー
|
|
257
|
-
|
|
332
|
+
--allow-incomplete-category カテゴリを最後まで一覧できないとき、取得できた分を抽出
|
|
333
|
+
-U, --update-cache 新しいダンプの版を今すぐ確認
|
|
334
|
+
--dump-date=<s> この日付(YYYYMMDD)のダンプを使う
|
|
258
335
|
|
|
259
336
|
出力オプション:
|
|
260
337
|
-o, --output-dir=<s> 出力ディレクトリ(デフォルト: カレント)
|
|
@@ -325,8 +402,7 @@ CATEGORIES: カテゴリ1, カテゴリ2, カテゴリ3
|
|
|
325
402
|
|
|
326
403
|
```yaml
|
|
327
404
|
cache:
|
|
328
|
-
dump_expiry_days: 30 #
|
|
329
|
-
category_expiry_days: 7 # カテゴリキャッシュの有効期限(1-90)
|
|
405
|
+
dump_expiry_days: 30 # 新しいダンプの版を確認する間隔の日数(1-365)
|
|
330
406
|
directory: ~/.wp2txt/cache
|
|
331
407
|
|
|
332
408
|
defaults:
|
data/Rakefile
CHANGED
|
@@ -30,34 +30,23 @@ end
|
|
|
30
30
|
Rake::Task["build"].enhance([:normalize_permissions])
|
|
31
31
|
|
|
32
32
|
# Pre-release gate: verify the built gem's payload against spec.files and scan
|
|
33
|
-
# it for names, content, and modes that must never ship
|
|
33
|
+
# it for names, content, and modes that must never ship.
|
|
34
34
|
Rake::Task["build"].enhance { sh "ruby", "scripts/verify_gem.rb" }
|
|
35
35
|
|
|
36
36
|
# =============================================================================
|
|
37
37
|
# Docker
|
|
38
38
|
# =============================================================================
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
# working tree, so anything ignored locally (private notes, scratch files)
|
|
42
|
-
# would otherwise ride along.
|
|
43
|
-
IMAGE_FORBIDDEN_PATHS = %w[/wp2txt/research-notes /wp2txt/tmp /wp2txt/.git /wp2txt/CLAUDE.md /wp2txt/.claude /wp2txt/.private-doc-tokens].freeze
|
|
44
|
-
|
|
45
|
-
desc "Verify a built image contains no private material (run before pushing)"
|
|
46
|
-
task :verify_image, [:tag] do |_t, args|
|
|
47
|
-
tag = args[:tag] || "wp2txt-verify:local"
|
|
48
|
-
checks = IMAGE_FORBIDDEN_PATHS.map { |p| "test -e #{p} && echo LEAK:#{p}" }.join("; ")
|
|
49
|
-
out, status = Open3.capture2e("docker", "run", "--rm", tag, "sh", "-c", "#{checks}; true")
|
|
50
|
-
abort "Image verification failed for #{tag}: #{out}" unless status.success?
|
|
51
|
-
leaks = out.lines.grep(/^LEAK:/).map(&:strip)
|
|
52
|
-
abort "Image #{tag} contains private paths:\n #{leaks.join("\n ")}" unless leaks.empty?
|
|
53
|
-
|
|
54
|
-
puts "OK: #{tag} contains none of #{IMAGE_FORBIDDEN_PATHS.join(', ')}"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
desc "Build the image locally and verify it, without pushing"
|
|
40
|
+
desc "Build the image from a clean copy of the last commit and run the gate CI runs"
|
|
58
41
|
task :check_image do
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
# A clean clone is what CI builds from: files that exist only in this working
|
|
43
|
+
# tree never reach the context, and the gate compares the image against it.
|
|
44
|
+
require "tmpdir"
|
|
45
|
+
Dir.mktmpdir("wp2txt-image-") do |dir|
|
|
46
|
+
sh "git", "clone", "--quiet", "--no-local", ".", dir
|
|
47
|
+
sh "docker", "build", "-t", "wp2txt-verify:local", dir
|
|
48
|
+
sh "ruby", "scripts/verify_image.rb", "wp2txt-verify:local", "--context", dir
|
|
49
|
+
end
|
|
61
50
|
end
|
|
62
51
|
|
|
63
52
|
desc "Explain how images are published (they are built and pushed by CI)"
|