Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ils_middleware/tasks/folio/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
"uri": "work",
"class": "bf:Person",
},
"editions": {"template": bf_work_map.editions, "uri": "work"},
"editions": {"template": bf_instance_map.editions, "uri": "instance"},
"instance_format": {
"template": bf_instance_map.instance_format_id,
"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"},
"identifiers.lccn": {"template": bf_instance_map.lccn_identifier, "uri": "instance"},
"identifiers.oclc": {
"template": bf_instance_map.local_identifier,
"uri": "instance",
Expand All @@ -47,6 +48,8 @@
"uri": "instance",
"class": "bf:Title",
},
"person_contributor": {"template": bf_work_map.person_contributor, "uri": "work"},
"corporate_contributor": {"template": bf_work_map.corporate_contributor, "uri": "work"},
}

FOLIO_FIELDS = BF_TO_FOLIO_MAP.keys()
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 .
}}
}}
"""
53 changes: 50 additions & 3 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 All @@ -52,7 +66,6 @@
"""

primary_contributor = """PREFIX bf: <http://id.loc.gov/ontologies/bibframe/>
PREFIX bflc: <http://id.loc.gov/ontologies/bflc/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

Expand All @@ -69,6 +82,40 @@
}}
"""

person_contributor = """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 ?subject ?person_contribution ?role
WHERE {
<{bf_work}> a bf:Work .
<{bf_work}> bf:contribution ?contribution .
?contribution bf:agent ?pcontribution .
?pcontribution a bf:Person .
?pcontribution rdfs:label ?person_contribution .
?contribution bf:role ?type .
?type rdfs:label ?role
}}
"""

corporate_contributor = """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 ?subject ?corporate_contribution ?role
WHERE {
<{bf_work}> a bf:Work .
<{bf_work}> bf:contribution ?contribution .
?contribution bf:agent ?ccontribution .
?ccontribution a bf:Organization .
?ccontribution rdfs:label ?corporate_contribution .
?contribution bf:role ?type .
?type rdfs:label ?role .
}}
"""

subject = """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#>
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