Skip to content

Commit 7cb9001

Browse files
committed
Add a Wikidata language option!
Though I don't think there are any formats labelled with another language code yet.
1 parent f4165dd commit 7cb9001

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

cmd/roy/harvest_wikidata.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func harvestWikidata() {
15-
log.Println("roy harvesting Wikidata definitions")
15+
log.Printf("roy harvesting Wikidata definitions: lang '%s'", config.WikidataLang())
1616
err := os.MkdirAll(config.WikidataHome(), os.ModePerm)
1717
if err != nil {
1818
fmt.Errorf("roy: error harvesting Wikidata definitions: %s", err)

cmd/roy/roy.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,15 @@ var (
156156
repetition = build.Int("repetition", config.Repetition(), "define a maximum tolerable repetition in a segment, used in combination with cost to determine segmentation")
157157

158158
// HARVEST
159-
harvest = flag.NewFlagSet("harvest", flag.ExitOnError)
160-
harvestHome = harvest.String("home", config.Home(), "override the default home directory")
161-
harvestDroid = harvest.String("droid", config.Droid(), "set name/path for DROID signature file")
162-
harvestChanges = harvest.Bool("changes", false, "harvest the latest PRONOM release-notes.xml file")
163-
_, htimeout, _, _ = config.HarvestOptions()
164-
timeout = harvest.Duration("timeout", htimeout, "set duration before timing-out harvesting requests e.g. 120s")
165-
throttlef = harvest.Duration("throttle", 0, "set a time to wait HTTP requests e.g. 50ms")
166-
harvestWikidataSig = harvest.Bool("wikidata", false, "harvest a static Wikidata report")
159+
harvest = flag.NewFlagSet("harvest", flag.ExitOnError)
160+
harvestHome = harvest.String("home", config.Home(), "override the default home directory")
161+
harvestDroid = harvest.String("droid", config.Droid(), "set name/path for DROID signature file")
162+
harvestChanges = harvest.Bool("changes", false, "harvest the latest PRONOM release-notes.xml file")
163+
_, htimeout, _, _ = config.HarvestOptions()
164+
timeout = harvest.Duration("timeout", htimeout, "set duration before timing-out harvesting requests e.g. 120s")
165+
throttlef = harvest.Duration("throttle", 0, "set a time to wait HTTP requests e.g. 50ms")
166+
harvestWikidataSig = harvest.Bool("wikidata", false, "harvest a static Wikidata report")
167+
harvestWikidataLang = harvest.String("lang", config.WikidataLang(), "two-letter language-code to download Wikidata strings, e.g. DE (default EN)")
167168

168169
// INSPECT (roy inspect | roy inspect fmt/121 | roy inspect usr/local/mysig.sig | roy inspect 10)
169170
inspect = flag.NewFlagSet("inspect", flag.ExitOnError)
@@ -482,6 +483,9 @@ func setHarvestOptions() {
482483
if *throttlef > 0 {
483484
config.SetHarvestThrottle(*throttlef)
484485
}
486+
if *harvestWikidataLang != "" {
487+
config.SetWikidataLang(*harvestWikidataLang)
488+
}
485489
}
486490

487491
func setSetsOptions() {

pkg/config/wikidata.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"os"
55
"path/filepath"
6+
"strings"
67
)
78

89
var wikidata = struct {
@@ -11,6 +12,9 @@ var wikidata = struct {
1112
nopronom bool
1213
filemode os.FileMode
1314

15+
wikidataLang string
16+
languageTemplate string
17+
1418
endpoint string
1519
sparql string
1620
}{
@@ -20,6 +24,9 @@ var wikidata = struct {
2024
name: "wikidata",
2125
filemode: 0644,
2226

27+
wikidataLang: "en",
28+
languageTemplate: "<<lang>>",
29+
2330
endpoint: "https://query.wikidata.org/sparql",
2431
sparql: `
2532
SELECT DISTINCT ?format ?formatLabel ?puid ?ldd ?extension ?mimetype ?sig ?referenceLabel ?date ?encodingLabel ?offset ?relativityLabel WHERE
@@ -44,7 +51,7 @@ var wikidata = struct {
4451
?format p:P4152 ?object.
4552
?object pq:P2210 ?relativity.
4653
}
47-
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
54+
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],<<lang>>". }
4855
}
4956
order by ?format`,
5057
}
@@ -84,5 +91,15 @@ func WikidataEndpoint() string {
8491

8592
// WikidataSPARQL ...
8693
func WikidataSPARQL() string {
87-
return wikidata.sparql
94+
return strings.Replace(wikidata.sparql, wikidata.languageTemplate, wikidata.wikidataLang, 1)
95+
}
96+
97+
// WikidataLang ...
98+
func WikidataLang() string {
99+
return wikidata.wikidataLang
100+
}
101+
102+
// SetWikidataLang ...
103+
func SetWikidataLang(lang string) {
104+
wikidata.wikidataLang = lang
88105
}

0 commit comments

Comments
 (0)