def test_labels_to_string(self): labels = [ Label(label='De Paardekastanje', language_id='nl'), Label(label='la châtaigne', language_id='fr') ] s = labels_to_string(labels, 'prefLabel') self.assertEqual('De Paardekastanje (nl), la châtaigne (fr)', s)
def setUp(self): conceptscheme = ConceptScheme() conceptscheme.uri = 'urn:x-atramhasis-demo' conceptscheme.id = 1 self.concept = Concept() self.concept.type = 'concept' self.concept.id = 11 self.concept.concept_id = 101 self.concept.uri = 'urn:x-atramhasis-demo:TREES:101' self.concept.conceptscheme_id = 1 self.concept.conceptscheme = conceptscheme notes = [] note = Note(note='test note', notetype_id='example', language_id='en') note2 = Note(note='note def', notetype_id='definition', language_id='en') notes.append(note) notes.append(note2) self.concept.notes = notes labels = [] label = Label(label='een label', labeltype_id='prefLabel', language_id='nl') label2 = Label(label='other label', labeltype_id='altLabel', language_id='en') label3 = Label(label='and some other label', labeltype_id='altLabel', language_id='en') labels.append(label) labels.append(label2) labels.append(label3) self.concept.labels = labels matches = [] match1 = Match() match1.uri = 'urn:test' match1.concept = self.concept match1.matchtype = MatchType(name='closeMatch', description='') match2 = Match() match2.uri = 'urn:test' match2.concept = self.concept match2.matchtype = MatchType(name='closeMatch', description='') matches.append(match1) matches.append(match2) self.matches = matches self.collection = Collection() self.collection.type = 'collection' self.collection.id = 12 self.collection.concept_id = 102 self.collection.uri = 'urn:x-atramhasis-demo:TREES:102' self.collection.conceptscheme_id = 1 self.collection.conceptscheme = conceptscheme
def setUp(self): self.concept = Concept() self.concept.type = 'concept' self.concept.id = 11 self.concept.concept_id = 101 self.concept.uri = 'urn:x-atramhasis-demo:TREES:101' self.concept.conceptscheme_id = 1 notes = [] note = Note(note='test note', notetype_id='example', language_id='en') note2 = Note(note='note def', notetype_id='definition', language_id='en') notes.append(note) notes.append(note2) self.concept.notes = notes labels = [] label = Label(label='een label', labeltype_id='prefLabel', language_id='nl') label2 = Label(label='other label', labeltype_id='altLabel', language_id='en') label3 = Label(label='and some other label', labeltype_id='altLabel', language_id='en') labels.append(label) labels.append(label2) labels.append(label3) self.concept.labels = labels matches = [] match = Match() match.matchtype = MatchType(name='closeMatch', description='test') match.uri = 'urn:somethingelse:st1' matches.append(match) match2 = Match() match2.matchtype = MatchType(name='closeMatch', description='test') match2.uri = 'urn:somethingelse:st2' matches.append(match2) match3 = Match() match3.matchtype = MatchType(name='exactMatch', description='test') match3.uri = 'urn:something:thingy' matches.append(match3) self.concept.matches = matches self.collection = Collection() self.collection.type = 'collection' self.collection.id = 12 self.collection.concept_id = 102 self.collection.uri = 'urn:x-atramhasis-demo:TREES:102' self.collection.conceptscheme_id = 1 self.concept.member_of.add(self.collection) self.collection.members.add(self.concept)
def get_all_mock(): a_concept = Concept(concept_id=7895, conceptscheme_id=1, type='concept') a_labels = [Label(label='De Paardekastanje', language_id='nl'), Label(label='The Chestnut', language_id='en'), Label(label='la châtaigne', language_id='fr')] a_concept.labels = a_labels b_concept = Concept(concept_id=9863, conceptscheme_id=1, type='concept') b_labels = [Label(label='test', language_id='nl')] b_concept.labels = b_labels all_mock = Mock(return_value=[a_concept, b_concept]) return all_mock
def test_sort_precedes_pref(self): label = self._get_fut() from skosprovider_sqlalchemy.models import Label khnl = Label('Knokke-Heist', "prefLabel", 'nl') chnl = Label('Cnock-Heyst', "altLabel", 'nl') khen = Label('Knocke-Heyst', "prefLabel", 'en') khensort = Label('123MeFirst', "sortLabel", 'en') khnlbe = self._get_knokke_heist_nl() chnlbe = self._get_cnocke_heyst_nl() khengb = self._get_knokke_heist_en() labels = [chnl, khen, khnlbe, khnl, chnlbe, khengb, khensort] assert khensort == label(labels, 'en', True) assert khensort == label(labels, 'en-GB', True)
def test_exact_precedes_inexact_match(self): label = self._get_fut() from skosprovider_sqlalchemy.models import Label khnl = Label('Knokke-Heist', "prefLabel", 'nl') chnl = Label('Cnock-Heyst', "altLabel", 'nl') khen = Label('Knocke-Heyst', "prefLabel", 'en') khnlbe = self._get_knokke_heist_nl() chnlbe = self._get_cnocke_heyst_nl() khengb = self._get_knokke_heist_en() labels = [chnl, khen, khnlbe, khnl, chnlbe, khengb] assert khnlbe == label(labels, 'nl-BE') assert khnl == label(labels, 'nl') assert label(labels, 'en-US') in [khen, khengb]
def test_update_last_visited_concepts(self): c = Concept() c.id = 2 c.labels = [Label('test', language_id='en-us')] update_last_visited_concepts(self.request, { 'label': c.label(), 'url': 'http://test.test/{0}'.format(55) }) c = Concept() c.id = 33 c.labels = [Label('test', language_id='nl-be')] update_last_visited_concepts(self.request, { 'label': c.label(), 'url': 'http://test.test/{0}'.format(2) }) self.assertEqual(2, len(self.request.session['last_visited']))
def map_conceptscheme(conceptscheme, conceptscheme_json): """ Map a conceptscheme from json to the database. :param skosprovider_sqlalchemy.models.ConceptScheme conceptscheme: A conceptscheme as known to the database. :param dict conceptscheme_json: A dict representing the json sent to our REST service. :returns: The :class:`skosprovider_sqlalchemy.models.ConceptScheme` enhanced with the information from the json object. """ conceptscheme.labels[:] = [] labels = conceptscheme_json.get('labels', []) for l in labels: label = Label(label=l.get('label', ''), labeltype_id=l.get('type', ''), language_id=l.get('language', '')) conceptscheme.labels.append(label) conceptscheme.notes[:] = [] notes = conceptscheme_json.get('notes', []) for n in notes: note = Note(note=n.get('note', ''), notetype_id=n.get('type', ''), language_id=n.get('language', '')) conceptscheme.notes.append(note) conceptscheme.sources[:] = [] sources = conceptscheme_json.get('sources', []) for s in sources: source = Source(citation=s.get('citation', '')) conceptscheme.sources.append(source) return conceptscheme
def _get_concept(self): from skosprovider_sqlalchemy.models import Concept, Label return Concept( id=2, concept_id=456, labels=[Label('Cathedrals', 'prefLabel', 'en')] )
def create_conceptscheme(conceptscheme_label, conceptscheme_uri): """ configure output conceptscheme """ cs = ConceptScheme(uri=conceptscheme_uri) l = Label(conceptscheme_label, 'prefLabel', 'und') cs.labels.append(l) return cs
def filter_by_mock_concept(**kwargs): filter_mock = Mock() concept_id = None conceptscheme_id = None if 'concept_id' in kwargs: concept_id = kwargs['concept_id'] if 'conceptscheme_id' in kwargs: conceptscheme_id = kwargs['conceptscheme_id'] if concept_id == '1': c = Concept(concept_id=concept_id, conceptscheme_id=conceptscheme_id) c.type = 'concept' label_mock = Mock() label_mock.label = 'test' c.label = Mock(return_value=label_mock) filter_mock.one = Mock(return_value=c) elif concept_id == '3': c = Collection(concept_id=concept_id, conceptscheme_id=conceptscheme_id) c.type = 'collection' label_mock = Mock() label_mock.label = 'test' c.label = Mock(return_value=label_mock) filter_mock.one = Mock(return_value=c) elif concept_id == '555': c = Thing(concept_id=concept_id, conceptscheme_id=conceptscheme_id) filter_mock.one = Mock(return_value=c) elif concept_id == '666': raise NoResultFound a_concept = Concept(concept_id=7895, conceptscheme_id=conceptscheme_id, type='concept') a_labels = [ Label(label='De Paardekastanje', language_id='nl'), Label(label='The Chestnut', language_id='en'), Label(label='la châtaigne', language_id='fr') ] a_concept.labels = a_labels b_concept = Concept(concept_id=9863, conceptscheme_id=conceptscheme_id, type='concept') b_labels = [Label(label='test', language_id='nl')] b_concept.labels = b_labels filter_mock.all = Mock(return_value=[a_concept, b_concept]) return filter_mock
def test_simple(self): from skosprovider_sqlalchemy.models import Label l = Label('Churches by function', 'prefLabel', 'en') c = self._get_target_class()( id=1, concept_id=253, labels=[l] ) self.assertEqual(1, c.id) self.assertEqual(l, c.label())
def test_mapping_collections_filled(self): label = Label(label='test', labeltype_id='altLabel', language_id='nl') self.concept.labels.append(label) related_concept = Concept(concept_id=6, conceptscheme_id=1) self.concept.related_concepts.add(related_concept) result_concept = map_concept(self.concept, test_json, self.request.db) self.assertEqual(3, len(result_concept.narrower_concepts)) self.assertEqual(2, len(result_concept.broader_concepts)) self.assertEqual(2, len(result_concept.related_concepts)) self.assertEqual(1, len(result_concept.member_of)) self.assertEqual(2, len(result_concept.labels)) self.assertEqual(1, len(result_concept.notes))
def test_update_last_visited_concepts_max(self): for id in range(50): c = Concept() c.id = id c.labels = [Label('test', language_id='en-us')] update_last_visited_concepts( self.request, { 'label': c.label(), 'url': 'http://test.test/{0}'.format(id) }) self.assertEqual(4, len(self.request.session['last_visited'])) last = self.request.session['last_visited'].pop() self.assertEqual('http://test.test/49', last['url'])
def test_simple(self): from skosprovider_sqlalchemy.models import Label, Source l = Label('Churches', 'prefLabel', 'en') s = Source('Carlisle, P. 2014.') c = self._get_target_class()( id=1, concept_id=1, labels=[l], sources=[s] ) assert 1 == c.id assert l == c.label() assert s in c.sources assert 'Concept-1' == str(c)
def test_simple(self): from skosprovider_sqlalchemy.models import Label, Language, Source l = Label('Heritage types', 'prefLabel', 'en') en = Language('en', 'English') s = Source('Carlisle, P. 2014.') c = self._get_target_class()( id=1, labels=[l], languages=[en], sources=[s] ) assert 1 == c.id assert l == c.label() assert 1 == len(c.languages) assert en in c.languages assert s in c.sources assert 'ConceptScheme-1' == str(c)
def test_mapping_collections_filled(self): label = Label(label='test', labeltype_id='altLabel', language_id='nl') self.concept.labels.append(label) related_concept = Concept(concept_id=6, conceptscheme_id=1) self.concept.related_concepts.add(related_concept) source = Source(citation='testCitation') self.concept.sources.append(source) source = Source(citation='AnotherTestCitation') self.concept.sources.append(source) result_concept = map_concept(self.concept, test_json, self.skos_manager) self.assertEqual(3, len(result_concept.narrower_concepts)) self.assertEqual(2, len(result_concept.broader_concepts)) self.assertEqual(2, len(result_concept.related_concepts)) self.assertEqual(1, len(result_concept.member_of)) self.assertEqual(2, len(result_concept.labels)) self.assertEqual(1, len(result_concept.notes)) self.assertEqual(1, len(result_concept.sources))
def map_concept(concept, concept_json, skos_manager): """ Map a concept from json to the database. :param skosprovider_sqlalchemy.models.Thing concept: A concept or collection as known to the database. :param dict concept_json: A dict representing the json sent to our REST service. :param skos_manager: A skos_manager to acces db operations :returns: The :class:`skosprovider_sqlalchemy.models.Thing` enhanced with the information from the json object. """ concept_json_type = concept_json.get('type', None) if concept.type != concept_json_type: if concept_json_type == 'concept': members = concept.members concept = skos_manager.change_type(concept, concept.concept_id, concept.conceptscheme_id, concept_json_type) for member in members: if member.type == 'concept': concept.narrower_concepts.add(member) elif member.type == 'collection': concept.narrower_collections.add(member) elif concept_json_type == 'collection': narrower_concepts = concept.narrower_concepts narrower_collections = concept.narrower_collections concept = skos_manager.change_type(concept, concept.concept_id, concept.conceptscheme_id, concept_json_type) for narrower_concept in narrower_concepts: concept.members.add(narrower_concept) for narrower_collection in narrower_collections: concept.members.add(narrower_collection) elif concept_json_type == 'collection': concept.members.clear() elif concept_json_type == 'concept': concept.narrower_collections.clear() concept.narrower_concepts.clear() if concept.type in ('concept', 'collection'): concept.labels[:] = [] labels = concept_json.get('labels', []) for l in labels: label = Label(label=l.get('label', ''), labeltype_id=l.get('type', ''), language_id=l.get('language', '')) concept.labels.append(label) concept.notes[:] = [] notes = concept_json.get('notes', []) for n in notes: note = Note(note=n.get('note', ''), notetype_id=n.get('type', ''), language_id=n.get('language', '')) if is_html(note.note): note.markup = 'HTML' concept.notes.append(note) concept.sources[:] = [] sources = concept_json.get('sources', []) for s in sources: source = Source(citation=s.get('citation', '')) if is_html(source.citation): source.markup = 'HTML' concept.sources.append(source) concept.member_of.clear() member_of = concept_json.get('member_of', []) for memberof in member_of: try: memberof_collection = skos_manager.get_thing( concept_id=memberof['id'], conceptscheme_id=concept.conceptscheme_id) except NoResultFound: memberof_collection = Collection(concept_id=memberof['id'], conceptscheme_id=concept.conceptscheme_id) concept.member_of.add(memberof_collection) if concept.type == 'concept': concept.related_concepts.clear() related = concept_json.get('related', []) for related in related: try: related_concept = skos_manager.get_thing( concept_id=related['id'], conceptscheme_id=concept.conceptscheme_id) except NoResultFound: related_concept = Concept(concept_id=related['id'], conceptscheme_id=concept.conceptscheme_id) concept.related_concepts.add(related_concept) concept.broader_concepts.clear() broader = concept_json.get('broader', []) for broader in broader: try: broader_concept = skos_manager.get_thing( concept_id=broader['id'], conceptscheme_id=concept.conceptscheme_id) except NoResultFound: broader_concept = Concept(concept_id=broader['id'], conceptscheme_id=concept.conceptscheme_id) concept.broader_concepts.add(broader_concept) narrower = concept_json.get('narrower', []) for narrower in narrower: try: narrower_concept = skos_manager.get_thing( concept_id=narrower['id'], conceptscheme_id=concept.conceptscheme_id) except NoResultFound: narrower_concept = Concept(concept_id=narrower['id'], conceptscheme_id=concept.conceptscheme_id) concept.narrower_concepts.add(narrower_concept) matches = [] matchdict = concept_json.get('matches', {}) for type in matchdict: db_type = type + "Match" matchtype = skos_manager.get_match_type(db_type) for uri in matchdict[type]: concept_id = concept_json.get('id', -1) try: match = skos_manager.get_match(uri=uri, matchtype_id=matchtype.name, concept_id=concept_id) except NoResultFound: match = Match() match.matchtype = matchtype match.uri = uri matches.append(match) concept.matches = matches narrower_collections = concept_json.get('subordinate_arrays', []) for narrower in narrower_collections: try: narrower_collection = skos_manager.get_thing( concept_id=narrower['id'], conceptscheme_id=concept.conceptscheme_id) except NoResultFound: narrower_collection = Collection(concept_id=narrower['id'], conceptscheme_id=concept.conceptscheme_id) concept.narrower_collections.add(narrower_collection) if concept.type == 'collection': members = concept_json.get('members', []) for member in members: try: member_concept = skos_manager.get_thing( concept_id=member['id'], conceptscheme_id=concept.conceptscheme_id) except NoResultFound: member_concept = Concept(concept_id=member['id'], conceptscheme_id=concept.conceptscheme_id) concept.members.add(member_concept) concept.broader_concepts.clear() broader_concepts = concept_json.get('superordinates', []) for broader in broader_concepts: try: broader_concept = skos_manager.get_thing( concept_id=broader['id'], conceptscheme_id=concept.conceptscheme_id) except NoResultFound: broader_concept = Concept(concept_id=broader['id'], conceptscheme_id=concept.conceptscheme_id) concept.broader_concepts.add(broader_concept) return concept
def _get_knokke_heist_nl(self): from skosprovider_sqlalchemy.models import Label return Label('Knokke-Heist', "prefLabel", 'nl-BE')
def _get_cnocke_heyst_nl(self): from skosprovider_sqlalchemy.models import Label return Label('Cnock-Heyst', "altLabel", 'nl-BE')
def create_data(session): from skosprovider_sqlalchemy.models import (Concept, ConceptScheme, Collection, Label, Note, Match, Language) en = session.query(Language).get('en') nl = session.query(Language).get('nl') cs = ConceptScheme(id=1, uri='urn:x-skosprovider:test', languages=[en, nl]) session.add(cs) con = Concept(id=10, uri='urn:x-skosprovider:test:1', concept_id=1, conceptscheme=cs) session.add(con) l = Label('Churches', 'prefLabel', 'en') con.labels.append(l) l = Label('Kerken', 'prefLabel', 'nl') con.labels.append(l) col = Collection(id=20, uri='urn:x-skosprovider:test:2', concept_id=2, conceptscheme=cs) col.broader_concepts.add(con) n = Note( 'Churches organised by function, as opposed to by shape or religion.', 'scopeNote', 'en') col.notes.append(n) l = Label('Churches by function', 'prefLabel', 'en') col.labels.append(l) l = Label('111sortmefirst', 'sortLabel', 'en') col.labels.append(l) session.add(col) chap = Concept(id=30, uri='urn:x-skosprovider:test:3', concept_id=3, conceptscheme=cs) l = Label('Chapels', 'prefLabel', 'en') chap.labels.append(l) session.add(chap) chap.related_concepts.add(con) tchap = Concept(id=50, uri='urn:x-skosprovider:test:5', concept_id=5, conceptscheme=cs) tchap.labels.append(Label('Boomkapellen', 'prefLabel', 'nl')) session.add(tchap) tchap.broader_concepts.add(chap) cath = Concept(id=40, uri='urn:x-skosprovider:test:4', concept_id=4, conceptscheme=cs) l = Label('Cathedrals', 'prefLabel', 'en') cath.labels.append(l) n = Note('A cathedral is a church which contains the seat of a bishop.', 'definition', 'en') cath.notes.append(n) session.add(cath) cath.broader_concepts.add(con) cath.member_of.add(col) match = Match(matchtype_id='closeMatch', uri='http://vocab.getty.edu/aat/300007501') cath.matches.append(match) session.commit()
def _get_knokke_heist_en(self): from skosprovider_sqlalchemy.models import Label return Label('Knocke-Heyst', "prefLabel", 'en-GB')
def map_concept(concept, concept_json, db_session): ''' Map a concept from json to the database. :param skosprovider_sqlalchemy.models.Thing concept: A concept or collection as known to the database. :param dict concept_json: A dict representing the json sent to our REST service. :param session: A :class:`sqlalchemy.orm.session.Session`. :returns: The :class:`skosprovider_sqlalchemy.models.Thing` enhanced with the information from the json object. ''' concept.type = concept_json.get('type', None) if concept.type in ('concept', 'collection'): for label in concept.labels: concept.labels.remove(label) labels = concept_json.get('labels', []) for l in labels: label = Label(label=l.get('label', ''), labeltype_id=l.get('type', ''), language_id=l.get('language', '')) concept.labels.append(label) for note in concept.notes: concept.notes.remove(note) notes = concept_json.get('notes', []) for n in notes: note = Note(note=n.get('note', ''), notetype_id=n.get('type', ''), language_id=n.get('language', '')) concept.notes.append(note) concept.member_of.clear() member_of = concept_json.get('member_of', []) for memberof in member_of: try: memberof_collection = db_session.query(Collection)\ .filter_by(concept_id=memberof['id'], conceptscheme_id=concept.conceptscheme_id).one() except NoResultFound: memberof_collection = Collection( concept_id=memberof['id'], conceptscheme_id=concept.conceptscheme_id) concept.member_of.add(memberof_collection) if concept.type == 'concept': concept.related_concepts.clear() related = concept_json.get('related', []) for related in related: try: related_concept = db_session.query(Concept).filter_by( concept_id=related['id'], conceptscheme_id=concept.conceptscheme_id).one() except NoResultFound: related_concept = Concept( concept_id=related['id'], conceptscheme_id=concept.conceptscheme_id) concept.related_concepts.add(related_concept) concept.narrower_concepts.clear() concept.broader_concepts.clear() broader = concept_json.get('broader', []) for broader in broader: try: broader_concept = db_session.query(Concept).filter_by( concept_id=broader['id'], conceptscheme_id=concept.conceptscheme_id).one() except NoResultFound: broader_concept = Concept( concept_id=broader['id'], conceptscheme_id=concept.conceptscheme_id) concept.broader_concepts.add(broader_concept) narrower = concept_json.get('narrower', []) for narrower in narrower: try: narrower_concept = db_session.query(Concept).filter_by( concept_id=narrower['id'], conceptscheme_id=concept.conceptscheme_id).one() except NoResultFound: narrower_concept = Concept( concept_id=narrower['id'], conceptscheme_id=concept.conceptscheme_id) concept.narrower_concepts.add(narrower_concept) matches = [] matchdict = concept_json.get('matches', {}) for type in matchdict: db_type = type + "Match" matchtype = db_session.query(MatchType).filter_by( name=db_type).one() for uri in matchdict[type]: concept_id = concept_json.get('id', -1) try: match = db_session.query(Match).filter_by( uri=uri, matchtype_id=matchtype.name, concept_id=concept_id).one() except NoResultFound: match = Match() match.matchtype = matchtype match.uri = uri matches.append(match) concept.matches = matches concept.narrower_collections.clear() narrower_collections = concept_json.get('subordinate_arrays', []) for narrower in narrower_collections: try: narrower_collection = db_session.query(Collection)\ .filter_by(concept_id=narrower['id'], conceptscheme_id=concept.conceptscheme_id).one() except NoResultFound: narrower_collection = Collection( concept_id=narrower['id'], conceptscheme_id=concept.conceptscheme_id) concept.narrower_collections.add(narrower_collection) if concept.type == 'collection': concept.members.clear() members = concept_json.get('members', []) for member in members: try: member_concept = db_session.query(Thing).filter_by( concept_id=member['id'], conceptscheme_id=concept.conceptscheme_id).one() except NoResultFound: member_concept = Concept( concept_id=member['id'], conceptscheme_id=concept.conceptscheme_id) concept.members.add(member_concept) concept.broader_concepts.clear() broader_concepts = concept_json.get('superordinates', []) for broader in broader_concepts: try: broader_concept = db_session.query(Concept)\ .filter_by(concept_id=broader['id'], conceptscheme_id=concept.conceptscheme_id).one() except NoResultFound: broader_concept = Concept( concept_id=broader['id'], conceptscheme_id=concept.conceptscheme_id) concept.broader_concepts.add(broader_concept) return concept
def main(argv=sys.argv): from fixtures.data import trees, geo from fixtures.styles_and_cultures import styles_and_cultures from fixtures.materials import materials from fixtures.eventtypes import eventtypes from fixtures.heritagetypes import heritagetypes from fixtures.periods import periods from fixtures.species import species if len(argv) < 2: usage(argv) config_uri = argv[1] options = parse_vars(argv[2:]) setup_logging(config_uri) settings = get_appsettings(config_uri, options=options) engine = engine_from_config(settings, 'sqlalchemy.') session_maker = sessionmaker(bind=engine, extension=ZopeTransactionExtension()) db_session = session_maker() with transaction.manager: import_provider( trees, ConceptScheme(id=1, uri='urn:x-skosprovider:trees', labels=[ Label('Verschillende soorten bomen', u'prefLabel', u'nl'), Label('Different types of trees', u'prefLabel', u'en') ]), db_session) import_provider( geo, ConceptScheme(id=2, uri='urn:x-skosprovider:geo', labels=[ Label('Geografie', u'prefLabel', u'nl'), Label('Geography', u'prefLabel', u'en') ]), db_session) import_provider( styles_and_cultures, ConceptScheme( id=3, uri='https://id.erfgoed.net/thesauri/stijlen_en_culturen', labels=[ Label('Stijlen en Culturen', u'prefLabel', u'nl'), Label('Styles and Cultures', u'prefLabel', u'en') ]), db_session) import_provider( materials, ConceptScheme(id=4, uri='https://id.erfgoed.net/thesauri/materialen', labels=[ Label('Materialen', u'prefLabel', u'nl'), Label('Materials', u'prefLabel', u'en') ]), db_session) import_provider( eventtypes, ConceptScheme( id=5, uri='https://id.erfgoed.net/thesauri/gebeurtenistypes', labels=[ Label('Gebeurtenistypes', u'prefLabel', u'nl'), Label('Event types', u'prefLabel', u'en') ]), db_session) import_provider( heritagetypes, ConceptScheme(id=6, uri='https://id.erfgoed.net/thesauri/erfgoedtypes', labels=[ Label('Erfgoedtypes', u'prefLabel', u'nl'), Label('Heritage types', u'prefLabel', u'en') ]), db_session) import_provider( periods, ConceptScheme(id=7, uri='https://id.erfgoed.net/thesauri/dateringen', labels=[ Label('Dateringen', u'prefLabel', u'nl'), Label('Periods', u'prefLabel', u'en') ]), db_session) import_provider( species, ConceptScheme(id=8, uri='https://id.erfgoed.net/thesauri/soorten', labels=[ Label('Soorten', u'prefLabel', u'nl'), Label('Species', u'prefLabel', u'en') ]), db_session) print('--atramhasis-db-initialized--')
def setUp(self): self.concept = Concept() self.concept.type = 'concept' self.concept.id = 11 self.concept.concept_id = 101 self.concept.uri = 'urn:x-atramhasis-demo:TREES:101' self.concept.conceptscheme_id = 1 notes = [] note = Note(note='test note', notetype_id='example', language_id='en') note2 = Note(note='note def', notetype_id='definition', language_id='en') notes.append(note) notes.append(note2) self.concept.notes = notes labels = [] label = Label(label='een label', labeltype_id='prefLabel', language_id='nl') label2 = Label(label='other label', labeltype_id='altLabel', language_id='en') label3 = Label(label='and some other label', labeltype_id='altLabel', language_id='en') labels.append(label) labels.append(label2) labels.append(label3) self.concept.labels = labels sources = [] source = Source('Van Daele K. 2009') sources.append(source) self.concept.sources = sources matches = [] match = Match() match.matchtype = MatchType(name='closeMatch', description='test') match.uri = 'urn:somethingelse:st1' matches.append(match) match2 = Match() match2.matchtype = MatchType(name='closeMatch', description='test') match2.uri = 'urn:somethingelse:st2' matches.append(match2) match3 = Match() match3.matchtype = MatchType(name='exactMatch', description='test') match3.uri = 'urn:something:thingy' matches.append(match3) self.concept.matches = matches self.collection = Collection() self.collection.type = 'collection' self.collection.id = 12 self.collection.concept_id = 102 self.collection.uri = 'urn:x-atramhasis-demo:TREES:102' self.collection.conceptscheme_id = 1 self.conceptscheme = ConceptScheme() self.conceptscheme.id = 1 self.conceptscheme.labels = labels self.conceptscheme.notes = notes self.conceptscheme.sources = sources self.conceptscheme.uri = None self.regis = Registry() self.regis.register_provider(trees) self.request = testing.DummyRequest() self.request.skos_registry = self.regis self.request.matchdict = {'scheme_id': 'TREES'} self.request.locale_name = 'nl' self.concept.member_of.add(self.collection) self.collection.members.add(self.concept)