Skip to content

Commit

Permalink
Handle somevalue time statements with irrelevant qualifiers
Browse files Browse the repository at this point in the history
Some qualifiers on somevalue time statements can affect the time itself,
e.g., https://www.wikidata.org/wiki/Property:P1326 latest date. But
others have no effect on the time, so ignore them.
  • Loading branch information
dseomn committed Nov 14, 2024
1 parent f852eb1 commit 091ec89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions rock_paper_sand/wikidata_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def human_readable_url_prefix(cls) -> str:
P_MODIFIED_VERSION_OF = _p("https://www.wikidata.org/wiki/Property:P5059")
P_PART_OF = _p("https://www.wikidata.org/wiki/Property:P361")
P_PART_OF_THE_SERIES = _p("https://www.wikidata.org/wiki/Property:P179")
P_PLACE_OF_PUBLICATION = _p("https://www.wikidata.org/wiki/Property:P291")
P_PLOT_EXPANDED_IN = _p("https://www.wikidata.org/wiki/Property:P5940")
P_PUBLICATION_DATE = _p("https://www.wikidata.org/wiki/Property:P577")
P_SEASON = _p("https://www.wikidata.org/wiki/Property:P4908")
Expand Down Expand Up @@ -381,10 +382,13 @@ def time_value(
case "value":
return mainsnak.time_value()
case "somevalue":
if self.json.get("qualifiers", {}):
noop_qualifiers = {
P_PLACE_OF_PUBLICATION.id,
}
if self.json.get("qualifiers", {}).keys() - noop_qualifiers:
raise NotImplementedError(
"Cannot parse somevalue time with qualifiers: "
f"{self.json}"
"Cannot parse somevalue time with unsupported "
f"qualifiers: {self.json}"
)
else:
return (None, None)
Expand Down
9 changes: 6 additions & 3 deletions rock_paper_sand/wikidata_value_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,13 @@ def test_statement_qualifiers(
error_regex=r"non-time",
),
dict(
testcase_name="somevalue_with_qualifiers",
testcase_name="somevalue_with_unsupported_qualifiers",
statement={
"mainsnak": {"snaktype": "somevalue", "datatype": "time"},
"qualifiers": {"P1": []},
},
error_class=NotImplementedError,
error_regex=r"somevalue time with qualifiers",
error_regex=r"somevalue time with unsupported qualifiers",
),
dict(
testcase_name="invalid_snaktype",
Expand Down Expand Up @@ -467,7 +467,10 @@ def test_statement_time_error(
("2000-01-01T00:00:00+00:00", "2000-01-01T23:59:59.999999+00:00"),
),
(
{"mainsnak": {"snaktype": "somevalue", "datatype": "time"}},
{
"mainsnak": {"snaktype": "somevalue", "datatype": "time"},
"qualifiers": {wikidata_value.P_PLACE_OF_PUBLICATION.id: []},
},
(None, None),
),
(
Expand Down

0 comments on commit 091ec89

Please sign in to comment.