Skip to content

Commit

Permalink
Add languages to conceptschemes. Refs #18
Browse files Browse the repository at this point in the history
  • Loading branch information
koenedaele committed Aug 26, 2015
1 parent 4b20221 commit 0e70d4e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
version of `skosprovider_sqlalchemy`, any databases created in that previous
verions will need to be updated as well. Please add a field called `markup`
to the `note` table.
* Inline with the skosprovider 0.6.0 update, a `languages` attribute was added
to :class:`skosprovider_sqlalchemy.models.ConceptScheme`. When upgrading from
a previous version of `skosprovider_sqlalchemy`, any databases created with
that previous verions will need to be updated as well. Please add a table
called `conceptscheme_language` with fields `conceptscheme_id` and
`language_id`. (#18)

0.4.2 (2015-03-02)
------------------
Expand Down
22 changes: 21 additions & 1 deletion skosprovider_sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@
Column('note_id', Integer, ForeignKey('note.id'), primary_key=True)
)

conceptscheme_language = Table(
'conceptscheme_language',
Base.metadata,
Column(
'conceptscheme_id',
Integer,
ForeignKey('conceptscheme.id'),
primary_key=True
),
Column(
'language_id',
String(64),
ForeignKey('language.id'),
primary_key=True
)
)

collection_concept = Table(
'collection_concept',
Base.metadata,
Expand Down Expand Up @@ -294,7 +311,10 @@ class ConceptScheme(Base):
secondary=conceptscheme_note,
backref=backref('conceptscheme', uselist=False)
)

languages = relationship(
'Language',
secondary=conceptscheme_language
)
def label(self, language='any'):
return label(self.labels, language)

Expand Down
3 changes: 3 additions & 0 deletions skosprovider_sqlalchemy/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def _get_concept_scheme(self):
notes=[
Note(n.note, n.notetype_id, n.language_id, n.markup)
for n in csm.notes
],
languages=[
l.id for l in csm.languages
]
)

Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ def create_data(session):
Collection,
Label,
Note,
Match
Match,
Language
)
en = session.query(Language).get('en')
nl = session.query(Language).get('nl')
cs = ConceptScheme(
id=1,
uri='urn:x-skosprovider:test'
uri='urn:x-skosprovider:test',
languages=[en, nl]
)
session.add(cs)
con = Concept(
Expand Down
8 changes: 6 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,18 @@ def _get_target_class(self):
return ConceptScheme

def test_simple(self):
from skosprovider_sqlalchemy.models import Label
from skosprovider_sqlalchemy.models import Label, Language
l = Label('Heritage types', 'prefLabel', 'en')
en = Language('en', 'English')
c = self._get_target_class()(
id=1,
labels=[l]
labels=[l],
languages=[en]
)
self.assertEqual(1, c.id)
self.assertEqual(l, c.label())
self.assertEqual(1, len(c.languages))
self.assertIn(en, c.languages)


class CollectionTests(ModelTestCase):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ def test_gen_uri(self):
c2 = provider.get_by_id(1)
assert c2.uri == 'http://id.example.com/trees/1'

def test_concept_scheme(self):
from skosprovider.skos import (
ConceptScheme
)
cs = self.provider.concept_scheme
assert isinstance(cs, ConceptScheme)
assert 'urn:x-skosprovider:test' == cs.uri
assert 2 == len(cs.languages)
assert 'en' in cs.languages

def test_get_concept_by_id(self):
from skosprovider.skos import Concept

Expand Down

0 comments on commit 0e70d4e

Please sign in to comment.