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/lib/wp2txt/corpus.rb
CHANGED
|
@@ -38,27 +38,6 @@ module Wp2txt
|
|
|
38
38
|
show_matched_sections: false
|
|
39
39
|
}.freeze
|
|
40
40
|
|
|
41
|
-
# Duck-typed replacement for MultistreamIndex that resolves titles through
|
|
42
|
-
# the IndexCache SQLite file on demand, avoiding loading millions of index
|
|
43
|
-
# entries into memory (important for long-lived server processes).
|
|
44
|
-
class LazyTitleIndex
|
|
45
|
-
def initialize(index_cache)
|
|
46
|
-
@cache = index_cache
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def find_by_title(title)
|
|
50
|
-
@cache.find_by_titles([title])[title]
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def stream_offset_for(title)
|
|
54
|
-
find_by_title(title)&.fetch(:offset, nil)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def stream_offsets
|
|
58
|
-
@stream_offsets ||= @cache.stream_offsets
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
41
|
attr_reader :multistream_path, :index_path, :metadata
|
|
63
42
|
|
|
64
43
|
def initialize(multistream_path:, index_path:, cache_dir: nil)
|
|
@@ -115,7 +94,9 @@ module Wp2txt
|
|
|
115
94
|
fulltext_current: fts.built? && fts.valid_for?(@multistream_path),
|
|
116
95
|
stats: stats,
|
|
117
96
|
fulltext: fts.built? ? fts.stats : nil,
|
|
118
|
-
langlinks: @metadata.built? ? @metadata.langlinks_provenance : nil
|
|
97
|
+
langlinks: @metadata.built? ? @metadata.langlinks_provenance : nil,
|
|
98
|
+
page_properties: @metadata.built? ? @metadata.page_props_provenance : nil,
|
|
99
|
+
inlinks: @metadata.built? ? @metadata.links_provenance : nil
|
|
119
100
|
}
|
|
120
101
|
end
|
|
121
102
|
|
|
@@ -147,7 +128,10 @@ module Wp2txt
|
|
|
147
128
|
else
|
|
148
129
|
render_text(page)
|
|
149
130
|
end
|
|
150
|
-
result = { id: page[:id], title: page[:title]
|
|
131
|
+
result = { id: page[:id], title: page[:title] }
|
|
132
|
+
properties = @metadata.built? ? @metadata.properties_for(page[:id]) : nil
|
|
133
|
+
result.merge!(properties) if properties
|
|
134
|
+
result[:format] = format.to_s
|
|
151
135
|
if max_chars && body.length > max_chars
|
|
152
136
|
result.merge(text: body[0, max_chars], truncated: true, total_chars: body.length)
|
|
153
137
|
else
|
|
@@ -409,6 +393,8 @@ module Wp2txt
|
|
|
409
393
|
next unless page
|
|
410
394
|
|
|
411
395
|
records = build_records(page, content, resolved_sections, chunk_size, chunk_overlap)
|
|
396
|
+
properties = @metadata.built? ? @metadata.properties_for(page[:id]) : nil
|
|
397
|
+
records.each { |record| record.merge!(properties) } if properties
|
|
412
398
|
next if records.empty?
|
|
413
399
|
|
|
414
400
|
articles_extracted += 1
|
|
@@ -577,6 +563,7 @@ module Wp2txt
|
|
|
577
563
|
end
|
|
578
564
|
|
|
579
565
|
def close
|
|
566
|
+
@reader&.close
|
|
580
567
|
close_read_connections
|
|
581
568
|
end
|
|
582
569
|
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"remove_templates": [
|
|
9
9
|
"sfn", "efn", "refn", "reflist", "refbegin", "refend", "notelist",
|
|
10
10
|
"r", "rp", "harvnb", "harv", "harvtxt", "sfnp",
|
|
11
|
+
"ref+", "sfnm", "sfnmp", "sfnref", "harvnp", "harvp", "harvc", "harvs",
|
|
12
|
+
"harvcol", "harvcolnb", "harvcoltxt", "harvard citation",
|
|
13
|
+
"harvard citation no brackets", "harvard citation text",
|
|
11
14
|
"main", "see also", "further", "details", "about",
|
|
12
15
|
"redirect", "distinguish", "other uses", "other people",
|
|
13
16
|
"for", "for other", "for more",
|
|
@@ -82,7 +85,7 @@
|
|
|
82
85
|
"Cite web", "Citeweb", "Cit"
|
|
83
86
|
],
|
|
84
87
|
"ruby_text_templates": [
|
|
85
|
-
"読み仮名", "よみがな", "ふりがな",
|
|
88
|
+
"読み仮名", "読み仮名 ruby不使用", "よみがな", "ふりがな",
|
|
86
89
|
"ruby", "Ruby", "ruby-ja", "Ruby-ja",
|
|
87
90
|
"ruby text", "ruby annotation",
|
|
88
91
|
"rubi", "rubytext",
|