Skip to content

Commit

Permalink
Adopt upstream helper
Browse files Browse the repository at this point in the history
  • Loading branch information
pudo committed Jul 26, 2022
1 parent f0e8e03 commit be6707f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
41 changes: 3 additions & 38 deletions nomenklatura/enrich/wikidata/qualified.py
@@ -1,47 +1,12 @@
from typing import TYPE_CHECKING, Iterable, Optional, Set
from typing import TYPE_CHECKING
from followthemoney.helpers import post_summary

from nomenklatura.enrich.wikidata.model import Claim

if TYPE_CHECKING:
from nomenklatura.enrich.wikidata import WikidataEnricher


def _position_date(dates: Iterable[Optional[str]]) -> Set[str]:
cleaned: Set[str] = set()
for date in dates:
if date is not None:
cleaned.add(date[:4])
return cleaned


def make_position(
main: str,
comment: Optional[str],
starts: Iterable[Optional[str]],
ends: Iterable[Optional[str]],
dates: Iterable[Optional[str]],
) -> str:
position = main
start = min(_position_date(starts), default="")
end = min(_position_date(ends), default="")
date_range = None
if len(start) or len(end):
date_range = f"{start}-{end}"
dates_ = _position_date(dates)
if date_range is None and len(dates_):
date_range = ", ".join(sorted(dates_))

bracketed = None
if date_range and comment:
bracketed = f"{comment}, {date_range}"
else:
bracketed = comment or date_range

if bracketed:
position = f"{position} ({bracketed})"
return position


def qualify_value(enricher: "WikidataEnricher", value: str, claim: Claim) -> str:
starts = set()
for qual in claim.get_qualifier("P580"):
Expand All @@ -55,4 +20,4 @@ def qualify_value(enricher: "WikidataEnricher", value: str, claim: Claim) -> str
for qual in claim.get_qualifier("P585"):
dates.add(qual.text(enricher))

return make_position(value, None, starts, ends, [])
return post_summary(value, None, starts, ends, [])
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -21,7 +21,7 @@
package_data={"": ["nomenklatura/data/*", "nomenklatura/py.typed"]},
zip_safe=False,
install_requires=[
"followthemoney >= 3.0.0, < 4.0.0",
"followthemoney >= 3.0.3, < 4.0.0",
"shortuuid >= 1.0.1, < 2.0.0",
"rich >= 10.9.0, < 13.0.0",
"textual >= 0.1.10, < 1.0.0",
Expand Down

0 comments on commit be6707f

Please sign in to comment.