Skip to content

Commit

Permalink
fixes #4 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
dieuska committed Sep 30, 2014
1 parent 7cb96d8 commit 739a148
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
16 changes: 8 additions & 8 deletions skosprovider_heritagedata/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import logging
from skosprovider.providers import VocabularyProvider
from skosprovider_heritagedata.utils import (
uri_to_id,
heritagedata_to_skos, uri_to_base_uri)
heritagedata_to_skos, _split_uri)

log = logging.getLogger(__name__)


class HeritagedataProvider(VocabularyProvider):
"""A provider that can work with the Heritagedata services of
http://www.heritagedata.org/blog/services/
Expand All @@ -33,8 +33,8 @@ def __init__(self, metadata, **kwargs):
if metadata['default_language'] != 'en':
raise ValueError("Only english('en') is supported as language for this skosprovider")
if 'scheme_uri' in kwargs:
self.base_scheme_uri = uri_to_base_uri(kwargs['scheme_uri'])
self.scheme_id = uri_to_id(kwargs['scheme_uri'])
self.base_scheme_uri = _split_uri(kwargs['scheme_uri'], 0)
self.scheme_id = _split_uri(kwargs['scheme_uri'], 1)
else:
self.base_scheme_uri = 'http://purl.org/heritagedata/schemes'
self.scheme_id = 'eh_period'
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_by_id(self, id):
except Exception as err:
if hasattr(err, 'code'):
if err.code == 404:
return None
return False
else:
raise

Expand All @@ -83,7 +83,7 @@ def get_by_uri(self, uri):
:return: corresponding :class:`skosprovider.skos.Concept` or :class:`skosprovider.skos.Concept`.
Returns None if non-existing id
"""
id = uri_to_id(uri)
id = _split_uri(uri, 1)
return self.get_by_id(id)


Expand Down Expand Up @@ -222,7 +222,7 @@ def _get_children(self, id, all=False):
answer = []
for r in result:
if r['property'] == str(SKOS.narrower):
child_id = uri_to_id(r["uri"])
child_id = _split_uri(r["uri"], 1)
answer.append(child_id)
if all is True:
child_list = self._get_children(child_id, all=True)
Expand Down Expand Up @@ -253,7 +253,7 @@ def _get_items(self, service, params):
for r in result:
if 'property' not in r.keys() or r['property'] == str(SKOS.narrower):
item = {
'id': uri_to_id(r["uri"]),
'id': _split_uri(r["uri"], 1),
'uri': r["uri"],
'type': 'concept',
'label': r["label"]
Expand Down
12 changes: 5 additions & 7 deletions skosprovider_heritagedata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def from_graph(self):
clist = []
for sub, pred, obj in self.graph.triples((None, RDF.type, SKOS.Concept)):
uri = str(sub)
con = Concept(uri_to_id(uri), uri=uri)
con = Concept(_split_uri(uri, 1), uri=uri)
con.broader = self._create_from_subject_predicate(sub, SKOS.broader)
con.narrower = self._create_from_subject_predicate(sub, SKOS.narrower)
con.related = self._create_from_subject_predicate(sub, SKOS.related)
Expand All @@ -35,7 +35,7 @@ def from_graph(self):

for sub, pred, obj in self.graph.triples((None, RDF.type, SKOS.Collection)):
uri = str(sub)
col = Collection(uri_to_id(uri), uri=uri)
col = Collection(_split_uri(uri, 1), uri=uri)
col.members = self._create_from_subject_predicate(sub, SKOS.member)
col.labels = self._create_from_subject_typelist(sub, Label.valid_types)
col.notes = self._create_from_subject_typelist(sub, Note.valid_types)
Expand Down Expand Up @@ -64,7 +64,7 @@ def _create_from_subject_predicate(self, subject, predicate, note_uris=None):
else:
o = None
else:
o = uri_to_id(o)
o = _split_uri(o, 1)
if o:
list.append(o)
return list
Expand Down Expand Up @@ -94,8 +94,6 @@ def _create_note(self, uri, type):

return Note(note, type, language)

def uri_to_id(uri):
return uri.strip('/').rsplit('/',1)[1]
def _split_uri(uri, index):
return uri.strip('/').rsplit('/', 1)[index]

def uri_to_base_uri(uri):
return uri.strip('/').rsplit('/',1)[0]
2 changes: 1 addition & 1 deletion tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_get_by_id_concept(self):

def test_get_by_id_nonexistant_id(self):
concept = HeritagedataProvider({'id': 'Heritagedata'}, scheme_uri='http://purl.org/heritagedata/schemes/eh_period').get_by_id('123')
self.assertIsNone(concept)
self.assertFalse(concept)

def test_get_by_uri(self):
concept = HeritagedataProvider({'id': 'Heritagedata'}, scheme_uri='http://purl.org/heritagedata/schemes/eh_period').get_by_uri('http://purl.org/heritagedata/schemes/eh_period/concepts/PM')
Expand Down

0 comments on commit 739a148

Please sign in to comment.