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 setUp(self): from skosprovider.uri import UriPatternGenerator self.ifile = open( os.path.join(os.path.dirname(__file__), 'data', 'menu.csv'), "r") reader = csv.reader(self.ifile) self.csvprovider = SimpleCsvProvider( {'id': 'MENU'}, reader, uri_generator=UriPatternGenerator('http://id.python.org/menu/%s'), concept_scheme=ConceptScheme('http://id.python.org/menu'))
def setUp(self): Base.metadata.create_all(self.engine) self.session = self.session_maker() Initialiser(self.session).init_all() create_data(self.session) self.provider = SQLAlchemyProvider( { 'id': 'SOORTEN', 'conceptscheme_id': 1 }, self.session_maker, uri_generator=UriPatternGenerator('urn:x-skosprovider-sa:test:%s'))
def test_set_uri_generator(self): from skosprovider.uri import UriPatternGenerator # Set up provider provider = SQLAlchemyProvider({ 'id': 'SOORTEN', 'conceptscheme_id': 1 }, self.session_maker, uri_generator=UriPatternGenerator( 'http://id.example.com/trees/%s')) assert 'http://id.example.com/trees/1' == provider.uri_generator.generate( id=1)
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 file_to_csv_provider(**kwargs): """ Create CSV 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 ifile: reader = csv.reader(ifile) uri_pattern = kwargs.get('uri_pattern') provider_kwargs = { 'uri_generator': UriPatternGenerator(uri_pattern) } if uri_pattern else {} return SimpleCsvProvider({'id': input_name.upper()}, reader, **provider_kwargs)
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 get_internal_providers(config): ret = [] engine = create_engine(config.get_settings()['sqlalchemy.url'], echo=True) engine.connect() result = engine.execute('SELECT * from conceptscheme') for row in result: scheme_db_id = row[0] scheme_uri = row[1] scheme_id = scheme_uri.split('/')[-1] scheme = SQLAlchemyProvider( { 'id': scheme_id, 'conceptscheme_id': scheme_db_id }, config.registry.dbmaker, uri_generator=UriPatternGenerator(f'{scheme_uri}/%s')) ret.append(scheme) engine.dispose() return ret
def test_gen_uri(self): from skosprovider_sqlalchemy.models import Concept, ConceptScheme from skosprovider.uri import UriPatternGenerator # Set up provider provider = SQLAlchemyProvider({ 'id': 'SOORTEN', 'conceptscheme_id': 99 }, self.session_maker, uri_generator=UriPatternGenerator( 'http://id.example.com/trees/%s')) c1 = Concept(concept_id=1, conceptscheme=ConceptScheme( id=99, uri='http://id.example.com/trees')) session = self.session_maker() session.add(c1) session.commit() assert c1.uri is None c2 = provider.get_by_id(1) assert c2.uri == 'http://id.example.com/trees/1'
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
from skosprovider.providers import SimpleCsvProvider from skosprovider.uri import UriPatternGenerator from skosprovider.skos import ConceptScheme, Label, Note, Source from skosprovider_rdf.utils import rdf_dumper ifile = open(os.path.join(os.path.dirname(__file__), 'data', 'menu.csv'), "r") reader = csv.reader(ifile) csvprovider = SimpleCsvProvider( {'id': 'MENU'}, reader, uri_generator=UriPatternGenerator('http://id.python.org/menu/%s'), concept_scheme=ConceptScheme( uri='http://id.python.org/menu', labels=[ Label(type='prefLabel', language='en', label='A pythonesque menu.') ], notes=[ Note( type='changeNote', language='en', note= "<strong>We didn't need no change notes when I was younger.</strong>", markup='HTML') ], sources=[Source("Monthy Python's Flying Circus, 1970. Spam.")]))
def test_simple(self): urigen = UriPatternGenerator('http://id.example.com/%s') self.assertEqual('http://id.example.com/1', urigen.generate(id=1))
'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')) # Get the top concepts in a provider
'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'))
# -*- 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'))
def includeme(config): # pragma: no cover dataseturigenerator = UriPatternGenerator('https://id.erfgoed.net/datasets/thesauri/%s') TREES = SQLAlchemyProvider( {'id': 'TREES', 'conceptscheme_id': 1}, config.registry.dbmaker ) GEO = SQLAlchemyProvider( {'id': 'GEOGRAPHY', 'conceptscheme_id': 2}, config.registry.dbmaker ) STYLES = SQLAlchemyProvider( { 'id': 'STYLES', 'conceptscheme_id': 3, 'dataset': { 'uri': dataseturigenerator.generate(id='stijlen_en_culturen'), 'publisher': ['https://id.erfgoed.net/actoren/501'], 'created': [date(2008,2,14)], 'language': ['nl-BE'], 'license': [ 'https://creativecommons.org/licenses/by/4.0/', 'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0' ] } }, config.registry.dbmaker, uri_generator=UriPatternGenerator('https://id.erfgoed.net/thesauri/stijlen_en_culturen/%s') ) MATERIALS = SQLAlchemyProvider( { 'id': 'MATERIALS', 'conceptscheme_id': 4, 'dataset': { 'uri': dataseturigenerator.generate(id='materialen'), 'publisher': ['https://id.erfgoed.net/actoren/501'], 'created': [date(2011,3,16)], 'language': ['nl-BE'], 'license': [ 'https://creativecommons.org/licenses/by/4.0/', 'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0' ] } }, config.registry.dbmaker, uri_generator=UriPatternGenerator('https://id.erfgoed.net/thesauri/materialen/%s') ) EVENTTYPES = SQLAlchemyProvider( { 'id': 'EVENTTYPE', 'conceptscheme_id': 5, 'dataset': { 'uri': dataseturigenerator.generate(id='gebeurtenistypes'), 'publisher': ['https://id.erfgoed.net/actoren/501'], 'created': [date(2010,8,13)], 'language': ['nl-BE'], 'license': [ 'https://creativecommons.org/licenses/by/4.0/', 'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0' ] } }, config.registry.dbmaker, uri_generator=UriPatternGenerator('https://id.erfgoed.net/thesauri/gebeurtenistypes/%s') ) HERITAGETYPES = SQLAlchemyProvider( { 'id': 'HERITAGETYPE', 'conceptscheme_id': 6, 'dataset': { 'uri': dataseturigenerator.generate(id='erfgoedtypes'), 'publisher': ['https://id.erfgoed.net/actoren/501'], 'created': [date(2008,2,14)], 'language': ['nl-BE'], 'license': [ 'https://creativecommons.org/licenses/by/4.0/', 'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0' ] } }, config.registry.dbmaker, uri_generator=UriPatternGenerator('https://id.erfgoed.net/thesauri/erfgoedtypes/%s') ) PERIODS = SQLAlchemyProvider( { 'id': 'PERIOD', 'conceptscheme_id': 7, 'dataset': { 'uri': dataseturigenerator.generate(id='dateringen'), 'publisher': ['https://id.erfgoed.net/actoren/501'], 'created': [date(2008,2,14)], 'language': ['nl-BE'], 'license': [ 'https://creativecommons.org/licenses/by/4.0/', 'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0' ] } }, config.registry.dbmaker, uri_generator=UriPatternGenerator('https://id.erfgoed.net/thesauri/dateringen/%s') ) SPECIES = SQLAlchemyProvider( { 'id': 'SPECIES', 'conceptscheme_id': 8, 'dataset': { 'uri': dataseturigenerator.generate(id='soorten'), 'publisher': ['https://id.erfgoed.net/actoren/501'], 'created': [date(2011,5,23)], 'language': ['nl-BE', 'la'], 'license': [ 'https://creativecommons.org/licenses/by/4.0/', 'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0' ] } }, config.registry.dbmaker, uri_generator=UriPatternGenerator('https://id.erfgoed.net/thesauri/soorten/%s') ) # use 'subject': ['external'] for read only external providers (only available in REST service) getty_session = CacheControl(requests.Session(), heuristic=ExpiresAfter(weeks=1)) AAT = AATProvider( {'id': 'AAT', 'subject': ['external']}, session=getty_session ) TGN = TGNProvider( {'id': 'TGN', 'subject': ['external']}, session=getty_session ) eh_session = CacheControl(requests.Session(), heuristic=ExpiresAfter(weeks=1)) EH_PERIOD = HeritagedataProvider( {'id': 'EH_PERIOD', 'subject': ['external']}, scheme_uri='http://purl.org/heritagedata/schemes/eh_period', session=eh_session ) EH_MONUMENT_TYPE = HeritagedataProvider( {'id': 'EH_MONUMENT_TYPE', 'subject': ['external']}, scheme_uri='http://purl.org/heritagedata/schemes/eh_tmt2', session=eh_session ) EH_MATERIALS = HeritagedataProvider( {'id': 'EH_MATERIALS', 'subject': ['external']}, scheme_uri='http://purl.org/heritagedata/schemes/eh_tbm', session=eh_session ) skosregis = config.get_skos_registry() skosregis.register_provider(TREES) skosregis.register_provider(GEO) skosregis.register_provider(STYLES) skosregis.register_provider(MATERIALS) skosregis.register_provider(EVENTTYPES) skosregis.register_provider(HERITAGETYPES) skosregis.register_provider(PERIODS) skosregis.register_provider(SPECIES) skosregis.register_provider(AAT) skosregis.register_provider(TGN) skosregis.register_provider(EH_PERIOD) skosregis.register_provider(EH_MONUMENT_TYPE) skosregis.register_provider(EH_MATERIALS)
def includeme(config): # pragma: no cover TREES = SQLAlchemyProvider({ 'id': 'TREES', 'conceptscheme_id': 1 }, config.registry.dbmaker) GEO = SQLAlchemyProvider({ 'id': 'GEOGRAPHY', 'conceptscheme_id': 2 }, config.registry.dbmaker) STYLES = SQLAlchemyProvider({ 'id': 'STYLES', 'conceptscheme_id': 3 }, config.registry.dbmaker) MATERIALS = SQLAlchemyProvider( { 'id': 'MATERIALS', 'conceptscheme_id': 4 }, config.registry.dbmaker, uri_generator=UriPatternGenerator('urn:x-vioe:materials:%s')) # use 'subject': ['external'] for read only external providers (only available in REST service) AAT = AATProvider({'id': 'AAT', 'subject': ['external']}, ) TGN = TGNProvider({'id': 'TGN', 'subject': ['external']}) EH_PERIOD = HeritagedataProvider( { 'id': 'EH_PERIOD', 'subject': ['external'] }, scheme_uri='http://purl.org/heritagedata/schemes/eh_period') EH_MONUMENT_TYPE = HeritagedataProvider( { 'id': 'EH_MONUMENT_TYPE', 'subject': ['external'] }, scheme_uri='http://purl.org/heritagedata/schemes/eh_tmt2') EH_MATERIALS = HeritagedataProvider( { 'id': 'EH_MATERIALS', 'subject': ['external'] }, scheme_uri='http://purl.org/heritagedata/schemes/eh_tbm') skosregis = config.get_skos_registry() skosregis.register_provider(TREES) skosregis.register_provider(GEO) skosregis.register_provider(STYLES) skosregis.register_provider(MATERIALS) skosregis.register_provider(AAT) skosregis.register_provider(TGN) skosregis.register_provider(EH_PERIOD) skosregis.register_provider(EH_MONUMENT_TYPE) skosregis.register_provider(EH_MATERIALS)
# -*- 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'))
# -*- coding: utf-8 -*- ''' Testdata cotaining event types .. versionadded:: 0.4.4 ''' from __future__ import unicode_literals from skosprovider.providers import DictionaryProvider from skosprovider.uri import UriPatternGenerator from .eventtypes_data import EVENTTYPESDATA eventtypes = DictionaryProvider( {'id': 'EVENTTYPE'}, EVENTTYPESDATA, uri_generator=UriPatternGenerator('https://id.erfgoed.net/thesauri/gebeurtenistypes/%s') )
def setUp(self): self.config = Configurator(settings=settings) self.config.add_route('login', '/auth/login') self.config.add_route('logout', '/auth/logout') includeme(self.config) self.config.add_static_view('atramhasis/static', 'atramhasis:static') Base.metadata.drop_all(self.engine) Base.metadata.create_all(self.engine) Base.metadata.bind = self.engine self.config.registry.dbmaker = self.session_maker self.config.add_request_method(db, reify=True) with transaction.manager: local_session = self.session_maker() import_provider( trees, ConceptScheme(id=1, uri='urn:x-skosprovider:trees'), local_session) import_provider(materials, ConceptScheme(id=4, uri='urn:x-vioe:materials'), local_session) import_provider(geo, ConceptScheme(id=2), local_session) local_session.add(ConceptScheme(id=3)) local_session.add(LabelType('hiddenLabel', 'A hidden label.')) local_session.add(LabelType('altLabel', 'An alternative label.')) local_session.add(LabelType('prefLabel', 'A preferred label.')) local_session.add(Language('nl', 'Dutch')) local_session.add(Language('en', 'English')) local_session.add(MatchType('broadMatch', '')) local_session.add(MatchType('closeMatch', '')) local_session.add(MatchType('exactMatch', '')) local_session.add(MatchType('narrowMatch', '')) local_session.add(MatchType('relatedMatch', '')) local_session.add(Language(id='de', name='test')) TREES = SQLAlchemyProvider({ 'id': 'TREES', 'conceptscheme_id': 1 }, self.config.registry.dbmaker) GEO = SQLAlchemyProvider({ 'id': 'GEOGRAPHY', 'conceptscheme_id': 2 }, self.config.registry.dbmaker) STYLES = SQLAlchemyProvider({ 'id': 'STYLES', 'conceptscheme_id': 3 }, self.config.registry.dbmaker) MATERIALS = SQLAlchemyProvider( { 'id': 'MATERIALS', 'conceptscheme_id': 4 }, self.config.registry.dbmaker, uri_generator=UriPatternGenerator('urn:x-vioe:materials:%s')) self.config.add_subscriber(self.mock_event_handler, ProtectedResourceEvent) self.config.add_subscriber( self.mock_event_handler_provider_unavailable, ProtectedResourceEvent) skosregis = self.config.get_skos_registry() skosregis.register_provider(TREES) skosregis.register_provider(GEO) skosregis.register_provider(STYLES) skosregis.register_provider(MATERIALS) skosregis.register_provider(TEST) self.app = self.config.make_wsgi_app() self.testapp = TestApp(self.app)
def test_simple(self): urigen = UriPatternGenerator('http://id.example.com/%s') self.assertEqual( 'http://id.example.com/1', urigen.generate(id=1) )
# -*- 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'))