Manybubbles has uploaded a new change for review.
https://gerrit.wikimedia.org/r/203849
Change subject: singleLable option shouldn't make up labels
......................................................................
singleLable option shouldn't make up labels
Originally the idea behind the single label option was that the munge process
would always output only a single label for each entity so you could always
just add a ```?e rdfs:label ?eLabel``` clause to get the label. This sounds
good but to do it you have to add labels to entities that don't have labels
in any of the languages in the fallback chain and thats silly because those
labels are fake. So instead we just don't add any labels if there aren't any
in the fallback chain. The only disadvantage here is that when searching the
graph you have to add a ```OPTIONAL { ?e rdfs:label ?eLabel }``` clause to get
the label. That isn't that big a deal to type anyway and we can reduce the
typing using magic syntax if we need to.
Closes T95779
Change-Id: Ic710816fd577c67a26b97f9a7c7415b65acf6ede
---
M tools/src/main/java/org/wikidata/query/rdf/tool/CliUtils.java
M tools/src/main/java/org/wikidata/query/rdf/tool/rdf/Munger.java
M tools/src/test/java/org/wikidata/query/rdf/tool/MungeIntegrationTest.java
M tools/src/test/java/org/wikidata/query/rdf/tool/rdf/MungerUnitTest.java
4 files changed, 18 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/rdf
refs/changes/49/203849/1
diff --git a/tools/src/main/java/org/wikidata/query/rdf/tool/CliUtils.java
b/tools/src/main/java/org/wikidata/query/rdf/tool/CliUtils.java
index 467e73e..6e1e390 100644
--- a/tools/src/main/java/org/wikidata/query/rdf/tool/CliUtils.java
+++ b/tools/src/main/java/org/wikidata/query/rdf/tool/CliUtils.java
@@ -63,8 +63,9 @@
@Option(longName = "labelLanguage", defaultToNull = true, description
= "Only import labels, aliases, and descriptions in these languages.")
List<String> labelLanguages();
- // TODO this really shouldn't import the Qid for label
- @Option(longName = "singleLabel", defaultToNull = true, description =
"Always import a single label and description using the languages specified as
a fallback list. If there aren't any matching labels or descriptions them the
entity itself is used as the label or description.")
+ @Option(longName = "singleLabel", defaultToNull = true, description =
"Only import a single label and description using the languages "
+ + "specified as a fallback list. If there isn't a label in any
of the specified languages then no label is imported. Ditto for "
+ + "description.")
List<String> singleLabelLanguages();
@Option(description = "Skip site links")
diff --git a/tools/src/main/java/org/wikidata/query/rdf/tool/rdf/Munger.java
b/tools/src/main/java/org/wikidata/query/rdf/tool/rdf/Munger.java
index 2959690..fcf573d 100644
--- a/tools/src/main/java/org/wikidata/query/rdf/tool/rdf/Munger.java
+++ b/tools/src/main/java/org/wikidata/query/rdf/tool/rdf/Munger.java
@@ -78,7 +78,9 @@
}
/**
- * Build a munger that will load only a single label per entity.
+ * Build a munger that will load only a single label per entity. Note that
+ * if there isn't a label in one of the languages then there will be no
+ * label for the entity.
*
* @param languages a fallback chain of languages with the first one being
* the most important
@@ -490,8 +492,8 @@
*/
private void finishSingleLabelMode() {
if (singleLabelModeLanguages != null) {
-
statements.add(singleLabelModeWorkForLabel.collectBestStatement());
-
statements.add(singleLabelModeWorkForDescription.collectBestStatement());
+ singleLabelModeWorkForLabel.addBestStatement(statements);
+ singleLabelModeWorkForDescription.addBestStatement(statements);
}
}
@@ -538,13 +540,12 @@
}
/**
- * Collect the best statement at the end of processing the labels.
+ * Add the best label or description to the statements if there is
+ * one.
*/
- public Statement collectBestStatement() {
- if (bestStatement == null) {
- return new StatementImpl(entityUriImpl, new
URIImpl(RDFS.LABEL), entityUriImpl);
- } else {
- return bestStatement;
+ public void addBestStatement(Collection<Statement> statements) {
+ if (bestStatement != null) {
+ statements.add(bestStatement);
}
}
}
diff --git
a/tools/src/test/java/org/wikidata/query/rdf/tool/MungeIntegrationTest.java
b/tools/src/test/java/org/wikidata/query/rdf/tool/MungeIntegrationTest.java
index 5b78a78..4bce1f1 100644
--- a/tools/src/test/java/org/wikidata/query/rdf/tool/MungeIntegrationTest.java
+++ b/tools/src/test/java/org/wikidata/query/rdf/tool/MungeIntegrationTest.java
@@ -58,7 +58,7 @@
Future<?> f = executor.submit(new Munge(uris, munger, from, to));
httpd.start();
try {
- assertEquals(941, rdfRepository.loadUrl("http://localhost:10999"));
+ assertEquals(939, rdfRepository.loadUrl("http://localhost:10999"));
} finally {
try {
f.get();
diff --git
a/tools/src/test/java/org/wikidata/query/rdf/tool/rdf/MungerUnitTest.java
b/tools/src/test/java/org/wikidata/query/rdf/tool/rdf/MungerUnitTest.java
index ec83423..45eb6e2 100644
--- a/tools/src/test/java/org/wikidata/query/rdf/tool/rdf/MungerUnitTest.java
+++ b/tools/src/test/java/org/wikidata/query/rdf/tool/rdf/MungerUnitTest.java
@@ -371,11 +371,10 @@
assertThat(george, not(hasItem(deLabel)));
george = otherGeorge;
munger.singleLabelMode("ja").munge("Q23", george);
- assertThat(george, hasItem(statement("Q23", RDFS.LABEL, "Q23")));
- assertThat(george, not(hasItem(enLabel)));
- assertThat(george, not(hasItem(itLabel)));
- assertThat(george, not(hasItem(frLabel)));
- assertThat(george, not(hasItem(deLabel)));
+ // There aren't any labels if none are in the languages
+ for (Statement statement : george) {
+ assertThat(statement.getPredicate().stringValue(),
not(equalTo(RDFS.LABEL)));
+ }
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/203849
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic710816fd577c67a26b97f9a7c7415b65acf6ede
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/rdf
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits