예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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'
     }])
예제 #4
0
 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"}), [])
예제 #5
0
 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
예제 #6
0
 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'}), [])
예제 #7
0
    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
예제 #8
0
 def test_get_all_default_language(self):
     trees = DictionaryProvider(
         {'id': 'TREES'},
         [larch]
     )
     self.assertEquals(
         trees.get_all(),
         [
             {
                 'id': '1',
                 'uri': 'http://id.trees.org/1',
                 'type': 'concept',
                 'label': 'The Larch'
             }
         ]
     )
예제 #9
0
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
예제 #10
0
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
예제 #11
0
    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)
예제 #12
0
    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
예제 #13
0
 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)
예제 #14
0
 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
예제 #15
0
 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')
예제 #16
0
 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'}),
         []
     )
예제 #17
0
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)
예제 #18
0
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
예제 #19
0
    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)
예제 #20
0
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
예제 #21
0
        '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')
                               ]))
예제 #22
0
        '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'
예제 #23
0
파일: api.py 프로젝트: leonqli/skosprovider
    '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'))
예제 #25
0
 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
예제 #26
0
 def _get_tree_provider(self, dictionary):
     return DictionaryProvider({'id': 'TEST'}, dictionary)
예제 #27
0
    '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]
}
예제 #28
0
        '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']
예제 #29
0
 def test_get_all_default_language(self):
     trees = DictionaryProvider({"id": "TREES"}, [larch])
     self.assertEquals(trees.get_all(), [{"id": "1", "label": "The Larch"}])
예제 #30
0
 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)
예제 #31
0
 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')
예제 #32
0
 def test_override_instance_scopes(self):
     trees = DictionaryProvider({'id': 'TREES'}, [larch],
                                allowed_instance_scopes=['single'])
     assert trees.allowed_instance_scopes == ['single']
예제 #33
0
    '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'))
예제 #34
0
# -*- 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'))
예제 #35
0
 def test_get_all_default_language(self):
     trees = DictionaryProvider({"id": "TREES"}, [larch])
     self.assertEquals(
         trees.get_all(), [{"id": "1", "uri": "http://id.trees.org/1", "type": "concept", "label": "The Larch"}]
     )
예제 #36
0
    "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')
예제 #37
0
# -*- 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'))