Skip to content

Commit

Permalink
Get matches working.
Browse files Browse the repository at this point in the history
  • Loading branch information
koenedaele committed Oct 13, 2014
1 parent be2e1b3 commit fbc1299
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion skosprovider_sqlalchemy/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Concept as ConceptModel,
Collection as CollectionModel,
Label as LabelModel,
MatchType as MatchTypeModel,
Visitation
)

Expand Down Expand Up @@ -122,6 +123,12 @@ def _from_thing(self, thing):
superordinates=[broader_concept.concept_id for broader_concept in thing.broader_concepts]
)
else:
matches = {}
for m in thing.matches:
key = m.matchtype.name[:m.matchtype.name.find('Match')]
if not key in matches:
matches[key] = []
matches[key].append(m.uri)
return Concept(
id=thing.concept_id,
uri=thing.uri if thing.uri is not None else self.uri_generator.generate(type='concept', id=thing.concept_id),
Expand All @@ -137,7 +144,8 @@ def _from_thing(self, thing):
narrower=[c.concept_id for c in thing.narrower_concepts],
related=[c.concept_id for c in thing.related_concepts],
member_of=[member_of.concept_id for member_of in thing.member_of],
subordinate_arrays=[narrower_collection.concept_id for narrower_collection in thing.narrower_collections]
subordinate_arrays=[narrower_collection.concept_id for narrower_collection in thing.narrower_collections],
matches=matches
)

def get_by_id(self, id):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_data(request, session):
cath.member_of.add(col)
match = Match(
matchtype_id = 'closeMatch',
uri = 'http://aat:something'
uri = 'http://vocab.getty.edu/aat/300007501'
)
cath.matches.append(match)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def test_concept_has_correct_note(self, provider):
assert len(cath.notes) == 1
assert isinstance(cath.notes[0], Note)

def test_concept_has_matches(self, provider):
cath = provider.get_by_id(4)
assert len(cath.matches.keys()) == 5
assert len(cath.matches['close']) == 1
assert cath.matches['close'][0] == 'http://vocab.getty.edu/aat/300007501'

def test_get_collection_by_id(self, provider):
from skosprovider.skos import Collection
col = provider.get_by_id(2)
Expand Down

0 comments on commit fbc1299

Please sign in to comment.