yuno-proofreader 0.1.1 → 0.1.3
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/CHANGELOG.md +15 -0
- data/lib/yuno/proofreader/analysis/adjustments.rb +30 -32
- data/lib/yuno/proofreader/analysis/crawler.rb +71 -73
- data/lib/yuno/proofreader/analysis/entries.rb +52 -54
- data/lib/yuno/proofreader/analysis/extractor.rb +162 -164
- data/lib/yuno/proofreader/analysis/graph.rb +86 -88
- data/lib/yuno/proofreader/analysis/judge.rb +80 -82
- data/lib/yuno/proofreader/analysis/judge_prompt.rb +50 -52
- data/lib/yuno/proofreader/analysis/judgments.rb +50 -52
- data/lib/yuno/proofreader/analysis/links.rb +44 -46
- data/lib/yuno/proofreader/analysis/list_order.rb +20 -22
- data/lib/yuno/proofreader/analysis/reasons.rb +44 -43
- data/lib/yuno/proofreader/analysis/report.rb +79 -81
- data/lib/yuno/proofreader/analysis/runner.rb +133 -135
- data/lib/yuno/proofreader/analysis/scorer.rb +97 -99
- data/lib/yuno/proofreader/analysis/settings.rb +65 -67
- data/lib/yuno/proofreader/analysis/signals.rb +77 -79
- data/lib/yuno/proofreader/analysis/structured_data.rb +40 -42
- data/lib/yuno/proofreader/analysis/url_tree.rb +34 -36
- data/lib/yuno/proofreader/analysis/weights.rb +67 -69
- data/lib/yuno/proofreader/audit/agenda.rb +63 -65
- data/lib/yuno/proofreader/audit/agenda_report.rb +44 -46
- data/lib/yuno/proofreader/audit/answers.rb +53 -55
- data/lib/yuno/proofreader/audit/attempt.rb +50 -52
- data/lib/yuno/proofreader/audit/batch.rb +49 -49
- data/lib/yuno/proofreader/audit/batch_report.rb +62 -64
- data/lib/yuno/proofreader/audit/cadence.rb +47 -49
- data/lib/yuno/proofreader/audit/instructions.rb +15 -17
- data/lib/yuno/proofreader/audit/log_fields.rb +16 -18
- data/lib/yuno/proofreader/audit/prompt.rb +118 -120
- data/lib/yuno/proofreader/audit/report.rb +116 -118
- data/lib/yuno/proofreader/audit/runner.rb +150 -152
- data/lib/yuno/proofreader/audit/schemas.rb +49 -0
- data/lib/yuno/proofreader/audit/steps.rb +46 -48
- data/lib/yuno/proofreader/cli/analysis_commands.rb +36 -38
- data/lib/yuno/proofreader/cli/audit_commands.rb +89 -91
- data/lib/yuno/proofreader/cli/command_log.rb +34 -36
- data/lib/yuno/proofreader/cli/flags.rb +33 -35
- data/lib/yuno/proofreader/cli/generate_commands.rb +99 -101
- data/lib/yuno/proofreader/cli/init_command.rb +123 -125
- data/lib/yuno/proofreader/cli/model_commands.rb +35 -37
- data/lib/yuno/proofreader/cli/queue_commands.rb +79 -81
- data/lib/yuno/proofreader/cli/sheet_commands.rb +42 -44
- data/lib/yuno/proofreader/cli.rb +197 -199
- data/lib/yuno/proofreader/config.rb +13 -17
- data/lib/yuno/proofreader/context.rb +45 -50
- data/lib/yuno/proofreader/env_file.rb +52 -56
- data/lib/yuno/proofreader/errors.rb +7 -9
- data/lib/yuno/proofreader/findings/finding.rb +73 -75
- data/lib/yuno/proofreader/findings/matching.rb +21 -23
- data/lib/yuno/proofreader/findings/merger.rb +35 -37
- data/lib/yuno/proofreader/findings/outline.rb +50 -52
- data/lib/yuno/proofreader/findings/plan.rb +14 -16
- data/lib/yuno/proofreader/findings/reconciler.rb +170 -172
- data/lib/yuno/proofreader/findings/source.rb +54 -56
- data/lib/yuno/proofreader/findings/text.rb +24 -26
- data/lib/yuno/proofreader/generate/cache.rb +54 -56
- data/lib/yuno/proofreader/generate/collector.rb +98 -100
- data/lib/yuno/proofreader/generate/describe.rb +18 -20
- data/lib/yuno/proofreader/generate/llm/prompt.rb +50 -52
- data/lib/yuno/proofreader/generate/llm/reader.rb +84 -86
- data/lib/yuno/proofreader/generate/llm/wording.rb +12 -14
- data/lib/yuno/proofreader/generate/llms_builder.rb +36 -38
- data/lib/yuno/proofreader/generate/llms_report.rb +82 -84
- data/lib/yuno/proofreader/generate/llms_txt.rb +99 -101
- data/lib/yuno/proofreader/generate/llms_writer.rb +43 -45
- data/lib/yuno/proofreader/generate/outline.rb +67 -69
- data/lib/yuno/proofreader/generate/passage.rb +41 -43
- data/lib/yuno/proofreader/generate/saved_answer.rb +42 -44
- data/lib/yuno/proofreader/http/client.rb +94 -96
- data/lib/yuno/proofreader/http/net_http_transport.rb +35 -37
- data/lib/yuno/proofreader/http/robots.rb +51 -53
- data/lib/yuno/proofreader/init/ask.rb +45 -47
- data/lib/yuno/proofreader/init/detector.rb +75 -77
- data/lib/yuno/proofreader/init/interview.rb +155 -157
- data/lib/yuno/proofreader/init/parsing.rb +37 -39
- data/lib/yuno/proofreader/init/web.rb +22 -24
- data/lib/yuno/proofreader/llm/client.rb +118 -113
- data/lib/yuno/proofreader/llm/defaults.rb +10 -12
- data/lib/yuno/proofreader/llm/errors.rb +18 -18
- data/lib/yuno/proofreader/llm/factory.rb +34 -36
- data/lib/yuno/proofreader/llm/handoff.rb +86 -88
- data/lib/yuno/proofreader/llm/http_transport.rb +25 -27
- data/lib/yuno/proofreader/llm/json_text.rb +12 -14
- data/lib/yuno/proofreader/llm/provider.rb +49 -51
- data/lib/yuno/proofreader/llm/providers/gemini.rb +111 -111
- data/lib/yuno/proofreader/llm/providers/manual.rb +34 -36
- data/lib/yuno/proofreader/llm/providers.rb +17 -19
- data/lib/yuno/proofreader/llm/types.rb +6 -8
- data/lib/yuno/proofreader/llm/usage.rb +8 -10
- data/lib/yuno/proofreader/log.rb +88 -96
- data/lib/yuno/proofreader/pages/fetcher.rb +53 -55
- data/lib/yuno/proofreader/pages/report.rb +37 -39
- data/lib/yuno/proofreader/pages/snapshot.rb +32 -34
- data/lib/yuno/proofreader/pages/trimmer.rb +23 -25
- data/lib/yuno/proofreader/settings_file.rb +35 -38
- data/lib/yuno/proofreader/site.rb +52 -54
- data/lib/yuno/proofreader/site_reader.rb +122 -124
- data/lib/yuno/proofreader/sitemap/aligner.rb +58 -60
- data/lib/yuno/proofreader/sitemap/importer.rb +19 -21
- data/lib/yuno/proofreader/sitemap/loader.rb +95 -97
- data/lib/yuno/proofreader/sitemap/mismatch.rb +53 -55
- data/lib/yuno/proofreader/sitemap/pairer.rb +171 -173
- data/lib/yuno/proofreader/sitemap/parser.rb +50 -52
- data/lib/yuno/proofreader/sitemap/report.rb +72 -74
- data/lib/yuno/proofreader/store/cells.rb +55 -49
- data/lib/yuno/proofreader/store/gateways/csv.rb +53 -56
- data/lib/yuno/proofreader/store/gateways/google.rb +152 -158
- data/lib/yuno/proofreader/store/memory.rb +60 -64
- data/lib/yuno/proofreader/store/records.rb +18 -20
- data/lib/yuno/proofreader/store/schema.rb +85 -89
- data/lib/yuno/proofreader/store/sheets.rb +132 -145
- data/lib/yuno/proofreader/store/tab_setup.rb +51 -54
- data/lib/yuno/proofreader/version.rb +1 -1
- data/lib/yuno/proofreader.rb +3 -4
- data/proofreader.example.yml +15 -10
- metadata +3 -2
|
@@ -1,108 +1,104 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Yuno
|
|
4
|
-
module
|
|
5
|
-
|
|
6
|
-
STATUSES = ["open", "on staging", "done", "rejected"].freeze
|
|
3
|
+
module Yuno::Proofreader
|
|
4
|
+
module Store
|
|
5
|
+
STATUSES = ["open", "on staging", "done", "rejected"].freeze
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def initialize(name:, type: :text, width: 120, wrap: false) = super
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# What a tab looks like: its columns, the ones that must exist, the dropdown columns and the grid size.
|
|
15
|
-
TabSchema = Data.define(:title, :columns, :required, :dropdowns, :rows) do
|
|
16
|
-
def names = columns.map(&:name)
|
|
7
|
+
Column = Data.define(:name, :type, :width, :wrap) do
|
|
8
|
+
def initialize(name:, type: :text, width: 120, wrap: false) = super
|
|
9
|
+
end
|
|
17
10
|
|
|
18
|
-
|
|
11
|
+
# What a tab looks like: its columns, the ones that must exist, the dropdown columns and the grid size.
|
|
12
|
+
TabSchema = Data.define(:title, :columns, :required, :dropdowns, :rows) do
|
|
13
|
+
def names = columns.map(&:name)
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
def absent(header) = names - normalized(header)
|
|
15
|
+
def column(name) = columns.find { |column| column.name == name }
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return if missing.empty?
|
|
17
|
+
# The columns of the schema that a header row lacks, required or not.
|
|
18
|
+
def absent(header) = names - normalized(header)
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
def check!(header)
|
|
21
|
+
missing = required - normalized(header)
|
|
22
|
+
return if missing.empty?
|
|
30
23
|
|
|
31
|
-
|
|
24
|
+
raise StoreError, "Tab #{title} is missing the column(s) #{missing.join(', ')}. Add them to the header row " \
|
|
25
|
+
"with exactly these names, or delete the tab and run prepare again."
|
|
32
26
|
end
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
SUGGESTION_COLUMNS = [
|
|
37
|
-
Column.new(name: "timestamp", type: :datetime, width: 150),
|
|
38
|
-
Column.new(name: "page", width: 180),
|
|
39
|
-
Column.new(name: "language", width: 80),
|
|
40
|
-
Column.new(name: "category", width: 100),
|
|
41
|
-
Column.new(name: "effort", width: 80),
|
|
42
|
-
Column.new(name: "approximate_place", width: 220, wrap: true),
|
|
43
|
-
Column.new(name: "original", width: 300, wrap: true),
|
|
44
|
-
Column.new(name: "suggested", width: 300, wrap: true),
|
|
45
|
-
Column.new(name: "reason", width: 300, wrap: true),
|
|
46
|
-
Column.new(name: "verified", width: 80),
|
|
47
|
-
Column.new(name: "status", width: 100),
|
|
48
|
-
Column.new(name: "found_by", width: 110),
|
|
49
|
-
Column.new(name: "last_seen", type: :datetime, width: 150),
|
|
50
|
-
Column.new(name: "amount_seen", type: :integer, width: 90)
|
|
51
|
-
].freeze
|
|
52
|
-
SUGGESTION_REQUIRED = %w[page language category effort original suggested reason verified status].freeze
|
|
28
|
+
def normalized(header) = header.map { |name| name.to_s.strip.downcase }
|
|
29
|
+
end
|
|
53
30
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
31
|
+
# The tabs the tool works with.
|
|
32
|
+
module Schema
|
|
33
|
+
SUGGESTION_COLUMNS = [
|
|
34
|
+
Column.new(name: "timestamp", type: :datetime, width: 150),
|
|
35
|
+
Column.new(name: "page", width: 180),
|
|
36
|
+
Column.new(name: "language", width: 80),
|
|
37
|
+
Column.new(name: "category", width: 100),
|
|
38
|
+
Column.new(name: "effort", width: 80),
|
|
39
|
+
Column.new(name: "approximate_place", width: 220, wrap: true),
|
|
40
|
+
Column.new(name: "original", width: 300, wrap: true),
|
|
41
|
+
Column.new(name: "suggested", width: 300, wrap: true),
|
|
42
|
+
Column.new(name: "reason", width: 300, wrap: true),
|
|
43
|
+
Column.new(name: "verified", width: 80),
|
|
44
|
+
Column.new(name: "status", width: 100),
|
|
45
|
+
Column.new(name: "found_by", width: 110),
|
|
46
|
+
Column.new(name: "last_seen", type: :datetime, width: 150),
|
|
47
|
+
Column.new(name: "amount_seen", type: :integer, width: 90)
|
|
48
|
+
].freeze
|
|
49
|
+
SUGGESTION_REQUIRED = %w[page language category effort original suggested reason verified status].freeze
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
Column.new(name: "freshness", type: :number, width: 80),
|
|
72
|
-
Column.new(name: "changed", width: 100),
|
|
73
|
-
Column.new(name: "route", width: 260, wrap: true),
|
|
74
|
-
Column.new(name: "ai_value", type: :integer, width: 80),
|
|
75
|
-
Column.new(name: "ai_kind", width: 100),
|
|
76
|
-
Column.new(name: "ai_place", width: 180),
|
|
77
|
-
Column.new(name: "ai_certainty", width: 90),
|
|
78
|
-
Column.new(name: "ai_reason", width: 320, wrap: true),
|
|
79
|
-
Column.new(name: "ai_spread", type: :integer, width: 80),
|
|
80
|
-
Column.new(name: "analyzed_at", type: :datetime, width: 150)
|
|
81
|
-
].freeze
|
|
51
|
+
# Written by the analysis, except boost, which a person fills in.
|
|
52
|
+
IMPORTANCE_COLUMNS = [
|
|
53
|
+
Column.new(name: "importance", type: :integer, width: 100),
|
|
54
|
+
Column.new(name: "tier", type: :integer, width: 60),
|
|
55
|
+
Column.new(name: "importance_notes", width: 320, wrap: true),
|
|
56
|
+
Column.new(name: "analyzed_at", type: :datetime, width: 150),
|
|
57
|
+
Column.new(name: "boost", type: :number, width: 70)
|
|
58
|
+
].freeze
|
|
82
59
|
|
|
83
|
-
|
|
60
|
+
ANALYSIS_COLUMNS = [
|
|
61
|
+
Column.new(name: "page_name", width: 220),
|
|
62
|
+
Column.new(name: "address", width: 300),
|
|
63
|
+
Column.new(name: "importance", type: :integer, width: 100),
|
|
64
|
+
Column.new(name: "tier", type: :integer, width: 60),
|
|
65
|
+
Column.new(name: "reach", type: :number, width: 80),
|
|
66
|
+
Column.new(name: "presence", type: :number, width: 80),
|
|
67
|
+
Column.new(name: "mentions", type: :number, width: 80),
|
|
68
|
+
Column.new(name: "freshness", type: :number, width: 80),
|
|
69
|
+
Column.new(name: "changed", width: 100),
|
|
70
|
+
Column.new(name: "route", width: 260, wrap: true),
|
|
71
|
+
Column.new(name: "ai_value", type: :integer, width: 80),
|
|
72
|
+
Column.new(name: "ai_kind", width: 100),
|
|
73
|
+
Column.new(name: "ai_place", width: 180),
|
|
74
|
+
Column.new(name: "ai_certainty", width: 90),
|
|
75
|
+
Column.new(name: "ai_reason", width: 320, wrap: true),
|
|
76
|
+
Column.new(name: "ai_spread", type: :integer, width: 80),
|
|
77
|
+
Column.new(name: "analyzed_at", type: :datetime, width: 150)
|
|
78
|
+
].freeze
|
|
84
79
|
|
|
85
|
-
|
|
86
|
-
urls = languages.map { |code| Column.new(name: "#{code}_url", width: 320) }
|
|
87
|
-
columns = [Column.new(name: "page_name", width: 220), *urls,
|
|
88
|
-
Column.new(name: "last_audited", type: :datetime, width: 150),
|
|
89
|
-
Column.new(name: "fingerprint", width: 130),
|
|
90
|
-
Column.new(name: "note", width: 200),
|
|
91
|
-
Column.new(name: "sitemap_lastmod", width: 130),
|
|
92
|
-
*IMPORTANCE_COLUMNS]
|
|
93
|
-
required = ["page_name", *urls.map(&:name), "last_audited"]
|
|
94
|
-
TabSchema.new(title: "Pages", columns:, required:, dropdowns: {}, rows: 1_000)
|
|
95
|
-
end
|
|
80
|
+
module_function
|
|
96
81
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
82
|
+
def pages(languages)
|
|
83
|
+
urls = languages.map { |code| Column.new(name: "#{code}_url", width: 320) }
|
|
84
|
+
columns = [Column.new(name: "page_name", width: 220), *urls,
|
|
85
|
+
Column.new(name: "last_audited", type: :datetime, width: 150),
|
|
86
|
+
Column.new(name: "fingerprint", width: 130),
|
|
87
|
+
Column.new(name: "note", width: 200),
|
|
88
|
+
Column.new(name: "sitemap_lastmod", width: 130),
|
|
89
|
+
*IMPORTANCE_COLUMNS]
|
|
90
|
+
required = ["page_name", *urls.map(&:name), "last_audited"]
|
|
91
|
+
TabSchema.new(title: "Pages", columns:, required:, dropdowns: {}, rows: 1_000)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def suggestions
|
|
95
|
+
TabSchema.new(title: "Suggestions", columns: SUGGESTION_COLUMNS, required: SUGGESTION_REQUIRED,
|
|
96
|
+
dropdowns: { "status" => STATUSES }, rows: 5_000)
|
|
97
|
+
end
|
|
101
98
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
end
|
|
99
|
+
def analysis
|
|
100
|
+
TabSchema.new(title: "Analysis", columns: ANALYSIS_COLUMNS, required: %w[page_name address], dropdowns: {},
|
|
101
|
+
rows: 1_000)
|
|
106
102
|
end
|
|
107
103
|
end
|
|
108
104
|
end
|
|
@@ -1,187 +1,174 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Yuno
|
|
4
|
-
module
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# The same store on a folder of CSV files.
|
|
17
|
-
def self.local(site, dir:)
|
|
18
|
-
schemas = [Schema.pages(site.languages), Schema.suggestions, Schema.analysis]
|
|
19
|
-
new(CsvGateway.new(dir:, schemas:), site)
|
|
20
|
-
end
|
|
3
|
+
module Yuno::Proofreader
|
|
4
|
+
module Store
|
|
5
|
+
# Keeps the pages, the suggestions and the analysis in tabs
|
|
6
|
+
class Sheets
|
|
7
|
+
Table = Data.define(:index, :rows, :width)
|
|
8
|
+
IMPORTANCE = %w[importance tier importance_notes analyzed_at].freeze
|
|
9
|
+
|
|
10
|
+
def self.connect(config, site)
|
|
11
|
+
require_relative "gateways/google"
|
|
12
|
+
new(GoogleGateway.new(spreadsheet_id: config.spreadsheet_id), site)
|
|
13
|
+
end
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@suggestions_schema = Schema.suggestions
|
|
27
|
-
@analysis_schema = Schema.analysis
|
|
28
|
-
end
|
|
15
|
+
def self.local(site, dir:)
|
|
16
|
+
schemas = [Schema.pages(site.languages), Schema.suggestions, Schema.analysis]
|
|
17
|
+
new(CsvGateway.new(dir:, schemas:), site)
|
|
18
|
+
end
|
|
29
19
|
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
def initialize(gateway, site)
|
|
21
|
+
@gateway = gateway
|
|
22
|
+
@languages = site.languages
|
|
23
|
+
@pages_schema = Schema.pages(@languages)
|
|
24
|
+
@suggestions_schema = Schema.suggestions
|
|
25
|
+
@analysis_schema = Schema.analysis
|
|
26
|
+
end
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
table = read_table(@pages_schema)
|
|
35
|
-
data_rows(table).map { |cells, row| page_record(table, cells, row) }
|
|
36
|
-
end
|
|
28
|
+
def prepare = TabSetup.new(@gateway, [@pages_schema, @suggestions_schema, @analysis_schema]).call
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
def pages
|
|
31
|
+
table = read_table(@pages_schema)
|
|
32
|
+
data_rows(table).map { |cells, row| page_record(table, cells, row) }
|
|
33
|
+
end
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
pages.size
|
|
45
|
-
end
|
|
35
|
+
def add_pages(pages)
|
|
36
|
+
return 0 if pages.empty?
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
table = read_table(@pages_schema)
|
|
39
|
+
@gateway.append(@pages_schema.title, pages.map { |page| build_row(table, @pages_schema, page_values(page)) })
|
|
40
|
+
pages.size
|
|
41
|
+
end
|
|
51
42
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
def record_audit(record, fingerprint:, at:)
|
|
44
|
+
table = read_table(@pages_schema)
|
|
45
|
+
change_rows(table, @pages_schema, { record.row => { last_audited: at, fingerprint: } })
|
|
46
|
+
end
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
unless missing.empty?
|
|
60
|
-
raise StoreError, "Tab Pages lacks the column(s) #{missing.join(', ')}. Type them at the end of its " \
|
|
61
|
-
"header row, with exactly these names. Run prepare to see every column it lacks."
|
|
62
|
-
end
|
|
48
|
+
def record_importance(updates)
|
|
49
|
+
return if updates.empty?
|
|
63
50
|
|
|
64
|
-
|
|
51
|
+
table = read_table(@pages_schema)
|
|
52
|
+
missing = IMPORTANCE - table.index.keys
|
|
53
|
+
unless missing.empty?
|
|
54
|
+
raise StoreError, "Tab Pages lacks the column(s) #{missing.join(', ')}. Type them at the end of its " \
|
|
55
|
+
"header row, with exactly these names. Run prepare to see every column it lacks."
|
|
65
56
|
end
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
records = data_rows(table).map { |cells, row| suggestion_record(table, cells, row) }
|
|
70
|
-
page_name ? records.select { |record| record.page == page_name } : records
|
|
71
|
-
end
|
|
58
|
+
change_rows(table, @pages_schema, updates)
|
|
59
|
+
end
|
|
72
60
|
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
def suggestions(page_name = nil)
|
|
62
|
+
table = read_table(@suggestions_schema)
|
|
63
|
+
records = data_rows(table).map { |cells, row| suggestion_record(table, cells, row) }
|
|
64
|
+
page_name ? records.select { |record| record.page == page_name } : records
|
|
65
|
+
end
|
|
75
66
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
@gateway.append(@suggestions_schema.title, rows)
|
|
79
|
-
records.size
|
|
80
|
-
end
|
|
67
|
+
def add_suggestions(records)
|
|
68
|
+
return 0 if records.empty?
|
|
81
69
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
table = read_table(@suggestions_schema)
|
|
71
|
+
rows = records.map { |record| build_row(table, @suggestions_schema, record.to_h.except(:row)) }
|
|
72
|
+
@gateway.append(@suggestions_schema.title, rows)
|
|
73
|
+
records.size
|
|
74
|
+
end
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
|
|
76
|
+
def update_suggestions(updates)
|
|
77
|
+
return if updates.empty?
|
|
88
78
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
table = read_table(@analysis_schema)
|
|
92
|
-
data_rows(table).map { |cells, row| { row:, **attributes(table, @analysis_schema, cells) } }
|
|
93
|
-
end
|
|
79
|
+
change_rows(read_table(@suggestions_schema), @suggestions_schema, updates)
|
|
80
|
+
end
|
|
94
81
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
built = rows.map { |values| build_row(table, @analysis_schema, values) }
|
|
100
|
-
height = table.rows.size
|
|
101
|
-
blank = Array.new(table.width, "")
|
|
102
|
-
kept = (0...height).map { |index| built[index] || blank }
|
|
103
|
-
@gateway.update_cells(@analysis_schema.title,
|
|
104
|
-
kept.each_with_index.flat_map { |values, index| row_cells(index + 2, values) })
|
|
105
|
-
@gateway.append(@analysis_schema.title, built.drop(height)) if built.size > height
|
|
106
|
-
end
|
|
82
|
+
def analysis_rows
|
|
83
|
+
table = read_table(@analysis_schema)
|
|
84
|
+
data_rows(table).map { |cells, row| { row:, **attributes(table, @analysis_schema, cells) } }
|
|
85
|
+
end
|
|
107
86
|
|
|
108
|
-
|
|
87
|
+
def replace_analysis(rows)
|
|
88
|
+
table = read_table(@analysis_schema)
|
|
89
|
+
built = rows.map { |values| build_row(table, @analysis_schema, values) }
|
|
90
|
+
height = table.rows.size
|
|
91
|
+
blank = Array.new(table.width, "")
|
|
92
|
+
kept = (0...height).map { |index| built[index] || blank }
|
|
93
|
+
@gateway.update_cells(@analysis_schema.title,
|
|
94
|
+
kept.each_with_index.flat_map { |values, index| row_cells(index + 2, values) })
|
|
95
|
+
@gateway.append(@analysis_schema.title, built.drop(height)) if built.size > height
|
|
96
|
+
end
|
|
109
97
|
|
|
110
|
-
|
|
98
|
+
private
|
|
111
99
|
|
|
112
|
-
|
|
113
|
-
values = @gateway.read(schema.title)
|
|
114
|
-
header = values.first.to_a.map { |name| name.to_s.strip.downcase }
|
|
115
|
-
schema.check!(header)
|
|
116
|
-
Table.new(index: header.each_with_index.to_h, rows: values.drop(1), width: header.size)
|
|
117
|
-
end
|
|
100
|
+
# ---- reading ----
|
|
118
101
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
102
|
+
def read_table(schema)
|
|
103
|
+
values = @gateway.read(schema.title)
|
|
104
|
+
header = values.first.to_a.map { |name| name.to_s.strip.downcase }
|
|
105
|
+
schema.check!(header)
|
|
106
|
+
Table.new(index: header.each_with_index.to_h, rows: values.drop(1), width: header.size)
|
|
107
|
+
end
|
|
125
108
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
[column.name.to_sym, Cells.from_cell(position ? cells[position] : "", column.type)]
|
|
130
|
-
end
|
|
109
|
+
def data_rows(table)
|
|
110
|
+
table.rows.each_with_index.filter_map do |cells, index|
|
|
111
|
+
[cells, index + 2] unless cells.all? { |cell| cell.to_s.strip.empty? }
|
|
131
112
|
end
|
|
113
|
+
end
|
|
132
114
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
fingerprint: attrs[:fingerprint], note: attrs[:note], sitemap_lastmod: attrs[:sitemap_lastmod],
|
|
138
|
-
importance: attrs[:importance], tier: attrs[:tier], boost: attrs[:boost])
|
|
115
|
+
def attributes(table, schema, cells)
|
|
116
|
+
schema.columns.to_h do |column|
|
|
117
|
+
position = table.index[column.name]
|
|
118
|
+
[column.name.to_sym, Cells.from_cell(position ? cells[position] : "", column.type)]
|
|
139
119
|
end
|
|
120
|
+
end
|
|
140
121
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
122
|
+
def page_record(table, cells, row)
|
|
123
|
+
attrs = attributes(table, @pages_schema, cells)
|
|
124
|
+
urls = @languages.to_h { |code| [code, attrs[:"#{code}_url"].strip] }.reject { |_code, url| url.empty? }
|
|
125
|
+
PageRecord.new(row:, name: attrs[:page_name], urls:, last_audited: attrs[:last_audited],
|
|
126
|
+
fingerprint: attrs[:fingerprint], note: attrs[:note], sitemap_lastmod: attrs[:sitemap_lastmod],
|
|
127
|
+
importance: attrs[:importance], tier: attrs[:tier], boost: attrs[:boost])
|
|
128
|
+
end
|
|
144
129
|
|
|
145
|
-
|
|
130
|
+
def suggestion_record(table, cells, row)
|
|
131
|
+
SuggestionRecord.build(row:, **attributes(table, @suggestions_schema, cells))
|
|
132
|
+
end
|
|
146
133
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
134
|
+
# ---- writing ----
|
|
135
|
+
|
|
136
|
+
def page_values(page)
|
|
137
|
+
values = { "page_name" => page.name, "note" => page.notes.join("; "), "sitemap_lastmod" => page.lastmod }
|
|
138
|
+
@languages.each { |code| values["#{code}_url"] = page.urls[code] }
|
|
139
|
+
values
|
|
140
|
+
end
|
|
152
141
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
cells[position] = Cells.to_cell(value, schema.column(name.to_s).type) if position
|
|
159
|
-
end
|
|
160
|
-
cells
|
|
142
|
+
def build_row(table, schema, values)
|
|
143
|
+
cells = Array.new(table.width, "")
|
|
144
|
+
values.each do |name, value|
|
|
145
|
+
position = table.index[name.to_s]
|
|
146
|
+
cells[position] = Cells.to_cell(value, schema.column(name.to_s).type) if position
|
|
161
147
|
end
|
|
148
|
+
cells
|
|
149
|
+
end
|
|
162
150
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
151
|
+
def change_rows(table, schema, changes)
|
|
152
|
+
last_row = table.rows.size + 1
|
|
153
|
+
cells = changes.flat_map do |row, values|
|
|
154
|
+
raise StoreError, "There is no row #{row} in #{schema.title}" unless row.to_i.between?(2, last_row)
|
|
167
155
|
|
|
168
|
-
|
|
169
|
-
end
|
|
170
|
-
@gateway.update_cells(schema.title, cells)
|
|
156
|
+
changed_cells(table, schema, row, values)
|
|
171
157
|
end
|
|
158
|
+
@gateway.update_cells(schema.title, cells)
|
|
159
|
+
end
|
|
172
160
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
161
|
+
def changed_cells(table, schema, row, values)
|
|
162
|
+
values.filter_map do |name, value|
|
|
163
|
+
column = schema.column(name.to_s)
|
|
164
|
+
raise StoreError, "Unknown field #{name} for #{schema.title}" unless column
|
|
177
165
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
end
|
|
166
|
+
position = table.index[column.name]
|
|
167
|
+
[row, position + 1, Cells.to_cell(value, column.type)] if position
|
|
181
168
|
end
|
|
182
|
-
|
|
183
|
-
def row_cells(row, values) = values.each_with_index.map { |value, index| [row, index + 1, value] }
|
|
184
169
|
end
|
|
170
|
+
|
|
171
|
+
def row_cells(row, values) = values.each_with_index.map { |value, index| [row, index + 1, value] }
|
|
185
172
|
end
|
|
186
173
|
end
|
|
187
174
|
end
|
|
@@ -1,72 +1,69 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Yuno
|
|
4
|
-
module
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class TabSetup
|
|
9
|
-
DEFAULT_TABS = %w[Sheet1 Tabellenblatt1].freeze
|
|
3
|
+
module Yuno::Proofreader
|
|
4
|
+
module Store
|
|
5
|
+
# Sets up the tabs of the sheet
|
|
6
|
+
class TabSetup
|
|
7
|
+
DEFAULT_TABS = %w[Sheet1 Tabellenblatt1].freeze
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
def initialize(gateway, schemas)
|
|
10
|
+
@gateway = gateway
|
|
11
|
+
@schemas = schemas
|
|
12
|
+
end
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
def call
|
|
15
|
+
tabs = @gateway.tabs
|
|
16
|
+
@schemas.flat_map { |schema| prepare_tab(schema, tabs) } + remove_default_tab
|
|
17
|
+
end
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
private
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
def prepare_tab(schema, tabs)
|
|
22
|
+
title = schema.title
|
|
23
|
+
return create_tab(schema) unless tabs.key?(title)
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
header = @gateway.read(title).first.to_a
|
|
26
|
+
return fill_tab(schema, tabs[title]) if header.empty?
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
schema.check!(header)
|
|
29
|
+
existing(schema, header)
|
|
30
|
+
end
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
# A tab that exists keeps its columns as they are. Columns a newer version of the tool added are named, so
|
|
33
|
+
# they can be typed at the end of the header row.
|
|
34
|
+
def existing(schema, header)
|
|
35
|
+
absent = schema.absent(header)
|
|
36
|
+
return ["Tab #{schema.title} already exists."] if absent.empty?
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
["Tab #{schema.title} already exists, but lacks the column(s) #{absent.join(', ')}. Type them at the end " \
|
|
39
|
+
"of its header row, with exactly these names."]
|
|
40
|
+
end
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
def create_tab(schema)
|
|
43
|
+
sheet_id = @gateway.add_tab(schema.title, rows: schema.rows, columns: schema.columns.size)
|
|
44
|
+
write_header(schema)
|
|
45
|
+
@gateway.format_tab(sheet_id, schema)
|
|
46
|
+
["Created tab #{schema.title}."]
|
|
47
|
+
end
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
def fill_tab(schema, sheet_id)
|
|
50
|
+
write_header(schema)
|
|
51
|
+
@gateway.format_tab(sheet_id, schema)
|
|
52
|
+
["Set up the empty tab #{schema.title}."]
|
|
53
|
+
end
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
def write_header(schema)
|
|
56
|
+
cells = schema.names.each_with_index.map { |name, index| [1, index + 1, name] }
|
|
57
|
+
@gateway.update_cells(schema.title, cells)
|
|
58
|
+
end
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
def remove_default_tab
|
|
61
|
+
ours = @schemas.map(&:title)
|
|
62
|
+
@gateway.tabs.filter_map do |title, sheet_id|
|
|
63
|
+
next unless DEFAULT_TABS.include?(title) && !ours.include?(title) && @gateway.read(title).empty?
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
end
|
|
65
|
+
@gateway.delete_tab(sheet_id)
|
|
66
|
+
"Removed the empty tab #{title}."
|
|
70
67
|
end
|
|
71
68
|
end
|
|
72
69
|
end
|