Skip to content

Commit

Permalink
Adds/updates SPARQL for ISBN, ISSN, and LCCN identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
jermnelson committed May 2, 2024
1 parent 95470eb commit 188095e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
5 changes: 3 additions & 2 deletions ils_middleware/tasks/folio/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,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",
Expand Down
47 changes: 33 additions & 14 deletions ils_middleware/tasks/folio/mappings/bf_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,46 @@
BF Instance with its associated BF Work.
"""

identifier = """PREFIX bf: <http://id.loc.gov/ontologies/bibframe/>
instance_format_id = """PREFIX bf: <http://id.loc.gov/ontologies/bibframe/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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: <http://id.loc.gov/ontologies/bibframe/>
isbn_identifier = """PREFIX bf: <http://id.loc.gov/ontologies/bibframe/>
PREFIX sinopia: <http://sinopia.io/vocabulary/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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: <http://id.loc.gov/ontologies/bibframe/>
PREFIX sinopia: <http://sinopia.io/vocabulary/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?lccn
WHERE {{
<{bf_instance}> a bf:Instance ;
bf:identifiedBy ?id .
?id a bf:Lccn ;
rdf:value ?lccn .
}}
"""

Expand Down Expand Up @@ -115,7 +131,7 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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 .
Expand All @@ -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 .
}}
}}
"""
18 changes: 16 additions & 2 deletions ils_middleware/tasks/folio/mappings/bf_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down Expand Up @@ -41,6 +41,20 @@
}}
"""

issn_identifier = """PREFIX bf: <http://id.loc.gov/ontologies/bibframe/>
PREFIX sinopia: <http://sinopia.io/vocabulary/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?issn
WHERE {{
<{bf_work}> a bf:Work ;
bf:identifiedBy ?id .
?id a bf:Issn ;
rdf:value ?issn .
}}
"""

language = """PREFIX bf: <http://id.loc.gov/ontologies/bibframe/>
SELECT ?language_uri ?language
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/bf.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ bf:Work rdfs:label "http://id.loc.gov/ontologies/bibframe/Work" .
bf:qualifier "(print)"@eng ;
bf:status <http://id.loc.gov/vocabulary/mstatus/incorrect> ;
rdf:value "9788869694103"@eng ],
[ a bf:Lccn ;
rdf:value "2022036707"@eng ],
[ a bf:Local ;
bf:source [ a bf:Source ;
rdfs:label "OCLC"@eng ] ;
Expand Down Expand Up @@ -115,6 +117,10 @@ bf:Work rdfs:label "http://id.loc.gov/ontologies/bibframe/Work" .
[ a bf:Contribution ;
bf:agent <http://id.loc.gov/authorities/names/n97060063> ;
bf:role <http://id.loc.gov/vocabulary/relators/aut> ] ;
bf:identifiedBy [
a bf:Issn ;
rdf:value "1940-5758"
];
bf:editionStatement "1st edition"@eng ;
bf:genreForm <http://id.loc.gov/authorities/genreForms/gf2014026113> ;
bf:hasInstance <https://api.stage.sinopia.io/resource/b0319047-acd0-4f30-bd8b-98e6c1bac6b0> ;
Expand Down
11 changes: 10 additions & 1 deletion tests/tasks/folio/mappings/test_bf_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions tests/tasks/folio/mappings/test_bf_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 188095e

Please sign in to comment.