Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Sinopia RDF to FOLIO Mapping #105

Merged
merged 3 commits into from
Nov 16, 2021
Merged
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
19 changes: 19 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# placing this in the root allows the tests in the 'tests' directory to import the packages in the root, e.g. 'dags'
import pathlib

import pytest
import rdflib

rdf_file = pathlib.Path(__file__).parent / "tests" / "fixtures" / "bf.ttl"


@pytest.fixture
def test_graph():
graph = rdflib.Graph()
for ns in [
("bf", "http://id.loc.gov/ontologies/bibframe/"),
("bflc", "http://id.loc.gov/ontologies/bflc/"),
("sinopia", "http://sinopia.io/vocabulary/"),
]:
graph.namespace_manager.bind(ns[0], ns[1])
graph.parse(rdf_file, format="turtle")
return graph
167 changes: 167 additions & 0 deletions ils_middleware/tasks/folio/mappings/bf_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
date_of_publication = """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 ?date
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:provisionActivity ?activity .
?activity a bf:Publication .
?activity bf:date ?date .
}}
"""

identifier = """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
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:identifiedBy ?ident_bnode .
?ident_bnode a {bf_class} .
?ident_bnode rdf:value ?identifier .
}}
"""

instance_format_category = """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 ?format_category
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:media ?format_category .
}}
"""

instance_format_term = """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 ?format_term
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:carrier ?format_term .
}}
"""

local_identifier = """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
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:identifiedBy ?ident_bnode .
?ident_bnode a bf:Local .
?ident_bnode bf:source ?source_bnode .
?ident_bnode rdf:value ?identifier .
?source_bnode a bf:Source .
OPTIONAL {{
?source_bnode rdfs:label "OColC" .
}}
OPTIONAL {{
?source_bnode rdfs:label "OCLC" .
}}
}}
"""

mode_of_issuance = """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 ?mode_of_issuance
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:issuance ?mode_of_issuance .
}}
"""

note = """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 ?note
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:note ?note_bnode .
?note_bnode a bf:Note .
?note_bnode rdfs:label ?note .
}}
"""

physical_description_dimensions = """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 ?dimensions
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:dimensions ?dimensions .
}}
"""

physical_description_extent = """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 ?extent
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:extent ?extent_bnode .
?extent_bnode a bf:Extent .
?extent_bnode rdfs:label ?extent .
}}
"""

place = """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 ?place
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:provisionActivity ?activity .
?activity a bf:Publication .
?activity bf:place ?place_holder .
?place_holder rdfs:label ?place .
}}
"""

publisher = """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 ?publisher
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:provisionActivity ?activity .
?activity a bf:Publication .
?activity bf:agent ?agent .
?agent a bf:Agent .
?agent rdfs:label ?publisher .
}}
"""

title = """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 ?main_title ?subtitle ?part_number ?part_name
WHERE {{
<{bf_instance}> a bf:Instance .
<{bf_instance}> bf:title ?title .
?title a {bf_class} .
?title bf:mainTitle ?main_title .
OPTIONAL {{
?title bf:subtitle ?subtitle .
}}
OPTIONAL {{
?title bf:partNumber ?part_number .
}}
OPTIONAL {{
?title bf:partName ?part_name
}}
}}
"""
80 changes: 80 additions & 0 deletions ils_middleware/tasks/folio/mappings/bf_work.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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#>

SELECT ?agent ?role
WHERE {{
<{bf_work}> a bf:Work .
<{bf_work}> bf:contribution ?contrib_bnode .
?contrib_bnode a bf:Contribution .
?contrib_bnode bf:role ?role_uri .
?role_uri rdfs:label ?role .
?contrib_bnode bf:agent ?agent_uri .
?agent_uri a {bf_class} .
?agent_uri rdfs:label ?agent .
}}
"""

editions = """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 ?edition
WHERE {{
<{bf_work}> a bf:Work .
<{bf_work}> bf:editionStatement ?edition .
}}
"""

instance_type_id = """PREFIX bf: <http://id.loc.gov/ontologies/bibframe/>

SELECT ?instance_type_id
WHERE {{
<{bf_work}> a bf:Work .
<{bf_work}> bf:content ?instance_type .
?instance_type rdfs:label ?instance_type_id .
}}
"""

language = """PREFIX bf: <http://id.loc.gov/ontologies/bibframe/>

SELECT ?language
WHERE {{
<{bf_work}> a bf:Work .
<{bf_work}> bf:language ?language_uri .
?language_uri rdfs:label ?language .
}}
"""

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#>

SELECT ?agent ?role
WHERE {{
<{bf_work}> a bf:Work .
<{bf_work}> bf:contribution ?contrib_bnode .
?contrib_bnode a bflc:PrimaryContribution .
?contrib_bnode bf:role ?role_uri .
?role_uri rdfs:label ?role .
?contrib_bnode bf:agent ?agent_uri .
?agent_uri a {bf_class} .
?agent_uri rdfs:label ?agent .
}}
"""

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#>

SELECT ?subject
WHERE {{
<{bf_work}> a bf:Work .
<{bf_work}> bf:subject ?subject_node .
OPTIONAL {{
?subject_node rdfs:label ?subject .
}}
}}
"""
Loading