Skip to content

Commit

Permalink
agents concepts places: add other identifiers
Browse files Browse the repository at this point in the history
* Adds `identifiedBy` for `035` values with `$2` for IDREF.
* Update dependencies.

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Jul 12, 2024
1 parent 0d16ac4 commit e8d7b50
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 300 deletions.
446 changes: 230 additions & 216 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rero_mef/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
#: Template for error pages.
THEME_ERROR_TEMPLATE = "rero_mef/page_error.html"

WEBPACKEXT_PROJECT = 'rero_mef.theme.webpack:project'
WEBPACKEXT_PROJECT = "rero_mef.theme.webpack:project"

# Email configuration
# ===================
Expand Down
10 changes: 4 additions & 6 deletions rero_mef/jsonschemas/common/agent-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@
"type": {
"enum": [
"bf:Local",
"uri"
"uri",
"bf:Nbn"
]
},
"source": {
"enum": [
"GND",
"RERO",
"IDREF"
]
"type": "string",
"minLength": 2
},
"value": {
"type": "string",
Expand Down
13 changes: 6 additions & 7 deletions rero_mef/jsonschemas/common/concept-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@
"type": {
"enum": [
"bf:Local",
"uri"
"uri",
"bf:Nbn"
]
},
"source": {
"enum": [
"BNF",
"RERO",
"IDREF"
]
"type": "string",
"minLength": 2
},
"value": {
"type": "string",
Expand Down Expand Up @@ -232,7 +230,8 @@
"type": {
"enum": [
"bf:Local",
"uri"
"uri",
"bf:Nbn"
]
},
"source": {
Expand Down
13 changes: 6 additions & 7 deletions rero_mef/jsonschemas/common/place-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@
"type": {
"enum": [
"bf:Local",
"uri"
"uri",
"bf:Nbn"
]
},
"source": {
"enum": [
"BNF",
"RERO",
"IDREF"
]
"type": "string",
"minLength": 2
},
"value": {
"type": "string",
Expand Down Expand Up @@ -231,7 +229,8 @@
"type": {
"enum": [
"bf:Local",
"uri"
"uri",
"bf:Nbn"
]
},
"source": {
Expand Down
21 changes: 20 additions & 1 deletion rero_mef/marctojson/do_idref_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,30 @@ def trans_idref_relation_pid(self):
if self.logger and self.verbose:
self.logger.info("Call Function", "trans_idref_relation_pid")
for field_035 in self.marc.get_fields("035"):
if field_035.get("a") and field_035.get("9") and field_035["9"] == "sudoc":
subfield_a = field_035.get("a")
if isinstance(subfield_a, list):
subfield_a = subfield_a[0]
subfield_2 = field_035.get("2")
if isinstance(subfield_2, list):
subfield_2 = subfield_2[0]
subfield_9 = field_035.get("9")
if isinstance(subfield_9, list):
subfield_9 = subfield_9[0]
if subfield_a and subfield_9 == "sudoc":
self.json_dict["relation_pid"] = {
"value": field_035["a"],
"type": "redirect_from",
}
elif subfield_2:
identified_by = self.json_dict.get("identifiedBy", [])
identified_by.append(
{
"source": subfield_2.upper(),
"type": "uri" if subfield_a.startswith("http") else "bf:Nbn",
"value": subfield_a,
}
)
self.json_dict["identifiedBy"] = identified_by

def trans_idref_gender(self):
"""Transformation gender 120 $a a:female, b: male, -:not known."""
Expand Down
24 changes: 21 additions & 3 deletions rero_mef/marctojson/do_idref_concepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,31 @@ def trans_idref_relation_pid(self):
"""Transformation old pids 035 $a $9 = sudoc."""
if self.logger and self.verbose:
self.logger.info("Call Function", "trans_idref_relation_pid")
fields_035 = self.marc.get_fields("035")
for field_035 in fields_035:
if field_035.get("a") and field_035.get("9") and field_035["9"] == "sudoc":
for field_035 in self.marc.get_fields("035"):
subfield_a = field_035.get("a")
if isinstance(subfield_a, list):
subfield_a = subfield_a[0]
subfield_2 = field_035.get("2")
if isinstance(subfield_2, list):
subfield_2 = subfield_2[0]
subfield_9 = field_035.get("9")
if isinstance(subfield_9, list):
subfield_9 = subfield_9[0]
if subfield_a and subfield_9 == "sudoc":
self.json_dict["relation_pid"] = {
"value": field_035["a"],
"type": "redirect_from",
}
elif subfield_2:
identified_by = self.json_dict.get("identifiedBy", [])
identified_by.append(
{
"source": subfield_2.upper(),
"type": "uri" if subfield_a.startswith("http") else "bf:Nbn",
"value": subfield_a,
}
)
self.json_dict["identifiedBy"] = identified_by

def trans_idref_deleted(self):
"""Transformation deleted leader 5 == d."""
Expand Down
24 changes: 21 additions & 3 deletions rero_mef/marctojson/do_idref_places.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,31 @@ def trans_idref_relation_pid(self):
"""Transformation old pids 035 $a $9 = sudoc."""
if self.logger and self.verbose:
self.logger.info("Call Function", "trans_idref_relation_pid")
fields_035 = self.marc.get_fields("035")
for field_035 in fields_035:
if field_035.get("a") and field_035.get("9") and field_035["9"] == "sudoc":
for field_035 in self.marc.get_fields("035"):
subfield_a = field_035.get("a")
if isinstance(subfield_a, list):
subfield_a = subfield_a[0]
subfield_2 = field_035.get("2")
if isinstance(subfield_2, list):
subfield_2 = subfield_2[0]
subfield_9 = field_035.get("9")
if isinstance(subfield_9, list):
subfield_9 = subfield_9[0]
if subfield_a and subfield_9 == "sudoc":
self.json_dict["relation_pid"] = {
"value": field_035["a"],
"type": "redirect_from",
}
elif subfield_2:
identified_by = self.json_dict.get("identifiedBy", [])
identified_by.append(
{
"source": subfield_2.upper(),
"type": "uri" if subfield_a.startswith("http") else "bf:Nbn",
"value": subfield_a,
}
)
self.json_dict["identifiedBy"] = identified_by

def trans_idref_deleted(self):
"""Transformation deleted leader 5 == d."""
Expand Down
2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ msg=$(safety check -o text ${safety_exceptions}) || {
exit 1
}
info_msg "Test black:"
black tests rero_mef --diff
black tests rero_mef tests --check
info_msg "Test pydocstyle:"
pydocstyle rero_mef tests docs
info_msg "Test isort:"
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/agents/examples/xml_minimal_record.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

<record>
<leader>00589nx a2200193 45 </leader>
<datafield ind1=" " ind2=" " tag="710">
<subfield code="a">Paul</subfield>
<subfield code="b">VI</subfield>
<subfield code="c">pape</subfield>
<subfield code="d">1897-1978</subfield>
<datafield tag="102" ind1=" " ind2=" ">
<subfield code="a">DE</subfield>
</datafield>
</record>
</record>
14 changes: 13 additions & 1 deletion tests/unit/agents/test_agent_idref_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,23 @@ def test_idref_relation_pid():
<subfield code="C">VIAF</subfield>
<subfield code="d">20200302</subfield>
</datafield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">A003915957</subfield>
<subfield code="2">RERO</subfield>
</datafield>
"""
trans = trans_prep("idref", xml_part_to_add)
trans.trans_idref_relation_pid()
assert trans.json == {
"relation_pid": {"value": "027630501", "type": "redirect_from"}
"identifiedBy": [
{
"source": "VIAF",
"type": "uri",
"value": "http://viaf.org/viaf/124265140",
},
{"source": "RERO", "type": "bf:Nbn", "value": "A003915957"},
],
"relation_pid": {"value": "027630501", "type": "redirect_from"},
}


Expand Down
61 changes: 15 additions & 46 deletions tests/unit/concepts/examples/xml_minimal_record.xml
Original file line number Diff line number Diff line change
@@ -1,55 +1,24 @@

<record>
<leader>00589nx a2200193 45 </leader>
<datafield tag="670" ind1=" " ind2=" ">
<subfield code="a">
Grand Larousse universel (art. : Livre)
</subfield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">027630501</subfield>
<subfield code="9">sudoc</subfield>
</datafield>
<datafield tag="675" ind1=" " ind2=" ">
<subfield code="a">
Laval RVM (en ligne), 2004-11-23
</subfield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">frBN001940328</subfield>
</datafield>
<datafield tag="680" ind1=" " ind2=" ">
<subfield code="a">
Mers profondément engagées dans la masse des continents
</subfield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">frBN000000089</subfield>
</datafield>
<datafield tag="667" ind1=" " ind2=" ">
<subfield code="a">Note interne</subfield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">FRBNF118620892</subfield>
<subfield code="z">FRBNF11862089</subfield>
</datafield>
<datafield tag="260" ind1=" " ind2="9">
<subfield code="a">
Voir le descripteur Opposition (science politique)
</subfield>
</datafield>
<datafield tag="260" ind1=" " ind2="9">
<subfield code="a">
Combiner un des descripteurs Mouvements contestataires
</subfield>
</datafield>
<datafield tag="260" ind1=" " ind2=" ">
<subfield code="a">
Voir les vedettes : Mouvements contestataires ; Opposition
</subfield>
</datafield>
<datafield tag="260" ind1=" " ind2=" ">
<subfield code="a">
Voir les vedettes du type : Antifascisme ; Mouvements
</subfield>
</datafield>
<datafield tag="260" ind1=" " ind2=" ">
<subfield code="a">
Voir aux mouvements d'opposition particuliers, par ex. : Combat
</subfield>
</datafield>
<datafield tag="360" ind1=" " ind2=" ">
<subfield code="a">
Voir aussi aux mers et océans particuliers
</subfield>
</datafield>
<datafield tag="016" ind1=" " ind2=" ">
<subfield code="9">VF3, NC3, NC30</subfield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">http://viaf.org/viaf/124265140</subfield>
<subfield code="2">VIAF</subfield>
<subfield code="C">VIAF</subfield>
<subfield code="d">20200302</subfield>
</datafield>
</record>
5 changes: 4 additions & 1 deletion tests/unit/concepts/test_concept_idref_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,8 @@ def test_idref_relation_pid():
trans = trans_prep(Transformation, "concepts", xml_part_to_add)
trans.trans_idref_relation_pid()
assert trans.json == {
"relation_pid": {"value": "027630501", "type": "redirect_from"}
"identifiedBy": [
{"source": "VIAF", "type": "uri", "value": "http://viaf.org/viaf/124265140"}
],
"relation_pid": {"value": "027630501", "type": "redirect_from"},
}
5 changes: 4 additions & 1 deletion tests/unit/places/test_places_idref_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,8 @@ def test_idref_relation_pid():
trans = trans_prep(Transformation, "places", xml_part_to_add)
trans.trans_idref_relation_pid()
assert trans.json == {
"relation_pid": {"value": "027630501", "type": "redirect_from"}
"identifiedBy": [
{"source": "VIAF", "type": "uri", "value": "http://viaf.org/viaf/124265140"}
],
"relation_pid": {"value": "027630501", "type": "redirect_from"},
}

0 comments on commit e8d7b50

Please sign in to comment.