Example #1
0
def filter_by_mock_conceptscheme(**kwargs):
    filter_mock = Mock()
    concept_scheme = ConceptScheme()
    concept_scheme.id = 1
    concept_scheme.uri = "urn:test:test"
    filter_mock.one = Mock(return_value=concept_scheme)
    return filter_mock
Example #2
0
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
    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'),
                        db_session)
        import_provider(geo, ConceptScheme(id=2, uri='urn:x-skosprovider:geo'),
                        db_session)
        import_provider(styles_and_cultures,
                        ConceptScheme(id=3, uri='urn:x-vioe:styles'),
                        db_session)
        import_provider(materials,
                        ConceptScheme(id=4, uri='urn:x-vioe:materials'),
                        db_session)
    print('--atramhasis-db-initialized--')
Example #3
0
def filter_by_mock_conceptscheme(**kwargs):
    filter_mock = Mock()
    concept_scheme = ConceptScheme()
    concept_scheme.id = 1
    concept_scheme.uri = "urn:test:test"
    filter_mock.one = Mock(return_value=concept_scheme)
    return filter_mock
Example #4
0
    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):
        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

        sources = []
        source = Source(citation='Kinsella S. & Carlisle P. 2015: Alice.')
        sources.append(source)
        self.concept.sources = sources

        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):
        settings['sqlalchemy.url'] = 'sqlite:///%s/dbtest.sqlite' % here
        self.engine = engine_from_config(settings, prefix='sqlalchemy.')
        Base.metadata.drop_all(self.engine)
        Base.metadata.create_all(self.engine)

        session_maker = sessionmaker(
            bind=self.engine,
            extension=ZopeTransactionExtension()
        )

        with transaction.manager:
            local_session = 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, uri='urn:x-vioe:geo'), local_session)
            import_provider(styles_and_cultures, ConceptScheme(id=3, uri='urn:x-vioe:styles'), local_session)
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
Example #8
0
    def setUp(self):
        self.engine = engine_from_config(settings, 'sqlalchemy.')
        Base.metadata.bind = self.engine
        SkosBase.metadata.bind = self.engine
        session_maker = sessionmaker(
            bind=self.engine,
        )
        SkosBase.metadata.drop_all(self.engine)
        SkosBase.metadata.create_all(self.engine)
        self.config = testing.setUp()
        self.config.registry.dbmaker = session_maker

        with transaction.manager:
            local_session = 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, uri='urn:x-vioe:geo'), local_session)
            import_provider(styles_and_cultures, ConceptScheme(id=3, uri='urn:x-vioe:styles'), local_session)
    def setUp(self):
        Base.metadata.drop_all(self.engine)
        Base.metadata.create_all(self.engine)
        Base.metadata.bind = self.engine
        VisitLogBase.metadata.drop_all(self.engine)
        VisitLogBase.metadata.create_all(self.engine)
        VisitLogBase.metadata.bind = self.engine

        with transaction.manager:
            local_session = self.session_maker()
            local_session.add(Language('nl', 'Dutch'))
            local_session.add(Language('nl-BE', 'Dutch'))
            local_session.add(Language('en', 'English'))

            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, uri='urn:x-vioe:geo'), local_session)
            local_session.add(ConceptScheme(id=3, uri='urn:x-vioe:test'))
            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(MatchType('broadMatch', ''))
            local_session.add(MatchType('closeMatch', ''))
            local_session.add(MatchType('exactMatch', ''))
            local_session.add(MatchType('narrowMatch', ''))
            local_session.add(MatchType('relatedMatch', ''))

            local_session.flush()

            match = Match()
            match.matchtype_id = 'narrowMatch'
            match.uri = 'urn:test'
            match.concept_id = 1
            local_session.add(match)

            local_session.add(ConceptVisitLog(concept_id=1, conceptscheme_id=1, origin='REST',
                                              visited_at=datetime(2015, 8, 27, 10, 58, 3)))
            local_session.add(ConceptVisitLog(concept_id=1, conceptscheme_id=1, origin='REST',
                                              visited_at=datetime(2015, 8, 27, 11, 58, 3)))
            local_session.add(ConceptVisitLog(concept_id=2, conceptscheme_id=1, origin='REST',
                                              visited_at=datetime(2015, 8, 27, 10, 58, 3)))
            local_session.add(ConceptVisitLog(concept_id=2, conceptscheme_id=2, origin='REST',
                                              visited_at=datetime(2015, 8, 27, 10, 58, 3)))
Example #10
0
 def add_conceptscheme_view(self):
     if 'user' not in self.request.session:
         return HTTPFound(self.request.route_path('login'))
     if 'scheme_name' in self.request.POST:
         cscheme = ConceptScheme(uri=self.request.POST['scheme_uri'])
         self.conceptscheme_manager.session.add(cscheme)
         command = 'touch atramhasis/__init__.py'
         os.system(command)
         return {'success': True}
     else:
         # TODO: return template
         return {}
 def setUp(self):
     self.skos_manager = SkosManager(session_maker())
     self.concept = Concept()
     self.concept.concept_id = 1
     self.concept.conceptscheme_id = 1
     self.collection = Collection()
     self.collection.concept_id = 0
     self.collection.conceptscheme_id = 1
     self.conceptscheme = ConceptScheme()
     self.conceptscheme.id = 1
     member_concept_1 = Concept()
     member_concept_1.concept_id = 5
     member_concept_1.conceptscheme_id = 1
     member_concept_2 = Collection()
     member_concept_2.concept_id = 6
     member_concept_2.conceptscheme_id = 1
     self.collection.members.add(member_concept_1)
     self.collection.members.add(member_concept_2)
     self.concept.narrower_concepts.add(member_concept_1)
     self.concept.narrower_collections.add(member_concept_2)
Example #12
0
 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'
Example #13
0
    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)
Example #14
0
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 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)