Skip to content

Commit

Permalink
Replace spaces by hypthens in URI template object
Browse files Browse the repository at this point in the history
Also add ASB classification as sample and unit tests.
  • Loading branch information
nichtich authored and danmichaelo committed Sep 4, 2017
1 parent 5caa2ba commit 56fff5f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ URIs can be also be generated on the fly from an URI template specified with opt

* ``{control_number}`` is the 001 value
* ``{collection}`` is "class", "table" or "scheme"
* ``{object}`` is a member of the classification scheme and part of
a ``{collection}``, such as a specific class or table.
* ``{object}`` is a member of the classification scheme (with spaces replaced by
hyphens) and part of a ``{collection}``, such as a specific class or table.
* ``{edition}`` is taken from ``084 $c`` (with language code stripped)


Expand Down
23 changes: 23 additions & 0 deletions examples/asb-ubk-2.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://uri.gbv.de/terminology/asb/Ubk-2> a skos:Concept ;
skos:altLabel "Astronomie / Atlas"@de,
"Astronomie / Aufgabensammlung / Allgemeines"@de,
"Astronomie / Bibliographie / Allgemeines"@de,
"Astronomie / Formelsammlung / Allgemeines"@de,
"Astronomie / Nachschlagewerk / Allgemeines"@de,
"Astronomie / Tabellensammlung / Allgemeines"@de,
"Weltraum / Atlas"@de ;
skos:broader <http://uri.gbv.de/terminology/asb/Ubk> ;
skos:editorialNote "Spezielle Nachschlagewerke und Bibliographien s. Ubk 5 bis Ubm 3"@de ;
skos:inScheme <http://uri.gbv.de/terminology/asb/> ;
skos:notation "Ubk 2" ;
skos:prefLabel "Nachschlagewerke. Bibliographien"@de ;
skos:scopeNote "Formel- und Tabellensammlungen"@de .

47 changes: 47 additions & 0 deletions examples/asb-ubk-2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">
<marc:record>
<marc:leader>*****nw###22*****n##4500</marc:leader>
<marc:datafield tag="040" ind1=" " ind2=" ">
<marc:subfield code="a">DE-Rt5</marc:subfield>
<marc:subfield code="b">ger</marc:subfield>
</marc:datafield>
<marc:datafield tag="084" ind1="0" ind2=" ">
<marc:subfield code="a">asb</marc:subfield>
<marc:subfield code="e">ger</marc:subfield>
<marc:subfield code="q">DE-Rt5</marc:subfield>
</marc:datafield>
<marc:datafield tag="153" ind1=" " ind2=" ">
<marc:subfield code="a">Ubk 2</marc:subfield>
<marc:subfield code="e">Ubk</marc:subfield>
<marc:subfield code="j">Nachschlagewerke. Bibliographien</marc:subfield>
</marc:datafield>
<marc:datafield tag="680" ind1="0" ind2=" ">
<marc:subfield code="i">Formel- und Tabellensammlungen</marc:subfield>
</marc:datafield>
<marc:datafield tag="683" ind1="0" ind2=" ">
<marc:subfield code="i">Spezielle Nachschlagewerke und Bibliographien s. Ubk 5 bis Ubm 3</marc:subfield>
</marc:datafield>
<marc:datafield tag="750" ind1=" " ind2="4">
<marc:subfield code="a">Astronomie / Atlas</marc:subfield>
</marc:datafield>
<marc:datafield tag="750" ind1=" " ind2="4">
<marc:subfield code="a">Astronomie / Aufgabensammlung / Allgemeines</marc:subfield>
</marc:datafield>
<marc:datafield tag="750" ind1=" " ind2="4">
<marc:subfield code="a">Astronomie / Bibliographie / Allgemeines</marc:subfield>
</marc:datafield>
<marc:datafield tag="750" ind1=" " ind2="4">
<marc:subfield code="a">Astronomie / Formelsammlung / Allgemeines</marc:subfield>
</marc:datafield>
<marc:datafield tag="750" ind1=" " ind2="4">
<marc:subfield code="a">Astronomie / Nachschlagewerk / Allgemeines</marc:subfield>
</marc:datafield>
<marc:datafield tag="750" ind1=" " ind2="4">
<marc:subfield code="a">Astronomie / Tabellensammlung / Allgemeines</marc:subfield>
</marc:datafield>
<marc:datafield tag="750" ind1=" " ind2="4">
<marc:subfield code="a">Weltraum / Atlas</marc:subfield>
</marc:datafield>
</marc:record>
</marc:collection>
4 changes: 4 additions & 0 deletions mc2skos/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def get_uri(self, uri_type='concept', **kwargs):
# Remove organization prefix in parenthesis:
kwargs['control_number'] = re.sub('^\(.+\)(.+)$', '\\1', kwargs['control_number'])

if 'object' in kwargs:
# replace spaces by hyphens
kwargs['object'] = kwargs['object'].replace(' ', '-')

if uri_type not in self.config:
raise UnknownSchemeError(scheme_code=self.code, **kwargs)

Expand Down
1 change: 1 addition & 0 deletions mc2skos/vocabularies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ classification_schemes:
utklklass:
concept: http://data.ub.uio.no/lklass/L{object[2:]}
scheme: http://data.ub.uio.no/lklass/
asb: http://uri.gbv.de/terminology/asb/{object}
subject_schemes:
a:
concept: http://id.loc.gov/authorities/subjects/{control_number}
Expand Down
7 changes: 4 additions & 3 deletions tests/test_process_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ def test_ddc_example(marc_file):
check_rdf(graph, expect, rdf_file)


@pytest.mark.parametrize('marc_file', examples('bk-(?P<notation>[0-9.]+)'))
def test_bk_example(marc_file):
@pytest.mark.parametrize('marc_file', examples('(?P<scheme>bk|asb)-(?P<notation>[0-9.]+)'))
def test_bk_asb_example(marc_file):
marc, match = tuple(marc_file)

scheme = match.group('scheme')
notation = match.group('notation')
rdf_file = match.group(1) + '.ttl'

expect = Graph()
uri = URIRef(u'http://uri.gbv.de/terminology/bk/' + notation)
uri = URIRef(u'http://uri.gbv.de/terminology/{}/{}'.format(scheme, notation))
expect.add((uri, RDF.type, SKOS.Concept))

graph = marc.processed_records(include_altlabels=True)
Expand Down

0 comments on commit 56fff5f

Please sign in to comment.