From f84a10b1eb48f6a3c6eda67bc39722fa19a566de Mon Sep 17 00:00:00 2001 From: Jeremy Nelson Date: Mon, 26 Feb 2024 16:16:25 -0800 Subject: [PATCH] Adds/updates SPARQL for ISBN, ISSN, and LCCN identifiers --- ils_middleware/tasks/folio/map.py | 5 +- .../tasks/folio/mappings/bf_instance.py | 47 +++++++++++++------ .../tasks/folio/mappings/bf_work.py | 18 ++++++- tests/fixtures/bf.ttl | 6 +++ .../tasks/folio/mappings/test_bf_instance.py | 11 ++++- tests/tasks/folio/mappings/test_bf_work.py | 9 ++++ 6 files changed, 77 insertions(+), 19 deletions(-) diff --git a/ils_middleware/tasks/folio/map.py b/ils_middleware/tasks/folio/map.py index a0909c9..2acc090 100644 --- a/ils_middleware/tasks/folio/map.py +++ b/ils_middleware/tasks/folio/map.py @@ -21,10 +21,11 @@ "uri": "instance", }, "identifiers.isbn": { - "template": bf_instance_map.identifier, + "template": bf_instance_map.isbn_identifier, "uri": "instance", - "class": "bf:Isbn", }, + "identifiers.issn": {"template": bf_work_map.issn_identifier, "uri": "work"}, + "identifies.lccn": {"template": bf_instance_map.lccn_identifier, "uri": "instance"}, "identifiers.oclc": { "template": bf_instance_map.local_identifier, "uri": "instance", diff --git a/ils_middleware/tasks/folio/mappings/bf_instance.py b/ils_middleware/tasks/folio/mappings/bf_instance.py index dac0e36..d1bbe82 100644 --- a/ils_middleware/tasks/folio/mappings/bf_instance.py +++ b/ils_middleware/tasks/folio/mappings/bf_instance.py @@ -2,30 +2,46 @@ BF Instance with its associated BF Work. """ -identifier = """PREFIX bf: +instance_format_id = """PREFIX bf: PREFIX rdf: PREFIX rdfs: -SELECT ?identifier +SELECT ?format_category ?format_term WHERE {{ <{bf_instance}> a bf:Instance . - <{bf_instance}> bf:identifiedBy ?ident_bnode . - ?ident_bnode a {bf_class} . - ?ident_bnode rdf:value ?identifier . + <{bf_instance}> bf:media ?format_category_uri . + <{bf_instance}> bf:carrier ?format_term_uri . + ?format_category_uri rdfs:label ?format_category . + ?format_term_uri rdfs:label ?format_term . }} """ -instance_format_id = """PREFIX bf: +isbn_identifier = """PREFIX bf: +PREFIX sinopia: PREFIX rdf: PREFIX rdfs: -SELECT ?format_category ?format_term + +SELECT ?isbn WHERE {{ - <{bf_instance}> a bf:Instance . - <{bf_instance}> bf:media ?format_category_uri . - <{bf_instance}> bf:carrier ?format_term_uri . - ?format_category_uri rdfs:label ?format_category . - ?format_term_uri rdfs:label ?format_term . + <{bf_instance}> a bf:Instance ; + bf:identifiedBy ?id . + ?id a bf:Isbn ; + rdf:value ?isbn . +}} +""" + +lccn_identifier = """PREFIX bf: +PREFIX sinopia: +PREFIX rdf: +PREFIX rdfs: + +SELECT ?lccn +WHERE {{ + <{bf_instance}> a bf:Instance ; + bf:identifiedBy ?id . + ?id a bf:Lccn ; + rdf:value ?lccn . }} """ @@ -115,7 +131,7 @@ PREFIX rdf: PREFIX rdfs: -SELECT ?main_title ?subtitle ?part_number ?part_name +SELECT ?main_title ?subtitle ?part_number ?part_name ?responsibility WHERE {{ <{bf_instance}> a bf:Instance . <{bf_instance}> bf:title ?title . @@ -128,7 +144,10 @@ ?title bf:partNumber ?part_number . }} OPTIONAL {{ - ?title bf:partName ?part_name + ?title bf:partName ?part_name . + }} + OPTIONAL {{ + ?title bf:responsibilityStatement ?responsibility . }} }} """ diff --git a/ils_middleware/tasks/folio/mappings/bf_work.py b/ils_middleware/tasks/folio/mappings/bf_work.py index 416a8f1..8270ff1 100644 --- a/ils_middleware/tasks/folio/mappings/bf_work.py +++ b/ils_middleware/tasks/folio/mappings/bf_work.py @@ -9,8 +9,8 @@ SELECT ?agent ?role WHERE {{ - <{bf_work}> a bf:Work . - <{bf_work}> bf:contribution ?contrib_bnode . + <{bf_work}> a bf:Work ; + bf:contribution ?contrib_bnode . ?contrib_bnode a bf:Contribution . ?contrib_bnode bf:role ?role_uri . ?role_uri rdfs:label ?role . @@ -41,6 +41,20 @@ }} """ +issn_identifier = """PREFIX bf: +PREFIX sinopia: +PREFIX rdf: +PREFIX rdfs: + +SELECT ?issn +WHERE {{ + <{bf_work}> a bf:Work ; + bf:identifiedBy ?id . + ?id a bf:Issn ; + rdf:value ?issn . + }} + """ + language = """PREFIX bf: SELECT ?language_uri ?language diff --git a/tests/fixtures/bf.ttl b/tests/fixtures/bf.ttl index a5dbd15..aee1dfb 100644 --- a/tests/fixtures/bf.ttl +++ b/tests/fixtures/bf.ttl @@ -70,6 +70,8 @@ bf:Work rdfs:label "http://id.loc.gov/ontologies/bibframe/Work" . bf:qualifier "(print)"@eng ; bf:status ; rdf:value "9788869694103"@eng ], + [ a bf:Lccn ; + rdf:value "2022036707"@eng ], [ a bf:Local ; bf:source [ a bf:Source ; rdfs:label "OCLC"@eng ] ; @@ -115,6 +117,10 @@ bf:Work rdfs:label "http://id.loc.gov/ontologies/bibframe/Work" . [ a bf:Contribution ; bf:agent ; bf:role ] ; + bf:identifiedBy [ + a bf:Issn ; + rdf:value "1940-5758" + ]; bf:editionStatement "1st edition"@eng ; bf:genreForm ; bf:hasInstance ; diff --git a/tests/tasks/folio/mappings/test_bf_instance.py b/tests/tasks/folio/mappings/test_bf_instance.py index ad973ad..63c494e 100644 --- a/tests/tasks/folio/mappings/test_bf_instance.py +++ b/tests/tasks/folio/mappings/test_bf_instance.py @@ -10,7 +10,7 @@ @typing.no_type_check def test_isbn(test_graph: rdflib.Graph): - sparql = bf_instance_map.identifier.format(bf_instance=uri, bf_class="bf:Isbn") + sparql = bf_instance_map.isbn_identifier.format(bf_instance=uri) isbns = [row[0] for row in test_graph.query(sparql)] @@ -27,6 +27,15 @@ def test_instance_format_id(test_graph: rdflib.Graph): assert str(instance_formats[0][1]).startswith("online resource") +@typing.no_type_check +def test_lccn(test_graph: rdflib.Graph): + sparql = bf_instance_map.lccn_identifier.format(bf_instance=uri) + + lccn = [row[0] for row in test_graph.query(sparql)] + + assert str(lccn[0]).startswith("2022036707") + + @typing.no_type_check def test_local_identifier(test_graph: rdflib.Graph): sparql = bf_instance_map.local_identifier.format(bf_instance=uri) diff --git a/tests/tasks/folio/mappings/test_bf_work.py b/tests/tasks/folio/mappings/test_bf_work.py index d8d6f39..43aa969 100644 --- a/tests/tasks/folio/mappings/test_bf_work.py +++ b/tests/tasks/folio/mappings/test_bf_work.py @@ -36,6 +36,15 @@ def test_instance_type_id(test_graph: rdflib.Graph): assert str(type_idents[0]).startswith("Text") +@typing.no_type_check +def test_issn(test_graph: rdflib.Graph): + sparql = bf_work_map.issn_identifier.format(bf_work=work_uri) + + issn = [row[0] for row in test_graph.query(sparql)] + + assert str(issn[0]).startswith("1940-5758") + + @typing.no_type_check def test_language(test_graph: rdflib.Graph): sparql = bf_work_map.language.format(bf_work=work_uri)