Skip to content

Commit

Permalink
[#32] Allow repeated $4 and $0 in 7XX
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Jul 6, 2017
1 parent 3cc7175 commit 1aa9f69
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 47 deletions.
18 changes: 10 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,13 @@ Notes:
The relationship type is ``skos:broader`` if ``$w=g``, ``skos:narrower`` if ``$w=h``,
and ``skos:related`` otherwise.
If ``$w=r`` and ``$4`` contains an URI, that URI is used as the relationship type.

* Mappings/relationships are generated for 7XX headings if the fields contain a ``$0``
subfield containing either the control number or the URI of the related record.
If ``$0`` contains a control number, an URI pattern for the vocabulary
(found in indicator 2 or ``$2``) must be defined in mc2skos.record.CONFIG.
If ``$4`` contains an URI, that URI is used as the relationship type.
Otherwise, if ``$4`` contains one of the ISO 25964 relations, the corresponding
SKOS relation is used. Otherwise, the default value ``skos:closeMatch`` is used.
Note that ``$4`` must precede ``$0`` (since both subfields can be repeated).

* Mappings/relationships are generated for 7XX headings if the fields contain a ``$0``
subfield containing either the control number or the URI of the related record.
If ``$0`` contains a control number, an URI pattern for the vocabulary
(found in indicator 2 or ``$2``) must be defined in mc2skos.record.CONFIG.
If ``$4`` contains an URI, that URI is used as the relationship type.
Otherwise, if ``$4`` contains one of the ISO 25964 relations, the corresponding
SKOS relation is used. Otherwise, the default value ``skos:closeMatch`` is used.
Note that ``$4`` must precede ``$0`` (since both subfields can be repeated).
1 change: 1 addition & 0 deletions examples/noubomn-c000011.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
owl:deprecated true ;
skos:closeMatch <http://id.loc.gov/authorities/subjects/sh85086566> ;
skos:exactMatch <http://data.ub.uio.no/humord/c08221>,
<http://dbpedia.org/page/Mold>,
<http://www.wikidata.org/entity/Q159341> ;
skos:inScheme <http://data.ub.uio.no/realfagstermer/> ;
skos:prefLabel "Mugg"@nb .
Expand Down
6 changes: 3 additions & 3 deletions examples/noubomn-c000011.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
</datafield>
<datafield ind1=" " ind2="7" tag="750">
<subfield code="a">Muggsopp</subfield>
<subfield code="4">=EQ</subfield>
<subfield code="0">(No-TrBIB)HUME08221</subfield>
<subfield code="2">humord</subfield>
<subfield code="4">=EQ</subfield>
</datafield>
<datafield ind1=" " ind2="7" tag="750">
<subfield code="a">muggsopp</subfield>
<subfield code="0">http://www.wikidata.org/entity/Q159341</subfield>
<subfield code="4">http://www.w3.org/2004/02/skos/core#exactMatch</subfield>
<subfield code="0">http://www.wikidata.org/entity/Q159341</subfield>
<subfield code="0">http://dbpedia.org/page/Mold</subfield>
</datafield>
<datafield ind1=" " ind2="0" tag="750">
<subfield code="a">Molds (Fungi)</subfield>
Expand Down
75 changes: 39 additions & 36 deletions mc2skos/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,40 +758,43 @@ def parse(self, options):

# 7XX: Heading Linking Entries
for heading in self.get_terms('7'):
sf_4 = heading['node'].text('mx:subfield[@code="4"]')
sf_0 = heading['node'].text('mx:subfield[@code="0"]')
relation = None
for sf in heading['node'].all('mx:subfield'):
if sf.get('code') == '4':
if is_uri(sf.text()):
relation = URIRef(sf.text())
else:
relation = {
'=EQ': SKOS.exactMatch,
'~EQ': SKOS.closeMatch,
'BM': SKOS.broadMatch,
'NM': SKOS.narrowMatch,
'RM': SKOS.relatedMatch,
}.get(sf.text()) # None if no match

elif sf.get('code') == '0':
# Note: Default value might change in the future
relation = relation if relation else SKOS.closeMatch

if is_uri(sf.text()):
self.relations.append({
'uri': sf.text(),
'relation': relation,
})
else:
scheme_code = {
'0': 'a', # Library of Congress Subject Headings
'1': 'b', # LC subject headings for children's literature
'2': 'c', # Medical Subject Headings
'3': 'd', # National Agricultural Library subject authority file
'4': 'n', # Source not specified
'5': 'k', # Canadian Subject Headings
'6': 'v', # Répertoire de vedettes-matière
'7': heading['node'].text('mx:subfield[@code="2"]'), # Source specified in subfield $2
}.get(heading['node'].get('ind2'))

if sf_4 is not None and is_uri(sf_4):
relation = URIRef(sf_4)
else:
relation = {
'=EQ': SKOS.exactMatch,
'~EQ': SKOS.closeMatch,
'BM': SKOS.broadMatch,
'NM': SKOS.narrowMatch,
'RM': SKOS.relatedMatch,
}.get(sf_4)

relation = relation or SKOS.closeMatch # default
if is_uri(sf_0):
self.relations.append({
'uri': sf_0,
'relation': relation,
})
else:
scheme_code = {
'0': 'a', # Library of Congress Subject Headings
'1': 'b', # LC subject headings for children's literature
'2': 'c', # Medical Subject Headings
'3': 'd', # National Agricultural Library subject authority file
'4': 'n', # Source not specified
'5': 'k', # Canadian Subject Headings
'6': 'v', # Répertoire de vedettes-matière
'7': heading['node'].text('mx:subfield[@code="2"]'), # Source specified in subfield $2
}.get(heading['node'].get('ind2'))

self.append_relation(
ConceptScheme(scheme_code, AuthorityRecord),
relation,
control_number=sf_0
)
self.append_relation(
ConceptScheme(scheme_code, AuthorityRecord),
relation,
control_number=sf.text()
)

0 comments on commit 1aa9f69

Please sign in to comment.