Skip to content

Commit

Permalink
Testing SPARQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jermnelson committed Nov 15, 2021
1 parent e142066 commit ca2c791
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 0 deletions.
143 changes: 143 additions & 0 deletions tests/tasks/folio/mappings/bf.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
@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#> .
@prefix sinopia: <http://sinopia.io/vocabulary/> .

<http://id.loc.gov/authorities/genreForms/gf2014026113> rdfs:label "Informational works@en"@eng .

<http://id.loc.gov/authorities/names/n2012041708> a bf:Person ;
rdfs:label "Brioni, Simone"@eng .

<http://id.loc.gov/authorities/names/n79018142> rdfs:label "Venice (Italy)"@eng .

<http://id.loc.gov/authorities/names/n79021783> rdfs:label "Italy@en"@eng .

<http://id.loc.gov/authorities/names/n97060063> a bf:Person ;
rdfs:label "Ramzanali Fazel, Shirin"@eng .

<http://id.loc.gov/authorities/names/nb2002005989> a bf:Person ;
rdfs:label "Blow, C. Joe"@eng .

<http://id.loc.gov/authorities/subjects/sh2005004457> rdfs:label "Islamophobia@en"@eng .

<http://id.loc.gov/authorities/subjects/sh85103571> rdfs:label "Cultural pluralism@en"@eng .

<http://id.loc.gov/authorities/subjects/sh85120595> rdfs:label "Sex discrimination against women@en"@eng .

bf:Electronic rdfs:label "Electronic"@eng .

bf:Text rdfs:label "Text"@eng .

bf:Work rdfs:label "http://id.loc.gov/ontologies/bibframe/Work" .

<http://id.loc.gov/vocabulary/carriers/cr> rdfs:label "online resource"@eng .

<http://id.loc.gov/vocabulary/contentTypes/txt> rdfs:label "Text"@eng .

<http://id.loc.gov/vocabulary/issuance/mono> rdfs:label "single unit"@eng .

<http://id.loc.gov/vocabulary/languages/ita> rdfs:label "Italian" .

<http://id.loc.gov/vocabulary/mediaTypes/c> rdfs:label "computer"@eng .

<http://id.loc.gov/vocabulary/mstatus/incorrect> rdfs:label "incorrect" .

<https://api.stage.sinopia.io/resource/238101af-86ce-473f-abcb-9ff038622c21> rdfs:label "Stanford University"@eng .

<https://api.stage.sinopia.io/resource/48e954be-4b9b-4589-b2a2-776551807d50> rdfs:label "Resource Description and Access"@eng .

<https://api.stage.sinopia.io/resource/992c99e5-adde-4d63-afcd-3391128136fe> rdfs:label "Resource Description and Access"@eng .

<https://api.stage.sinopia.io/resource/b0319047-acd0-4f30-bd8b-98e6c1bac6b0> a bf:Instance ;
rdfs:label "OCLC"@eng ;
bflc:relationship [ a bflc:Relationship ;
bf:hasEquivalent "Also issued in print"@eng ] ;
bf:adminMetadata <https://api.stage.sinopia.io/resource/992c99e5-adde-4d63-afcd-3391128136fe> ;
bf:carrier <http://id.loc.gov/vocabulary/carriers/cr> ;
bf:copyrightDate "©2020" ;
bf:dimensions "30 cm by 15 cm"@eng ;
bf:editionStatement "1a edizione"@ita ;
bf:electronicLocator <https://phaidra.cab.unipd.it/detail/o:445140?mycoll=o:432583>,
<https://purl.stanford.edu/mf283yt5578> ;
bf:extent [ a bf:Extent ;
rdfs:label "1 online resource (128 pages)"@eng ] ;
bf:hasItem <https://api.stage.sinopia.io/resource/238101af-86ce-473f-abcb-9ff038622c21> ;
bf:identifiedBy [ a bf:Isbn ;
bf:qualifier "(ebook)"@eng ;
rdf:value "9788869694110" ],
[ a bf:Isbn ;
bf:qualifier "(print)"@eng ;
bf:status <http://id.loc.gov/vocabulary/mstatus/incorrect> ;
rdf:value "9788869694103"@eng ],
[ a bf:Local ;
bf:source [ a bf:Source ;
rdfs:label "OCLC"@eng ] ;
rdf:value "1272909598"@eng ] ;
bf:instanceOf <https://api.stage.sinopia.io/resource/c96d8b55-e0ac-48a5-9a9b-b0684758c99e> ;
bf:issuance <http://id.loc.gov/vocabulary/issuance/mono> ;
bf:media <http://id.loc.gov/vocabulary/mediaTypes/c> ;
bf:note [ a bf:Note ;
rdfs:label "Includes bibliographical references (page 117-128)"@eng ],
[ a bf:Note ;
rdfs:label "Description based on online resource (Stanford Digital Repository, viewed October 1, 2021)"@eng ] ;
bf:provisionActivity [ a bf:Publication ;
bf:agent [ a bf:Agent ;
rdfs:label "Edizioni Ca'Foscari"@eng ] ;
bf:date "2020"@eng ;
bf:place <http://id.loc.gov/authorities/names/n79018142> ] ;
bf:provisionActivityStatement "Venezia : Edizioni Ca'Foscari, 2020"@ita ;
bf:responsibilityStatement "Simone Brioni e Shirin Ramzanali Fazel"@ita ;
bf:seriesStatement "Diaspore, 2610-9387 ; 13"@ita ;
bf:title [ a bf:Title ;
bf:mainTitle "Scrivere di Islam"@ita ;
bf:note [ a bf:Note ;
rdfs:label " Title from PDF title page "@eng ] ;
bf:subtitle "raccontere la diaspora"@ita ],
[ a bf:ParallelTitle ;
bf:mainTitle "Writing about Islam"@eng ;
bf:subtitle "narrating a diaspora"@eng ] ;
sinopia:hasResourceTemplate "pcc:bf2:Monograph:Instance" ;

rdf:type bf:Electronic .

<https://api.stage.sinopia.io/resource/c96d8b55-e0ac-48a5-9a9b-b0684758c99e> a bf:Text,
bf:Work ;
rdfs:label "\"Scrivere di Islam. Raccontare la diaspora (Writing About Islam. Narrating a Diaspora) is a meditation on our multireligious, multicultural, and multilingual reality. It is the result of a personal and collaborative exploration of the necessity to rethink national culture and identity in a more diverse, inclusive, and anti-racist way. The central part of this volume - both symbolically and physically - includes Shirin Ramzanali Fazel's reflections on the discrimination of Muslims, and especially Muslim women, in Italy and the UK. Looking at school textbooks, newspapers, TV programs, and sharing her own personal experience, this section invites us to change the way Muslim immigrants are narrated in scholarly research and news reports. Most importantly, this section urges us to consider minorities not just as 'topics' of cultural analysis, but as audiences and cultural agents. Following Shirin's invitation to question prevailing modes of representations of immigrants, the volume continues with a dialogue between the co-authors and discusses how collaboration can be a way to avoid reproducing a 'colonial model' of knowledge production, in which the white male scholar takes as object of analysis the work of an African female writer. The last chapter also asserts that immigration literature cannot be approached with the same expectations and questions readers would have when reading 'canonised' texts. A new critical terminology is needed in order to understand the innovative linguistic choices and narrative forms that immigrant writers have invented in order to describe a reality that has lacked representation or which has frequently been misrepresented, especially in the discourse around the contemporary Muslim diaspora\"--Abstract"@eng ;
bf:adminMetadata <https://api.stage.sinopia.io/resource/48e954be-4b9b-4589-b2a2-776551807d50> ;
bf:classification [ a bf:ClassificationLcc ;
bf:classificationPortion "BP52.5"@eng ] ;
bf:content <http://id.loc.gov/vocabulary/contentTypes/txt> ;
bf:contribution [ a bflc:PrimaryContribution ;
bf:agent <http://id.loc.gov/authorities/names/n2012041708>,
<http://id.loc.gov/authorities/names/nb2002005989> ;
bf:role <http://id.loc.gov/vocabulary/relators/aut> ],
[ a bf:Contribution ;
bf:agent <http://id.loc.gov/authorities/names/n97060063> ;
bf:role <http://id.loc.gov/vocabulary/relators/aut> ] ;
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> ;
bf:language <http://id.loc.gov/vocabulary/languages/ita> ;
bf:notation [ a bf:Script ;
rdfs:label "Latin"@eng ] ;
bf:originDate "2020"@eng ;
bf:originPlace <http://id.loc.gov/authorities/names/n79021783> ;
bf:subject <http://id.loc.gov/authorities/subjects/sh2005004457>,
<http://id.loc.gov/authorities/subjects/sh85103571>,
<http://id.loc.gov/authorities/subjects/sh85120595>,
"Immigrants' writings--History and criticism"@eng ;
bf:summary [ a bf:Summary ;
rdfs:label "\"Scrivere di Islam. Raccontare la diaspora (Writing About Islam. Narrating a Diaspora) is a meditation on our multireligious, multicultural, and multilingual reality. It is the result of a personal and collaborative exploration of the necessity to rethink national culture and identity in a more diverse, inclusive, and anti-racist way. The central part of this volume - both symbolically and physically - includes Shirin Ramzanali Fazel's reflections on the discrimination of Muslims, and especially Muslim women, in Italy and the UK. Looking at school textbooks, newspapers, TV programs, and sharing her own personal experience, this section invites us to change the way Muslim immigrants are narrated in scholarly research and news reports. Most importantly, this section urges us to consider minorities not just as 'topics' of cultural analysis, but as audiences and cultural agents. Following Shirin's invitation to question prevailing modes of representations of immigrants, the volume continues with a dialogue between the co-authors and discusses how collaboration can be a way to avoid reproducing a 'colonial model' of knowledge production, in which the white male scholar takes as object of analysis the work of an African female writer. The last chapter also asserts that immigration literature cannot be approached with the same expectations and questions readers would have when reading 'canonised' texts. A new critical terminology is needed in order to understand the innovative linguistic choices and narrative forms that immigrant writers have invented in order to describe a reality that has lacked representation or which has frequently been misrepresented, especially in the discourse around the contemporary Muslim diaspora\"--Abstract"@eng ] ;
bf:supplementaryContent [ a bf:SupplementaryContent ;
rdfs:label "Includes bibliographical references"@eng ] ;
bf:title [ a bf:Title ;
bf:mainTitle "Scrivere di Islam "@ita ] ;
sinopia:hasResourceTemplate "pcc:bf2:Monograph:Work" .

<https://phaidra.cab.unipd.it/detail/o:445140?mycoll=o:432583> rdfs:label "https://phaidra.cab.unipd.it/detail/o:445140?mycoll=o:432583"@eng .

<https://purl.stanford.edu/mf283yt5578> rdfs:label "Stanford Digital Repository"@eng .

<http://id.loc.gov/vocabulary/relators/aut> rdfs:label "Author" .

16 changes: 16 additions & 0 deletions tests/tasks/folio/mappings/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pathlib

import pytest
import rdflib

rdf_file = pathlib.Path(__file__).parent / "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
93 changes: 93 additions & 0 deletions tests/tasks/folio/mappings/test_bf_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

import pytest
import rdflib

import ils_middleware.tasks.folio.mappings.bf_instance as bf_instance_map

uri = 'https://api.stage.sinopia.io/resource/b0319047-acd0-4f30-bd8b-98e6c1bac6b0'

def test_date_of_publication(test_graph: rdflib.Graph):
sparql = bf_instance_map.date_of_publication.format(bf_instance=uri)
dates = [row[0] for row in test_graph.query(sparql)]

assert str(dates[0]).startswith("2020")

def test_isbn(test_graph: rdflib.Graph):
sparql = bf_instance_map.identifier.format(bf_instance=uri,
bf_identifier_class="bf:Isbn")

isbns = [row[0] for row in test_graph.query(sparql)]

assert str(isbns[0]).startswith("9788869694110")
assert str(isbns[1]).startswith("9788869694103")

def test_media_format(test_graph: rdflib.Graph):
sparql = bf_instance_map.instance_format_category.format(bf_instance=uri)
media_formats = [row[0] for row in test_graph.query(sparql)]

assert str(media_formats[0]).startswith("http://id.loc.gov/vocabulary/mediaTypes/c")

def test_carrier_term(test_graph: rdflib.Graph):
sparql = bf_instance_map.instance_format_term.format(bf_instance=uri)
terms = [row[0] for row in test_graph.query(sparql)]

assert str(terms[0]).startswith("http://id.loc.gov/vocabulary/carriers/cr")

def test_local_idenitifier(test_graph: rdflib.Graph):
sparql = bf_instance_map.local_identifier.format(bf_instance=uri)
local_idents = [row[0] for row in test_graph.query(sparql)]

assert str(local_idents[0]).startswith("1272909598")

def test_mode_of_issuance(test_graph: rdflib.Graph):
sparql = bf_instance_map.mode_of_issuance.format(bf_instance=uri)
modes = [row[0] for row in test_graph.query(sparql)]

assert str(modes[0]).startswith("http://id.loc.gov/vocabulary/issuance/mono")

def test_note(test_graph: rdflib.Graph):
sparql = bf_instance_map.note.format(bf_instance=uri)
notes = [row[0] for row in test_graph.query(sparql)]

assert len(str(notes[0])) == 50
assert len(str(notes[1])) == 90

def test_physical_description_dimensions(test_graph: rdflib.Graph):
sparql = bf_instance_map.physical_description_dimensions.format(bf_instance=uri)
dimensions = [row[0] for row in test_graph.query(sparql)]

assert str(dimensions[0]).startswith("30 cm by 15 cm")

def test_physical_description_extent(test_graph: rdflib.Graph):
sparql = bf_instance_map.physical_description_extent.format(bf_instance=uri)
extents = [row[0] for row in test_graph.query(sparql)]

assert str(extents[0]).startswith("1 online resource (128 pages)")

def test_place(test_graph: rdflib.Graph):
sparql = bf_instance_map.place.format(bf_instance=uri)
places = [row[0] for row in test_graph.query(sparql)]

assert str(places[0]).startswith("Venice (Italy)")

def test_publisher(test_graph: rdflib.Graph):
sparql = bf_instance_map.publisher.format(bf_instance=uri)
publishers = [row[0] for row in test_graph.query(sparql)]

assert str(publishers[0]).startswith("Edizioni Ca'Foscari")

def test_main_title(test_graph: rdflib.Graph):
sparql = bf_instance_map.title.format(bf_instance=uri,
bf_title_class="bf:Title")
titles = [row for row in test_graph.query(sparql)]

assert str(titles[0][0]).startswith("Scrivere di Islam")
assert str(titles[0][1]).startswith("raccontere la diaspora")

def test_parallel_title(test_graph: rdflib.Graph):
sparql = bf_instance_map.title.format(bf_instance=uri,
bf_title_class="bf:ParallelTitle")
titles = [row for row in test_graph.query(sparql)]

assert str(titles[0][0]).startswith("Writing about Islam")
assert str(titles[0][1]).startswith("narrating a diaspora")
57 changes: 57 additions & 0 deletions tests/tasks/folio/mappings/test_bf_work.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pytest
import rdflib

import ils_middleware.tasks.folio.mappings.bf_work as bf_work_map


work_uri = "https://api.stage.sinopia.io/resource/c96d8b55-e0ac-48a5-9a9b-b0684758c99e"

def test_contributor_author_person(test_graph: rdflib.Graph):
sparql = bf_work_map.contributor.format(bf_work=work_uri,
bf_class="bf:Person")

contributors = [row for row in test_graph.query(sparql)]

assert str(contributors[0][0]).startswith("Ramzanali Fazel, Shirin")
assert str(contributors[0][1]).startswith("Author")

def test_edition(test_graph: rdflib.Graph):
sparql = bf_work_map.editions.format(bf_work=work_uri)

editions = [row[0] for row in test_graph.query(sparql)]

assert str(editions[0]).startswith("1st edition")


def test_instance_type_id(test_graph: rdflib.Graph):
sparql = bf_work_map.instance_type_id.format(bf_work=work_uri)

type_idents = [row[0] for row in test_graph.query(sparql)]

assert str(type_idents[0]).startswith("Text")

def test_language(test_graph: rdflib.Graph):
sparql = bf_work_map.language.format(bf_work=work_uri)

languages = [row[0] for row in test_graph.query(sparql)]

assert str(languages[0]).startswith("Italian")

def test_primary_contributor(test_graph: rdflib.Graph):
sparql = bf_work_map.primary_contributor.format(bf_work=work_uri, bf_class="bf:Person")

primary_contributors = [row for row in test_graph.query(sparql)]

assert str(primary_contributors[0][0]).startswith("Brioni, Simone")
assert str(primary_contributors[0][1]).startswith("Author")

assert str(primary_contributors[1][0]).startswith("Blow, C. Joe")
assert str(primary_contributors[1][1]).startswith("Author")

def test_subject(test_graph: rdflib.Graph):
sparql = bf_work_map.subject.format(bf_work=work_uri)

subjects = [row for row in test_graph.query(sparql)]

assert len(subjects) == 3

0 comments on commit ca2c791

Please sign in to comment.