Skip to content

Commit

Permalink
Add country to item (#25)
Browse files Browse the repository at this point in the history
Add country of citizenship, converted from MARC code, using prepared mapping file.

Task: https://phabricator.wikimedia.org/T203634
  • Loading branch information
Vesihiisi committed Sep 6, 2018
1 parent abd8221 commit a00032b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions importer/Person.py
Expand Up @@ -118,14 +118,18 @@ def set_lifespan(self):
self.add_statement("dead", dead_pwb, ref=self.source)

def set_nationality(self):
"""Add country of nationality, converted from MARC code."""
has_nationality = self.raw_data[1].get("nationality")
if has_nationality:
nationality = self.raw_data[1]["nationality"][0]["@id"].split(
"/")[-1]
country = self.data_files["countries"].get(nationality)
if country:
self.add_statement("citizenship", country, ref=self.source)
"""Add countries of nationality, converted from MARC-ish code."""
country_map = self.data_files["countries"]
nationalities = self.raw_data[1].get("nationality")
if not nationalities:
return
for nat in nationalities:
if nat.get("@id"):
nat_q = [x.get("q")
for x in
country_map if x["name"] == nat["@id"]]
if nat_q:
self.add_statement("citizenship", nat_q, ref=self.source)

def create_sources(self):
"""
Expand Down Expand Up @@ -208,7 +212,7 @@ def __init__(self, raw_data, repository, data_files, existing):

self.set_is()
self.set_uri()
# self.set_nationality()
self.set_nationality()
# self.set_lifespan()
# self.set_profession()
# self.set_surname()
Expand Down
4 changes: 2 additions & 2 deletions importer/mappings/countries.json
Expand Up @@ -17,7 +17,7 @@
{
"count": 5003,
"name": "https://id.kb.se/nationality/xx",
"q": "",
"q": ""
},
{
"count": 4113,
Expand Down Expand Up @@ -177,7 +177,7 @@
{
"count": 195,
"name": "https://id.kb.se/nationality/a-su---",
"q": "Saudi Arabia"
"q": "Q851"
},
{
"count": 192,
Expand Down

0 comments on commit a00032b

Please sign in to comment.