示例#1
0
def load_themes():
    vocab_file_path = _get_path('data-theme-skos.rdf', 'vocabularies')

    class Opts(object):
        def __init__(self, filename, name, format):
            self.filename = filename
            self.url = None  #filename
            self.name = name
            self.format = format

    themes_loader.options = Opts(vocab_file_path, 'eu_themes', None)
    themes_loader.load()

    tag_localized = interfaces.get_localized_tag_name('ECON')
    Session.flush()
    assert tag_localized
    q = Session.query(Vocabulary).filter_by(name='eu_themes')
    vocab = q.first()
    assert vocab

    map_f = _get_path(MAPPING_FILE)
    voc_f = _get_path(EUROVOC_FILE)
    clear_subthemes()
    load_subthemes(map_f, voc_f)
    assert Subtheme.q().first()
示例#2
0
    def load(self):
        ##
        # Checking command given options
        ##

        url = self.options.url
        filename = self.options.filename
        format = self.options.format

        if not url and not filename:
            print "ERROR: No URL or FILENAME provided and one is required"
            print self.usage
            return

        vocab_name = self.options.name

        if not vocab_name:
            print "ERROR: No vocabulary name provided and is required"
            print self.usage
            return

        if vocab_name not in self._controlled_vocabularies_allowed:
            print "ERROR: Incorrect vocabulary name, only one of these values are allowed: {0}".format(
                self._controlled_vocabularies_allowed)
            print self.usage
            return

        if vocab_name == LICENSES_NAME:
            clear_licenses()
            load_licenses_from_graph(filename, url)
            Session.commit()
            return

        if vocab_name == SUBTHEME_NAME:
            clear_subthemes()
            theme_map = self.options.filename
            try:
                eurovoc = self.args[-1]
            except IndexError:
                print "ERROR: Missing eurovoc file"
                print self.usage
                return
            load_subthemes(theme_map, eurovoc)
            Session.commit()
            return

        do_load(vocab_name, url=url, filename=filename, format=format)
示例#3
0
    def test_subthemes(self):
        clear_subthemes()
        g = Graph()
        g.parse(self.map_f)

        refs = list(g.objects(None, SKOS.narrowMatch))
        self.assertTrue(len(refs)> 0)

        load_subthemes(self.map_f, self.voc_f)
        all_subthemes = Subtheme.q()
        self.assertTrue(all_subthemes.count()> 0)
        for ref in refs:
            try:
                subtheme = Subtheme.q().filter_by(uri=str(ref)).one()
                self.assertIsNotNone(subtheme)
            except Exception, err:
                self.assertIsNone(err, "No results for {}: {}".format(ref, err))