def _get_materials(): from skosprovider.providers import DictionaryProvider materials = DictionaryProvider({'id': 'MATERIALS'}, [{ 'id': '1', 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'Cardboard' }], 'narrower': [2], 'related': [3], 'subordinate_arrays': [56] }, { 'id': '789', 'type': 'collection', 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'Wood by Tree' }], 'members': [654] }]) return materials
def _get_materials_provider(self): import json materials_data = json.load( open( os.path.join(os.path.dirname(__file__), 'data', 'materiaal.txt')), )['materiaal'] from skosprovider.providers import DictionaryProvider from skosprovider.uri import UriPatternGenerator from skosprovider.skos import ConceptScheme, Label, Note materials = DictionaryProvider( {'id': 'Materials'}, materials_data, uri_generator=UriPatternGenerator( 'https://id.erfgoed.net/thesauri/materialen/%s'), conceptscheme=ConceptScheme( uri='https://id.erfgoed.net/thesauri/materialen', labels=[ Label(type='prefLabel', language='nl', label='Materialen') ], notes=[ Note( type='scopeNote', language='nl', note= 'Materialen zijn grondstoffen of halfafgewerkte producten die vaak een rol spelen bij onroerend erfgoed.' ) ])) return materials
def test_find_kastanje(self): trees = DictionaryProvider({ 'id': 'TREES', 'default_language': 'nl' }, [larch, chestnut, species]) concepts = trees.find({'label': 'De Paardekastanje'}) assert len(concepts) == 1
def test_get_all_default_language(self): trees = DictionaryProvider({'id': 'TREES'}, [larch]) self.assertEqual(trees.get_all(), [{ 'id': '1', 'uri': 'http://id.trees.org/1', 'type': 'concept', 'label': 'The Larch' }])
def _get_buildings(): from skosprovider.providers import DictionaryProvider buildings = DictionaryProvider( {'id': 'BUILDINGS'}, [{ 'id': '1', 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'Fortifications' }], 'narrower': [2], 'matches': { 'exact': ['http://vocab.getty.edu/aat/300006888'] } }, { 'id': 2, 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'Castle' }], 'broader': [1, 3], 'matches': { 'broad': ['http://vocab.getty.edu/aat/300006888'] } }, { 'id': 3, 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'Habitations' }], 'narrower': [2, 4], 'matches': { 'close': ['http://vocab.getty.edu/aat/300005425'] } }, { 'id': 4, 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'Huts' }, { 'type': 'prefLabel', 'language': None, 'label': 'Hutten' }], 'broader': [3], 'matches': { 'exact': ['http://vocab.getty.edu/aat/300004824'] } }]) return buildings
def test_empty_provider(self): from skosprovider.providers import DictionaryProvider p = DictionaryProvider({'id': 'EMPTY'}, []) cs = self._get_cs() self.session.add(cs) import_provider(p, cs, self.session) vc = VisitationCalculator(self.session) v = vc.visit(cs) assert 0 == len(v)
def test_empty_provider(self): from skosprovider_sqlalchemy.models import (ConceptScheme as ConceptSchemeModel) from skosprovider.providers import DictionaryProvider p = DictionaryProvider({'id': 'EMPTY'}, []) cs = self._get_cs() self.session.add(cs) import_provider(p, cs, self.session) scheme = self.session.query(ConceptSchemeModel).get(68) assert scheme == cs
def test_register_provider_wrong_scope(self): from skosprovider.skos import ConceptScheme from skosprovider.providers import DictionaryProvider trees = DictionaryProvider( {'id': 'TREES', 'default_language': 'nl'}, [larch, chestnut, species], concept_scheme=ConceptScheme('urn:something'), allowed_instance_scopes = ['threaded_thread'] ) with pytest.raises(RegistryException): self.reg.register_provider(trees)
def test_one_provider_getConceptByUriDifferentFromConceptScheme(self): from skosprovider.skos import ConceptScheme from skosprovider.providers import DictionaryProvider trees = DictionaryProvider( {'id': 'TREES', 'default_language': 'nl'}, [larch, chestnut, species], concept_scheme=ConceptScheme('urn:something') ) self.reg.register_provider(trees) c = self.reg.get_by_uri('http://id.trees.org/1') self.assertEqual(c.id, '1') self.assertEqual(c.uri, 'http://id.trees.org/1')
def test_override_get_vocabulary_uri_generates_cs(self): trees = DictionaryProvider( { 'id': 'TREES', 'uri': 'http://id.trees.org', 'default_language': 'nl', 'subject': ['biology'], 'dataset': { 'uri': 'http://id.trees.org/dataset' } }, [larch, chestnut, species]) assert 'http://id.trees.org' == trees.get_vocabulary_uri() assert 'http://id.trees.org' == trees.concept_scheme.uri
def file_to_json_provider(**kwargs): """ Create Dictionary provider from the input file """ input_file = kwargs.get('input_file') input_name, input_ext = os.path.splitext(os.path.basename(input_file)) with open(input_file, 'r') as data_file: dictionary = json.load(data_file) uri_pattern = kwargs.get('uri_pattern') provider_kwargs = { 'uri_generator': UriPatternGenerator(uri_pattern) } if uri_pattern else {} return DictionaryProvider({'id': input_name.upper()}, dictionary, **provider_kwargs)
def test_find_case_sensitive(self): trees = DictionaryProvider({ 'id': 'TREES', 'default_language': 'nl' }, [larch, chestnut, species], case_insensitive=False) self.assertEqual(trees.find({'label': 'The Lar'}), [{ 'id': '1', 'uri': 'http://id.trees.org/1', 'type': 'concept', 'label': 'De Lariks' }]) self.assertEqual(trees.find({'label': 'lar'}), [])
def _get_event_types(): import json event_data = json.load( open(os.path.join(os.path.dirname(__file__), 'data', 'gebeurtenis.js')), )['gebeurtenis'] from skosprovider.providers import DictionaryProvider from skosprovider.uri import UriPatternGenerator heritage_types = DictionaryProvider( {'id': 'EVENT_TYPES'}, event_data, uri_generator=UriPatternGenerator( 'https://id.erfgoed.net/thesauri/gebeurtenistypes/%s')) return heritage_types
def test_provider_invalid_language(self): from skosprovider.providers import DictionaryProvider with self.assertRaises(ValueError): p = DictionaryProvider({'id': 'EMPTY'}, [{ 'id': '1', 'labels': [{ 'type': 'prefLabel', 'language': 'nederlands', 'label': 'Versterkingen' }] }]) cs = self._get_cs() self.session.add(cs) import_provider(p, cs, self.session)
def test_override_get_vocabulary_uri(self): trees = DictionaryProvider( { 'id': 'TREES', 'uri': 'http://id.trees.org', 'default_language': 'nl', 'subject': ['biology'], 'dataset': { 'uri': 'http://id.trees.org/dataset' } }, [larch, chestnut, species], concept_scheme=ConceptScheme('http://idtoo.trees.org', labels=[{ 'type': 'prefLabel', 'language': 'nl', 'label': 'Soorten' }], languages=['nl', 'en'])) assert 'http://id.trees.org' == trees.get_vocabulary_uri() assert 'http://idtoo.trees.org' == trees.concept_scheme.uri
def _get_heritage_types(): import json typology_data = json.load( open(os.path.join(os.path.dirname(__file__), 'data', 'typologie.js')), )['typologie'] from skosprovider.providers import DictionaryProvider from skosprovider.uri import UriPatternGenerator from skosprovider.skos import ConceptScheme heritage_types = DictionaryProvider( {'id': 'HERITAGE_TYPES'}, typology_data, uri_generator=UriPatternGenerator( 'https://id.erfgoed.net/thesauri/erfgoedtypes/%s'), concept_scheme=ConceptScheme( uri='https://id.erfgoed.net/thesauri/erfgoedtypes', labels=[{ 'label': 'Erfgoedtypes', 'type': 'prefLabel', 'language': 'nl-BE' }, { 'label': 'Heritagetypes', 'type': 'prefLabel', 'language': 'en' }], notes=[{ 'note': 'Different types of heritage.', 'type': 'definition', 'language': 'en' }, { 'note': 'Verschillende types van erfgoed.', 'type': 'definition', 'language': 'nl' }], languages=['nl', 'en'])) return heritage_types
'type': 'prefLabel', 'language': 'nl', 'label': 'Bomen per soort' }, { 'type': 'sortLabel', 'language': 'nl', 'label': 'b' }], 'type': 'collection', 'members': ['1', '2'] } trees = DictionaryProvider( { 'id': 'TREES', 'default_language': 'nl', 'conceptscheme_id': 1 }, [larch, chestnut, species]) world = { 'id': '1', 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'World' }], 'narrower': [2, 3], 'matches': { 'close': ['urn:somethingelse:st1', 'urn:somethingelse:st2'], 'exact': ['urn:something:thingy'], 'related': ['urn:somethingelse:stuff']
def test_override_instance_scopes(self): trees = DictionaryProvider({'id': 'TREES'}, [larch], allowed_instance_scopes=['single']) assert trees.allowed_instance_scopes == ['single']
'note': 'As seen in <em>How to Recognise Different Types of Trees from Quite a Long Way Away</em>.', 'markup': 'HTML' }], 'infer_concept_relations': False } trees = DictionaryProvider( { 'id': 'TREES', 'default_language': 'nl', 'subject': ['biology'], 'dataset': { 'uri': 'http://id.trees.org/dataset' } }, [larch, chestnut, species], concept_scheme=ConceptScheme('http://id.trees.org', labels=[{ 'type': 'prefLabel', 'language': 'nl', 'label': 'Soorten' }], languages=['nl', 'en'])) world = { 'id': '1', 'uri': None, 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'World'
'members': ['1', '2'], 'notes': [ { 'type': 'editorialNote', 'language': 'en', 'note': 'As seen in <em>How to Recognise Different Types of Trees from Quite a Long Way Away</em>.', 'markup': 'HTML' } ] } provider = DictionaryProvider( { 'id': 'TREES', 'default_language': 'nl', 'subject': ['biology'] }, [larch, chestnut, species], uri_generator=UriPatternGenerator('http://id.trees.org/types/%s'), concept_scheme=ConceptScheme('http://id.trees.org') ) # Get a concept or collection by id print(provider.get_by_id(1).label().label) # Get a concept or collection by uri print(provider.get_by_uri('http://id.trees.org/types/1')) # Get all concepts and collections in a provider # If possible, show a Dutch(as spoken in Belgium) label # Order them ascending by label print(provider.get_all(language='nl-BE', sort='label', sort_order='asc'))
# -*- coding: utf-8 -*- ''' Testdata cotaining stylistic (eg. Gothic, Romanesque) and cultural periods (eg. La Tène) .. versionadded:: 0.2.0 ''' from __future__ import unicode_literals from skosprovider.providers import DictionaryProvider from skosprovider.uri import UriPatternGenerator from .stijl_data import STIJLDATA styles_and_cultures = DictionaryProvider( {'id': 'STYLE'}, STIJLDATA, uri_generator=UriPatternGenerator( 'https://id.erfgoed.net/thesauri/stijlen_en_culturen/%s'))
'type': 'prefLabel', 'language': 'nl', 'label': 'Bomen per soort' }, { 'type': 'prefLabel', 'language': 'nl', 'label': 'b' }], 'notes': [{ 'type': 'scopeNote', 'language': 'en', 'note': 'A division of trees.' }], 'type': 'collection', 'members': ['1', '2'] } trees = DictionaryProvider({ 'id': 'TREES', 'default_language': 'nl' }, [larch, chestnut, species], concept_scheme=ConceptScheme( uri='http://python.com/trees', labels=[ Label('Different types of trees', 'prefLabel', 'en'), Label('Verschillende soorten bomen', 'prefLabel', 'nl') ]))
'labels': [{ 'type': 'prefLabel', 'language': 'nl', 'label': 'vakwerkbouw' }], 'type': 'concept', 'id': 2, 'related': [] }, { 'broader': [62], 'narrower': [], 'notes': [], 'labels': [{ 'type': 'prefLabel', 'language': 'nl', 'label': 'vlaardingencultuur' }], 'type': 'concept', 'id': 113, 'related': [] }] styles_and_cultures = DictionaryProvider( {'id': 'STYLE'}, sdata, uri_generator=UriPatternGenerator('urn:x-vioe:styles:%s'))
def _get_tree_provider(self, dictionary): return DictionaryProvider({'id': 'TEST'}, dictionary)
def test_all_providers(self): self.dummy.provider = DictionaryProvider(list=[species], metadata={'id': 'Test'}) self.dummy.all_providers('ok') self.assertEqual(self.dummy.dummy, 'ok')
def test_no_sqlalchemyprovider(self): self.dummy.provider = DictionaryProvider(list=[species], metadata={'id': 'Test'}) self.assertRaises(HTTPMethodNotAllowed, self.dummy.internal_providers, 'ok') self.assertIsNone(self.dummy.dummy)
# -*- coding: utf-8 -*- ''' Testdata cotaining heritage types .. versionadded:: 0.4.4 ''' from __future__ import unicode_literals from skosprovider.providers import DictionaryProvider from skosprovider.uri import UriPatternGenerator from .heritagetypes_data import HERITAGETYPESDATA heritagetypes = DictionaryProvider( {'id': 'HERITAGETYPE'}, HERITAGETYPESDATA, uri_generator=UriPatternGenerator( 'https://id.erfgoed.net/thesauri/erfgoedtypes/%s'))
# -*- coding: utf-8 -*- ''' Testdata cotaining materials: concrete, glass, metal, silex, ... .. versionadded:: 0.2.0 ''' from __future__ import unicode_literals from skosprovider.providers import DictionaryProvider from skosprovider.uri import UriPatternGenerator from .materiaal_data import MATERIAALDATA materials = DictionaryProvider( {'id': 'MATERIAL'}, MATERIAALDATA, uri_generator=UriPatternGenerator( 'https://id.erfgoed.net/thesauri/materialen/%s'))
"members": [{ "id": 333 }, { "id": 7 }], "notes": [{ "note": "een notitie", "type": "note", "language": "nl" }] } TEST = DictionaryProvider( { 'id': 'TEST', 'default_language': 'nl', 'subject': ['biology'] }, [larch, chestnut, species], concept_scheme=skosprovider.skos.ConceptScheme('http://id.trees.org')) class FunctionalTests(unittest.TestCase): @classmethod def setUpClass(cls): cls.engine = engine_from_config(settings, prefix='sqlalchemy.') cls.session_maker = sessionmaker(bind=cls.engine, extension=ZopeTransactionExtension()) def setUp(self): self.config = Configurator(settings=settings) self.config.add_route('login', '/auth/login')
'type': 'collection', 'members': ['1', '2'], 'notes': [{ 'type': 'editorialNote', 'language': 'en', 'note': 'As seen in <em>How to Recognise Different Types of Trees from Quite a Long Way Away</em>.', 'markup': 'HTML' }] } trees = DictionaryProvider( { 'id': 'TREES', 'default_language': 'nl', 'subject': ['biology'] }, [larch, chestnut, species], concept_scheme=ConceptScheme('http://id.trees.org')) world = { 'id': '1', 'uri': None, 'labels': [{ 'type': 'prefLabel', 'language': 'en', 'label': 'World' }], 'narrower': [2, 3] }