Esempio n. 1
0
class SubthemeTestCase(unittest.TestCase):
    MAPPING_FILE = 'eurovoc_mapping.rdf'
    EUROVOC_FILE = 'eurovoc.rdf'

    def setUp(self):
        self._load_mapping()

    def _load_mapping(self):
        self.map_f = get_path(self.MAPPING_FILE)
        self.voc_f = get_path(self.EUROVOC_FILE)

    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))
        themes = g.subjects(RDF.type, SKOS.Concept)
        for theme in themes:
            theme_len = g.objects(theme, SKOS.narrowMatch)
            theme_name = Subtheme.normalize_theme(theme)
            q = Subtheme.for_theme(theme_name)
            self.assertTrue(q.count() >= len(list(theme_len)))
    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.assertGreater(all_subthemes.count(), 0)
        for ref in refs:
            try:
                subtheme = Subtheme.q().filter_by(uri=str(ref)).one()
                self.assertIsNotNone(subtheme)
            except Exception as err:
                self.fail(f'No results for {ref}: {err}')
        themes = g.subjects(RDF.type, SKOS.Concept)
        for theme in themes:
            theme_len = g.objects(theme, SKOS.narrowMatch)
            theme_name = Subtheme.normalize_theme(theme)
            q = Subtheme.for_theme(theme_name)
            self.assertGreaterEqual(q.count(), len(list(theme_len)))