Smalyshev has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/355570 )
Change subject: Recognize normalized values and keep them. ...................................................................... Recognize normalized values and keep them. Bug: T166196 Change-Id: I849a03039975e67d0cece32025dd167f41c9ef30 --- M common/src/main/java/org/wikidata/query/rdf/common/uri/Ontology.java M tools/src/main/java/org/wikidata/query/rdf/tool/rdf/Munger.java M tools/src/test/java/org/wikidata/query/rdf/tool/rdf/MungerUnitTest.java 3 files changed, 42 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/rdf refs/changes/70/355570/1 diff --git a/common/src/main/java/org/wikidata/query/rdf/common/uri/Ontology.java b/common/src/main/java/org/wikidata/query/rdf/common/uri/Ontology.java index a8222e7..1501559 100644 --- a/common/src/main/java/org/wikidata/query/rdf/common/uri/Ontology.java +++ b/common/src/main/java/org/wikidata/query/rdf/common/uri/Ontology.java @@ -177,6 +177,10 @@ * The unit of the quantity. */ public static final String UNIT = PREFIX + "Unit"; + /** + * Normalized value for quantity. + */ + public static final String NORMALIZED = PREFIX + "Normalized"; private Quantity() { // Utility class. 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 b787893..aca9281 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 @@ -35,6 +35,7 @@ import org.wikidata.query.rdf.common.WikibasePoint.CoordinateOrder; import org.wikidata.query.rdf.common.uri.OWL; import org.wikidata.query.rdf.common.uri.Ontology; +import org.wikidata.query.rdf.common.uri.Ontology.Quantity; import org.wikidata.query.rdf.common.uri.Provenance; import org.wikidata.query.rdf.common.uri.RDF; import org.wikidata.query.rdf.common.uri.RDFS; @@ -220,7 +221,6 @@ // remove all values that we have seen as they are used by statements existingValues.removeAll(op.extraValidSubjects); existingRefs.removeAll(op.extraValidSubjects); - return; } /** @@ -722,6 +722,14 @@ return false; } break; + case Quantity.NORMALIZED: + /* Keep normalized values. It's a bit tricky here since + * normalized value may not be used yet and when we restore + * regular value we may miss normalized one. So we always add + * normalized ones to allowed list. + */ + registerExtraValidSubject(statement.getObject().stringValue()); + break; default: } if (!extraValidSubjects.contains(subject)) { @@ -822,8 +830,8 @@ throw new BadSubjectException(unknownSubjects.keySet(), uris); } else { log.info( - "Unrecognized subjects: {}. Expected only sitelinks and subjects starting with {} and {}", - unknownSubjects.keySet(), uris.entityData(), uris.entity()); + "Unrecognized subjects: {} while processing {}. Expected only sitelinks and subjects starting with {} and {}", + unknownSubjects.keySet(), entityUri, uris.entityData(), uris.entity()); } } if (revisionId == null) { 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 a9ff440..efec12a 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 @@ -178,6 +178,33 @@ } @Test + public void valueWithNormalized() { + String statementUri = uris.statement() + "q1-someuuid"; + String valueUri = uris.value() + "someotheruuid"; + String valueNormUri = uris.value() + "normalizedvalue"; + entity("Q1") + // + .retain(statement("Q1", "P580", statementUri), // + statement(statementUri, uris.value() + "P580", new LiteralImpl("-13798000000-01-01T00:00:00Z", + XMLSchema.DATETIME)), // + statement(statementUri, uris.value() + "P580" + "-value", valueUri), + // Currently wikibase exports the deep time values as + // strings, not dateTime. + statement(valueUri, Ontology.Quantity.AMOUNT, new IntegerLiteralImpl(BigInteger.valueOf(123))), + statement(valueUri, Ontology.Quantity.UNIT, "Q12345"), + statement(valueUri, Ontology.Quantity.NORMALIZED, valueNormUri), + statement(valueNormUri, Ontology.Quantity.AMOUNT, new IntegerLiteralImpl(BigInteger.valueOf(456))), + statement(valueNormUri, Ontology.Quantity.UNIT, "Q4567"), + statement(valueNormUri, Ontology.Quantity.NORMALIZED, valueNormUri) + ) + .remove(statement(statementUri, RDF.TYPE, Ontology.STATEMENT), + statement(valueNormUri, RDF.TYPE, Ontology.VALUE), + statement(valueUri, RDF.TYPE, Ontology.VALUE)) + .testWithoutShuffle(); + + } + + @Test public void expandedValueOnQualifier() { String statementUri = uris.statement() + "q1-someuuid"; String valueUri = uris.value() + "someotheruuid"; -- To view, visit https://gerrit.wikimedia.org/r/355570 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I849a03039975e67d0cece32025dd167f41c9ef30 Gerrit-PatchSet: 1 Gerrit-Project: wikidata/query/rdf Gerrit-Branch: master Gerrit-Owner: Smalyshev <smalys...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits