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
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "wp2txt/template_patterns"
|
|
5
|
+
require "wp2txt/template_expander"
|
|
6
|
+
|
|
7
|
+
RSpec.describe Wp2txt::TemplatePatterns do
|
|
8
|
+
let(:data) do
|
|
9
|
+
{
|
|
10
|
+
"wikis" => {
|
|
11
|
+
"xx" => {
|
|
12
|
+
"templates" => {
|
|
13
|
+
"Lang-de" => { "p" => "Deutsch: {1}" },
|
|
14
|
+
"Langx" => { "code_arg" => 1, "p" => "{2}", "by_code" => { "de" => "Deutsch: {2}", "fr" => "Französisch: {2}" } },
|
|
15
|
+
"Link" => { "code_arg" => 2, "p" => "{1}", "by_code" => { "de" => "{1} (deutsch)" }, "replaces" => { "label" => "1" } },
|
|
16
|
+
"Cite web" => { "p" => "{1}" },
|
|
17
|
+
"Circa" => { "p" => "c. {1} – c. {2}", "p1" => "c. {1}" },
|
|
18
|
+
"Reading" => { "p" => "{1} ({2})" },
|
|
19
|
+
"Iw" => { "code_arg" => 3, "p" => "{2}", "by_code" => { "en" => "{2} [en]" }, "fallback" => { "2" => "1" } },
|
|
20
|
+
"Ill" => { "p" => "{2}", "fallback" => { "2" => "1" }, "replaces" => { "label" => "2" } },
|
|
21
|
+
"Count" => { "p" => "THREE {1}", "p1" => "ONE {1}", "p2" => "TWO {1}" },
|
|
22
|
+
"Known" => { "p" => "{1}" },
|
|
23
|
+
"Height" => { "p" => "{1} m", "n" => 1 },
|
|
24
|
+
"Start date" => { "p" => "{1}", "n" => 1 },
|
|
25
|
+
"Lang" => { "code_arg" => 1, "p" => "{2}", "n" => 2 },
|
|
26
|
+
"Some langs" => { "code_arg" => 1, "p" => "{2}", "n" => 2, "codes" => %w[de grc] },
|
|
27
|
+
"Zh" => { "p" => "Chinese: {1}", "replaces" => { "s" => "1", "t" => "1" }, "ignores" => %w[link],
|
|
28
|
+
"with" => { "lit" => "Chinese: {1}, lit. {lit}", "lc" => "chinese: {1}", "sm" => "Chinese: {1}" },
|
|
29
|
+
"off" => { "lc" => %w[no NO] }, "shows" => %w[s t lit rm sep] },
|
|
30
|
+
"Auy" => { "p" => "{1}, {2}", "with" => { "bio" => "{1}" } },
|
|
31
|
+
"Enlink" => { "p" => "({3}:{2})", "p2" => "({2})", "with" => { "p" => "{3}:{2}" } },
|
|
32
|
+
"Infobox thing" => { "p" => "" },
|
|
33
|
+
"Infobox thing/link" => { "p" => "{1}" },
|
|
34
|
+
"Box" => { "p" => "" },
|
|
35
|
+
"Range" => { "p" => "{1} {2}{3}", "p2" => "{1} {2}", "with" => { "to" => "{1} to {to} {2}{3}", "alt" => "{alt}" },
|
|
36
|
+
"shows" => %w[to alt] }
|
|
37
|
+
},
|
|
38
|
+
"aliases" => { "Lde" => "Lang-de" }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
around do |example|
|
|
45
|
+
saved = described_class.instance_variable_get(:@data)
|
|
46
|
+
described_class.instance_variable_set(:@data, data)
|
|
47
|
+
example.run
|
|
48
|
+
ensure
|
|
49
|
+
described_class.instance_variable_set(:@data, saved)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def render(lang, name, *parts)
|
|
53
|
+
definition = described_class.lookup(lang, name)
|
|
54
|
+
definition && described_class.render(definition, Wp2txt::TemplateArgs.parse(parts))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "finds a template by its name as MediaWiki matches it, or by a name that redirects to it" do
|
|
58
|
+
expect(described_class.lookup("xx", "lang-de")).to eq(data.dig("wikis", "xx", "templates", "Lang-de"))
|
|
59
|
+
expect(described_class.lookup("xx", " cite_web ")).to eq(data.dig("wikis", "xx", "templates", "Cite web"))
|
|
60
|
+
expect(described_class.lookup("xx", "lde")).to eq(data.dig("wikis", "xx", "templates", "Lang-de"))
|
|
61
|
+
expect(described_class.lookup("xx", "Unknown")).to be_nil
|
|
62
|
+
expect(described_class.lookup("yy", "Lang-de")).to be_nil
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "puts the arguments in the pattern's slots" do
|
|
66
|
+
expect(render("xx", "Lang-de", "Wort")).to eq("Deutsch: Wort")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "uses the pattern for the language code given, and the plain one for other codes" do
|
|
70
|
+
expect(render("xx", "Langx", "fr", "mot")).to eq("Französisch: mot")
|
|
71
|
+
expect(render("xx", "Langx", "DE", "Wort")).to eq("Deutsch: Wort")
|
|
72
|
+
expect(render("xx", "Langx", "qq", "x")).to eq("x")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "uses the pattern for as many arguments as the call gives" do
|
|
76
|
+
expect(render("xx", "Circa", "1550")).to eq("c. 1550")
|
|
77
|
+
expect(render("xx", "Circa", "1550", "1560")).to eq("c. 1550 – c. 1560")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "does not render a call with more arguments than the pattern was learned with" do
|
|
81
|
+
expect(render("xx", "Height", "185")).to eq("185 m")
|
|
82
|
+
expect(render("xx", "Height", "29", "4", "2000")).to be_nil
|
|
83
|
+
expect(render("xx", "Height", "Ada")).to be_nil
|
|
84
|
+
expect(render("xx", "Lang", "grc", "λόγος")).to eq("λόγος")
|
|
85
|
+
expect(render("xx", "Lang", "grc", "λόγος", "logos")).to be_nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "renders a code pattern learned from n arguments only for calls of that shape and its codes" do
|
|
89
|
+
expect(render("xx", "Lang", "grc")).to be_nil
|
|
90
|
+
expect(render("xx", "Lang", "grc", "λόγος", "italic=no")).to be_nil
|
|
91
|
+
expect(render("xx", "Lang", "grc", "")).to be_nil
|
|
92
|
+
expect(render("xx", "Lang", "2=λόγος")).to be_nil
|
|
93
|
+
expect(render("xx", "Some langs", "GRC", "λόγος")).to eq("λόγος")
|
|
94
|
+
expect(render("xx", "Some langs", "fr", "mot")).to be_nil
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe "named arguments" do
|
|
98
|
+
it "uses the pattern where the named arguments change nothing, stand in for an argument, or are not known" do
|
|
99
|
+
expect(render("xx", "Zh", "字", "link=no")).to eq("Chinese: 字")
|
|
100
|
+
expect(render("xx", "Zh", "s=字")).to eq("Chinese: 字")
|
|
101
|
+
expect(render("xx", "Zh", "字", "lit=")).to eq("Chinese: 字")
|
|
102
|
+
expect(render("xx", "Zh", "字", "mode=x")).to eq("Chinese: 字")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "uses the pattern learned with a named argument where the call gives no other, its last value" do
|
|
106
|
+
expect(render("xx", "Zh", "字", "lit=word")).to eq("Chinese: 字, lit. word")
|
|
107
|
+
expect(render("xx", "Zh", "字", "lit=old", "lit=new", "link=no")).to eq("Chinese: 字, lit. new")
|
|
108
|
+
expect(render("xx", "Zh", "字", "lit=word", "mode=x")).to eq("Chinese: 字, lit. word")
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "uses the pattern learned with a named argument for a call of fewer arguments, where it has their slots" do
|
|
112
|
+
expect(render("xx", "Range", "252", "to=381", "m")).to eq("252 to 381 m")
|
|
113
|
+
expect(render("xx", "Range", "2018", "alt=in 2018")).to eq("in 2018")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "reads a setting given a value the template reads as off as off" do
|
|
117
|
+
expect(render("xx", "Zh", "字", "lc=no")).to eq("Chinese: 字")
|
|
118
|
+
expect(render("xx", "Zh", "字", "lc=NO")).to eq("Chinese: 字")
|
|
119
|
+
expect(render("xx", "Zh", "字", "lc=yes")).to eq("chinese: 字")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "follows the pattern with the values shown, each once, where no pattern has the named arguments given" do
|
|
123
|
+
expect(render("xx", "Zh", "字", "rm=zi", "lit=word")).to eq("Chinese: 字 zi word")
|
|
124
|
+
expect(render("xx", "Zh", "s=字", "lit=word")).to eq("Chinese: 字 word")
|
|
125
|
+
expect(render("xx", "Zh", "s=字", "rm=字")).to eq("Chinese: 字")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "keeps each value given in place of the same argument" do
|
|
129
|
+
expect(render("xx", "Zh", "s=字", "t=體")).to eq("Chinese: 字 體")
|
|
130
|
+
expect(render("xx", "Zh", "s=字", "t=體", "rm=zi")).to eq("Chinese: 字 體 zi")
|
|
131
|
+
expect(render("xx", "Zh", "s=字", "t=[[字]]")).to eq("Chinese: 字")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "does not add a value that holds no word or number" do
|
|
135
|
+
expect(render("xx", "Zh", "字", "rm=zi", "sep=、")).to eq("Chinese: 字 zi")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "does not use a pattern learned with a named argument that leaves out an argument without showing its own" do
|
|
139
|
+
expect(render("xx", "Auy", "Vent.", "1807", "bio=bot")).to eq("Vent., 1807")
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "does not use a pattern learned with a named argument where an argument the call leaves empty is joined to its text" do
|
|
143
|
+
expect(render("xx", "Enlink", "Resident (title)", "Resident", "p=off")).to eq("(Resident)")
|
|
144
|
+
expect(render("xx", "Enlink", "Handwerksordnung", "Gesetz", "de", "p=off")).to eq("de:Gesetz")
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "uses the pattern for settings given together that show no value of their own" do
|
|
148
|
+
expect(render("xx", "Zh", "字", "lc=yes", "sm=y")).to eq("Chinese: 字")
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "does not render a code pattern learned from n arguments for a named argument not known to change nothing" do
|
|
152
|
+
expect(render("xx", "Lang", "grc", "λόγος", "italic=no")).to be_nil
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "shows nothing for a template shown only as blocks, whatever it is given" do
|
|
156
|
+
expect(render("xx", "Box", "x", "style=y")).to eq("")
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "does not take a number for a language code" do
|
|
161
|
+
expect(render("xx", "Langx", "2000", "5")).to be_nil
|
|
162
|
+
expect(render("xx", "Langx", "de", "Wort")).to eq("Deutsch: Wort")
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "leaves out brackets that hold no argument" do
|
|
166
|
+
expect(render("xx", "Reading", "東京")).to eq("東京")
|
|
167
|
+
expect(render("xx", "Reading", "東京", "とうきょう")).to eq("東京 (とうきょう)")
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "shows a named label in place of the argument it replaces" do
|
|
171
|
+
expect(render("xx", "Link", "Title", "de", "Titel")).to eq("Title (deutsch)")
|
|
172
|
+
expect(render("xx", "Link", "Title", "de", "Titel", "label=Shown")).to eq("Shown (deutsch)")
|
|
173
|
+
expect(render("xx", "Link", "Title", "de", "Titel", "label=")).to eq("Title (deutsch)")
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "shows another argument in place of one left empty, as the template does" do
|
|
177
|
+
expect(render("xx", "Iw", "Title", "Label", "en", "Other")).to eq("Label [en]")
|
|
178
|
+
expect(render("xx", "Iw", "Title", "", "en", "Other")).to eq("Title [en]")
|
|
179
|
+
expect(render("xx", "Iw", "Title")).to eq("Title")
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it "prefers a named label to the argument it replaces, even where that argument is left empty" do
|
|
183
|
+
expect(render("xx", "Ill", "Title", "", "label=Shown")).to eq("Shown")
|
|
184
|
+
expect(render("xx", "Ill", "Title", "")).to eq("Title")
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "keeps brackets and spaces that an argument holds" do
|
|
188
|
+
expect(render("xx", "Known", "()")).to eq("()")
|
|
189
|
+
expect(render("xx", "Reading", "a b", "")).to eq("a b")
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "keeps the spaces around an unnamed argument" do
|
|
193
|
+
expect(render("xx", "Lang-de", " Wort ")).to eq("Deutsch: Wort ")
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
describe "with templates inside arguments" do
|
|
197
|
+
it "keeps an equals sign an inner template shows as text" do
|
|
198
|
+
expect(Wp2txt::TemplateExpander.new(lang: "xx", literal_equals: "\u{FDD1}").expand("{{Known|{{Known|1=a=b}}}}"))
|
|
199
|
+
.to eq("a\u{FDD1}b")
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it "reads the data the same way from any Ractor" do
|
|
204
|
+
expect(Ractor.shareable?(described_class::DATA)).to be(true)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
describe "in the template expander" do
|
|
208
|
+
it "counts an empty last argument as given" do
|
|
209
|
+
expect(Wp2txt::TemplateExpander.new(lang: "xx").expand("{{Count|x|}}")).to eq("TWO x")
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "chooses the pattern for a language code given by a template in the argument" do
|
|
213
|
+
expect(Wp2txt::TemplateExpander.new(lang: "xx").expand("{{Langx|{{Known|de}}|Wort}}")).to eq("Deutsch: Wort")
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it "renders known templates of the dump's edition" do
|
|
217
|
+
expect(Wp2txt::TemplateExpander.new(lang: "xx").expand("a {{lang-de|Wort}} b")).to eq("a Deutsch: Wort b")
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it "keeps citations removed, whatever the patterns say" do
|
|
221
|
+
expect(Wp2txt::TemplateExpander.new(lang: "xx").expand("a{{Cite web|x}}b")).to eq("ab")
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it "leaves a template shown as a block marker to the markers" do
|
|
225
|
+
expect(Wp2txt::TemplateExpander.new(lang: "xx", preserve_unknown: true).expand("a{{Infobox thing|name=x}}b"))
|
|
226
|
+
.to eq("a{{Infobox thing|name=x}}b")
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it "uses the pattern of a template named like a block that shows text, and of one holding a block" do
|
|
230
|
+
expander = Wp2txt::TemplateExpander.new(lang: "xx", preserve_unknown: true)
|
|
231
|
+
expect(expander.expand("a{{Infobox thing/link|Album}}b")).to eq("aAlbumb")
|
|
232
|
+
expect(expander.expand("a{{Auy|Vent.|1807|note={{Infobox thing}}}}b")).to eq("aVent., 1807b")
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it "leaves a call the pattern does not tell to the other rules" do
|
|
236
|
+
expander = Wp2txt::TemplateExpander.new(lang: "xx", preserve_unknown: true)
|
|
237
|
+
expect(expander.expand("a {{Height|29|4|2000}} b")).to eq("a {{Height|29|4|2000}} b")
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "gives the cleaner the arguments as expanded" do
|
|
241
|
+
expect(Wp2txt::TemplateExpander.new(lang: "xx", preserve_unknown: true).expand("{{Height|{{Known|29}}|x}}"))
|
|
242
|
+
.to eq("{{Height|29|x}}")
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "gives the other rules the arguments as expanded" do
|
|
246
|
+
expect(Wp2txt::TemplateExpander.new(lang: "xx").expand("{{Start date|{{Known|2000}}|5|3}}")).to eq("May 3, 2000")
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it "uses its own handlers when the edition is not known" do
|
|
250
|
+
expect(Wp2txt::TemplateExpander.new.expand("{{lang-de|Wort}}")).to eq("German: Wort")
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "tmpdir"
|
|
7
|
+
|
|
8
|
+
# scripts/check_tracked_paths.rb and scripts/pre-push, run against a disposable
|
|
9
|
+
# copy of this repository's index: what it passes, and what it must stop.
|
|
10
|
+
RSpec.describe "tracked-path allow list" do
|
|
11
|
+
repo_root = File.expand_path("..", __dir__)
|
|
12
|
+
|
|
13
|
+
around do |example|
|
|
14
|
+
Dir.mktmpdir("wp2txt-paths-") do |dir|
|
|
15
|
+
@dir = dir
|
|
16
|
+
@repo = File.join(dir, "repo")
|
|
17
|
+
# Commits in the copy run no hooks but the one under test
|
|
18
|
+
@no_hooks = File.join(dir, "no-hooks")
|
|
19
|
+
Dir.mkdir(@no_hooks)
|
|
20
|
+
Dir.mkdir(@repo)
|
|
21
|
+
system("git", "-C", repo_root, "checkout-index", "-a", "-f", "--prefix=#{@repo}/", exception: true)
|
|
22
|
+
git("init", "-q", "-b", "master")
|
|
23
|
+
git("add", "-A")
|
|
24
|
+
commit("initial")
|
|
25
|
+
example.run
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def git(*args, hooks: @no_hooks)
|
|
30
|
+
out, status = Open3.capture2e("git", "-c", "core.hooksPath=#{hooks}", "-c", "user.name=t",
|
|
31
|
+
"-c", "user.email=t@example.invalid", "-C", @repo, *args)
|
|
32
|
+
raise "git #{args.join(' ')} failed:\n#{out}" unless status.success?
|
|
33
|
+
|
|
34
|
+
out
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def commit(message)
|
|
38
|
+
git("commit", "-q", "--allow-empty", "-m", message)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def put(path, content = "x\n", stage: true)
|
|
42
|
+
full = File.join(@repo, path)
|
|
43
|
+
FileUtils.mkdir_p(File.dirname(full))
|
|
44
|
+
File.write(full, content, mode: "a")
|
|
45
|
+
git("add", path) if stage
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def check(*args)
|
|
49
|
+
out, status = Open3.capture2e(RbConfig.ruby, File.join(@repo, "scripts", "check_tracked_paths.rb"), *args)
|
|
50
|
+
[status.success?, out]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "passes the files tracked now" do
|
|
54
|
+
expect(check).to match([true, /OK: every tracked file is allowed/])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "stops an internal note, wherever it is placed" do
|
|
58
|
+
["notes/plan.md", "PLAN.md", "README_plan.md", "docs/PLAN.md", "spec/notes.md"].each do |path|
|
|
59
|
+
put(path)
|
|
60
|
+
ok, out = check
|
|
61
|
+
expect([path, ok]).to eq([path, false])
|
|
62
|
+
expect(out).to include(" #{path}\n")
|
|
63
|
+
git("rm", "-q", "--cached", path)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "stops logs, environment files, databases, and data in places not allowed" do
|
|
68
|
+
%w[debug.log .env data.sqlite3 dump.json lib/dump.json lib/wp2txt/data/dump.json spec/fixtures/dump.json].each do |path|
|
|
69
|
+
put(path)
|
|
70
|
+
expect(check.first).to be(false), "#{path} passed"
|
|
71
|
+
git("rm", "-q", "--cached", path)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "stops an alternative that matches no tracked file" do
|
|
76
|
+
put("scripts/tracked_paths.allow", "image/*.{svg,png}\n")
|
|
77
|
+
ok, out = check
|
|
78
|
+
expect(ok).to be(false)
|
|
79
|
+
expect(out).to include("image/*.png (from image/*.{svg,png})")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "judges by the staged list, not by an unstaged edit to it" do
|
|
83
|
+
put("notes/plan.md")
|
|
84
|
+
put("scripts/tracked_paths.allow", "notes/*.md\n", stage: false)
|
|
85
|
+
expect(check.first).to be(false)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "judges a commit by the list inside that commit" do
|
|
89
|
+
put("notes/plan.md")
|
|
90
|
+
commit("add a note")
|
|
91
|
+
expect(check("--tree", "HEAD").first).to be(false)
|
|
92
|
+
expect(check("--tree", "HEAD~1").first).to be(true)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "refuses to pass when it saw nothing" do
|
|
96
|
+
expect(check("--tree")).to match([false, /needs a revision/])
|
|
97
|
+
expect(check("--tree", "--other")).to match([false, /needs a revision/])
|
|
98
|
+
expect(check("--tree", "no-such-rev")).to match([false, /could not list/])
|
|
99
|
+
git("rm", "-q", "--cached", "scripts/tracked_paths.allow")
|
|
100
|
+
expect(check).to match([false, /has no scripts\/tracked_paths.allow/])
|
|
101
|
+
|
|
102
|
+
outside = File.join(@dir, "outside", "scripts")
|
|
103
|
+
FileUtils.mkdir_p(outside)
|
|
104
|
+
FileUtils.cp(File.join(@repo, "scripts", "check_tracked_paths.rb"), outside)
|
|
105
|
+
_out, status = Open3.capture2e(RbConfig.ruby, File.join(outside, "check_tracked_paths.rb"))
|
|
106
|
+
expect(status.success?).to be(false)
|
|
107
|
+
|
|
108
|
+
system("git", "init", "-q", File.join(@dir, "outside"), exception: true) # a checkout tracking nothing
|
|
109
|
+
out, status = Open3.capture2e(RbConfig.ruby, File.join(outside, "check_tracked_paths.rb"))
|
|
110
|
+
expect([status.success?, out]).to match([false, /could not list/])
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "pre-push" do
|
|
114
|
+
before do
|
|
115
|
+
@remote = File.join(@dir, "remote.git")
|
|
116
|
+
system("git", "init", "-q", "--bare", @remote, exception: true)
|
|
117
|
+
git("remote", "add", "origin", @remote)
|
|
118
|
+
git("push", "-q", "origin", "master")
|
|
119
|
+
@hooks = File.join(@dir, "hooks")
|
|
120
|
+
Dir.mkdir(@hooks)
|
|
121
|
+
File.symlink(File.join(@repo, "scripts", "pre-push"), File.join(@hooks, "pre-push"))
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def push
|
|
125
|
+
out, status = Open3.capture2e("git", "-c", "core.hooksPath=#{@hooks}", "-C", @repo, "push", "origin", "master")
|
|
126
|
+
[status.success?, out]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def remote_head
|
|
130
|
+
`git -C #{@remote} rev-parse master`.strip
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "lets allowed commits through and says how many it checked" do
|
|
134
|
+
put("lib/wp2txt/extra.rb")
|
|
135
|
+
commit("add a module")
|
|
136
|
+
expect(push).to match([true, /1 commit\(s\) checked/])
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "stops a push when only a commit in the middle of the range has an unallowed file" do
|
|
140
|
+
before = remote_head
|
|
141
|
+
put("debug.log")
|
|
142
|
+
commit("add a log")
|
|
143
|
+
git("rm", "-q", "debug.log")
|
|
144
|
+
commit("remove it again")
|
|
145
|
+
ok, out = push
|
|
146
|
+
expect(ok).to be(false)
|
|
147
|
+
expect(out).to include("debug.log")
|
|
148
|
+
expect(remote_head).to eq(before)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "stops a new commit that carries no allow list" do
|
|
152
|
+
git("rm", "-q", "scripts/tracked_paths.allow")
|
|
153
|
+
commit("drop the list")
|
|
154
|
+
expect(push).to match([false, /without scripts\/tracked_paths.allow/])
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "checks every commit no remote has when pushing a new branch" do
|
|
158
|
+
git("switch", "-q", "-c", "topic")
|
|
159
|
+
put(".env")
|
|
160
|
+
commit("add env")
|
|
161
|
+
git("rm", "-q", ".env")
|
|
162
|
+
commit("remove env")
|
|
163
|
+
out, status = Open3.capture2e("git", "-c", "core.hooksPath=#{@hooks}", "-C", @repo, "push", "origin", "topic")
|
|
164
|
+
expect(status.success?).to be(false)
|
|
165
|
+
expect(out).to include(".env")
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
data/spec/utils_spec.rb
CHANGED
|
@@ -352,6 +352,12 @@ RSpec.describe "Wp2txt Utils" do
|
|
|
352
352
|
expect(b2).to eq "http://yohasebe.com"
|
|
353
353
|
expect(c2).to eq "* Turkish: {{t+|tr|köken bilimi}}]], {{t+|tr|etimoloji}}"
|
|
354
354
|
end
|
|
355
|
+
|
|
356
|
+
it "keeps a bracket that does not open with a URL as written" do
|
|
357
|
+
expect(process_external_links("Ким Уэстон[англ.] said [sic] it")).to eq "Ким Уэстон[англ.] said [sic] it"
|
|
358
|
+
expect(process_external_links("[//example.org Site] and [mailto:a@example.org mail]")).to eq "Site and mail"
|
|
359
|
+
expect(process_external_links("[wikipedia://en/Example entry]")).to eq "entry"
|
|
360
|
+
end
|
|
355
361
|
end
|
|
356
362
|
|
|
357
363
|
describe "correct_inline_template" do
|
|
@@ -366,7 +372,7 @@ RSpec.describe "Wp2txt Utils" do
|
|
|
366
372
|
expect(correct_inline_template(str_before2)).to eq str_after2
|
|
367
373
|
|
|
368
374
|
str_before3 = "{{a|b=c|d=f}}"
|
|
369
|
-
str_after3 = "
|
|
375
|
+
str_after3 = ""
|
|
370
376
|
expect(correct_inline_template(str_before3)).to eq str_after3
|
|
371
377
|
|
|
372
378
|
str_before4 = "{{a|b|{{c|d|e}}}}"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wp2txt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yoichiro Hasebe
|
|
@@ -221,8 +221,8 @@ files:
|
|
|
221
221
|
- docs/INDEXES.md
|
|
222
222
|
- lib/wp2txt.rb
|
|
223
223
|
- lib/wp2txt/article.rb
|
|
224
|
+
- lib/wp2txt/bz2_stream.rb
|
|
224
225
|
- lib/wp2txt/bz2_validator.rb
|
|
225
|
-
- lib/wp2txt/category_cache.rb
|
|
226
226
|
- lib/wp2txt/cli.rb
|
|
227
227
|
- lib/wp2txt/cli_ui.rb
|
|
228
228
|
- lib/wp2txt/config.rb
|
|
@@ -234,7 +234,10 @@ files:
|
|
|
234
234
|
- lib/wp2txt/data/language_tiers.json
|
|
235
235
|
- lib/wp2txt/data/mediawiki_aliases.json
|
|
236
236
|
- lib/wp2txt/data/template_aliases.json
|
|
237
|
+
- lib/wp2txt/data/template_patterns.json
|
|
237
238
|
- lib/wp2txt/data/wikipedia_entities.json
|
|
239
|
+
- lib/wp2txt/dump_snapshot.rb
|
|
240
|
+
- lib/wp2txt/extraction_run.rb
|
|
238
241
|
- lib/wp2txt/extractor.rb
|
|
239
242
|
- lib/wp2txt/file_utils.rb
|
|
240
243
|
- lib/wp2txt/formatter.rb
|
|
@@ -243,63 +246,86 @@ files:
|
|
|
243
246
|
- lib/wp2txt/index_cache.rb
|
|
244
247
|
- lib/wp2txt/index_commands.rb
|
|
245
248
|
- lib/wp2txt/langlinks_importer.rb
|
|
249
|
+
- lib/wp2txt/lead_terms.rb
|
|
250
|
+
- lib/wp2txt/link_counter.rb
|
|
246
251
|
- lib/wp2txt/magic_words.rb
|
|
247
252
|
- lib/wp2txt/memory_monitor.rb
|
|
248
253
|
- lib/wp2txt/metadata_index.rb
|
|
249
254
|
- lib/wp2txt/multistream.rb
|
|
250
255
|
- lib/wp2txt/output_path.rb
|
|
251
256
|
- lib/wp2txt/output_writer.rb
|
|
257
|
+
- lib/wp2txt/page_props_importer.rb
|
|
252
258
|
- lib/wp2txt/parser_functions.rb
|
|
253
259
|
- lib/wp2txt/ractor_worker.rb
|
|
254
260
|
- lib/wp2txt/regex.rb
|
|
255
261
|
- lib/wp2txt/section_extractor.rb
|
|
262
|
+
- lib/wp2txt/site_info.rb
|
|
263
|
+
- lib/wp2txt/sql_dump_reader.rb
|
|
256
264
|
- lib/wp2txt/stream_processor.rb
|
|
265
|
+
- lib/wp2txt/stream_store.rb
|
|
266
|
+
- lib/wp2txt/template_args.rb
|
|
257
267
|
- lib/wp2txt/template_expander.rb
|
|
268
|
+
- lib/wp2txt/template_patterns.rb
|
|
258
269
|
- lib/wp2txt/text_processing.rb
|
|
259
270
|
- lib/wp2txt/utils.rb
|
|
260
271
|
- lib/wp2txt/version.rb
|
|
272
|
+
- lib/wp2txt/wikitext_regions.rb
|
|
261
273
|
- spec/article_spec.rb
|
|
262
274
|
- spec/auto_download_spec.rb
|
|
263
275
|
- spec/bz2_validator_spec.rb
|
|
264
|
-
- spec/category_cache_spec.rb
|
|
265
276
|
- spec/category_fetcher_spec.rb
|
|
266
277
|
- spec/cleanup_spec.rb
|
|
267
278
|
- spec/cli_options_spec.rb
|
|
268
279
|
- spec/cli_spec.rb
|
|
280
|
+
- spec/cli_targeted_spec.rb
|
|
269
281
|
- spec/config_spec.rb
|
|
270
282
|
- spec/constants_spec.rb
|
|
271
283
|
- spec/corpus_spec.rb
|
|
272
284
|
- spec/docs_sync_spec.rb
|
|
285
|
+
- spec/dump_fetch_spec.rb
|
|
286
|
+
- spec/extraction_run_spec.rb
|
|
273
287
|
- spec/file_utils_spec.rb
|
|
274
288
|
- spec/fixtures/samples.rb
|
|
275
289
|
- spec/formatter_sections_spec.rb
|
|
276
290
|
- spec/fts_index_spec.rb
|
|
277
291
|
- spec/global_data_cache_spec.rb
|
|
292
|
+
- spec/index_build_spec.rb
|
|
278
293
|
- spec/index_cache_spec.rb
|
|
294
|
+
- spec/index_commands_version_spec.rb
|
|
279
295
|
- spec/integration_spec.rb
|
|
280
296
|
- spec/langlinks_importer_spec.rb
|
|
297
|
+
- spec/lead_terms_edge_cases_spec.rb
|
|
298
|
+
- spec/lead_terms_links_qids_spec.rb
|
|
281
299
|
- spec/magic_words_spec.rb
|
|
282
300
|
- spec/markers_spec.rb
|
|
283
301
|
- spec/memory_monitor_spec.rb
|
|
284
302
|
- spec/metadata_index_spec.rb
|
|
285
303
|
- spec/multi_dump_attach_spec.rb
|
|
304
|
+
- spec/multistream_reader_spec.rb
|
|
286
305
|
- spec/multistream_spec.rb
|
|
287
306
|
- spec/output_integrity_spec.rb
|
|
288
307
|
- spec/output_writer_spec.rb
|
|
289
308
|
- spec/p1_correctness_spec.rb
|
|
309
|
+
- spec/page_properties_spec.rb
|
|
290
310
|
- spec/parser_functions_spec.rb
|
|
291
311
|
- spec/ractor_worker_spec.rb
|
|
292
312
|
- spec/regex_spec.rb
|
|
313
|
+
- spec/region_semantics_spec.rb
|
|
293
314
|
- spec/section_extractor_spec.rb
|
|
294
315
|
- spec/spec_helper.rb
|
|
295
316
|
- spec/stream_processor_spec.rb
|
|
317
|
+
- spec/support/dump_status.rb
|
|
296
318
|
- spec/support/meta_db_fixture.rb
|
|
297
319
|
- spec/support/multistream_fixture.rb
|
|
320
|
+
- spec/template_args_spec.rb
|
|
298
321
|
- spec/template_data_spec.rb
|
|
299
322
|
- spec/template_expander_spec.rb
|
|
323
|
+
- spec/template_passthrough_spec.rb
|
|
324
|
+
- spec/template_patterns_spec.rb
|
|
300
325
|
- spec/template_processing_spec.rb
|
|
301
326
|
- spec/text_processing_spec.rb
|
|
302
327
|
- spec/titles_output_path_spec.rb
|
|
328
|
+
- spec/tracked_paths_spec.rb
|
|
303
329
|
- spec/utils_spec.rb
|
|
304
330
|
- spec/wp2txt_spec.rb
|
|
305
331
|
- wp2txt.gemspec
|
|
@@ -321,7 +347,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
321
347
|
- !ruby/object:Gem::Version
|
|
322
348
|
version: '0'
|
|
323
349
|
requirements: []
|
|
324
|
-
rubygems_version: 4.0.
|
|
350
|
+
rubygems_version: 4.0.20
|
|
325
351
|
specification_version: 4
|
|
326
352
|
summary: A command-line toolkit to extract text content and category data from Wikipedia
|
|
327
353
|
dump files
|
|
@@ -329,44 +355,58 @@ test_files:
|
|
|
329
355
|
- spec/article_spec.rb
|
|
330
356
|
- spec/auto_download_spec.rb
|
|
331
357
|
- spec/bz2_validator_spec.rb
|
|
332
|
-
- spec/category_cache_spec.rb
|
|
333
358
|
- spec/category_fetcher_spec.rb
|
|
334
359
|
- spec/cleanup_spec.rb
|
|
335
360
|
- spec/cli_options_spec.rb
|
|
336
361
|
- spec/cli_spec.rb
|
|
362
|
+
- spec/cli_targeted_spec.rb
|
|
337
363
|
- spec/config_spec.rb
|
|
338
364
|
- spec/constants_spec.rb
|
|
339
365
|
- spec/corpus_spec.rb
|
|
340
366
|
- spec/docs_sync_spec.rb
|
|
367
|
+
- spec/dump_fetch_spec.rb
|
|
368
|
+
- spec/extraction_run_spec.rb
|
|
341
369
|
- spec/file_utils_spec.rb
|
|
342
370
|
- spec/fixtures/samples.rb
|
|
343
371
|
- spec/formatter_sections_spec.rb
|
|
344
372
|
- spec/fts_index_spec.rb
|
|
345
373
|
- spec/global_data_cache_spec.rb
|
|
374
|
+
- spec/index_build_spec.rb
|
|
346
375
|
- spec/index_cache_spec.rb
|
|
376
|
+
- spec/index_commands_version_spec.rb
|
|
347
377
|
- spec/integration_spec.rb
|
|
348
378
|
- spec/langlinks_importer_spec.rb
|
|
379
|
+
- spec/lead_terms_edge_cases_spec.rb
|
|
380
|
+
- spec/lead_terms_links_qids_spec.rb
|
|
349
381
|
- spec/magic_words_spec.rb
|
|
350
382
|
- spec/markers_spec.rb
|
|
351
383
|
- spec/memory_monitor_spec.rb
|
|
352
384
|
- spec/metadata_index_spec.rb
|
|
353
385
|
- spec/multi_dump_attach_spec.rb
|
|
386
|
+
- spec/multistream_reader_spec.rb
|
|
354
387
|
- spec/multistream_spec.rb
|
|
355
388
|
- spec/output_integrity_spec.rb
|
|
356
389
|
- spec/output_writer_spec.rb
|
|
357
390
|
- spec/p1_correctness_spec.rb
|
|
391
|
+
- spec/page_properties_spec.rb
|
|
358
392
|
- spec/parser_functions_spec.rb
|
|
359
393
|
- spec/ractor_worker_spec.rb
|
|
360
394
|
- spec/regex_spec.rb
|
|
395
|
+
- spec/region_semantics_spec.rb
|
|
361
396
|
- spec/section_extractor_spec.rb
|
|
362
397
|
- spec/spec_helper.rb
|
|
363
398
|
- spec/stream_processor_spec.rb
|
|
399
|
+
- spec/support/dump_status.rb
|
|
364
400
|
- spec/support/meta_db_fixture.rb
|
|
365
401
|
- spec/support/multistream_fixture.rb
|
|
402
|
+
- spec/template_args_spec.rb
|
|
366
403
|
- spec/template_data_spec.rb
|
|
367
404
|
- spec/template_expander_spec.rb
|
|
405
|
+
- spec/template_passthrough_spec.rb
|
|
406
|
+
- spec/template_patterns_spec.rb
|
|
368
407
|
- spec/template_processing_spec.rb
|
|
369
408
|
- spec/text_processing_spec.rb
|
|
370
409
|
- spec/titles_output_path_spec.rb
|
|
410
|
+
- spec/tracked_paths_spec.rb
|
|
371
411
|
- spec/utils_spec.rb
|
|
372
412
|
- spec/wp2txt_spec.rb
|