Exemplo n.º 1
0
 def setUp(self):
     from skosprovider.uri import UriPatternGenerator
     self.ifile = open(
         os.path.join(os.path.dirname(__file__), 'data', 'menu.csv'), "r")
     reader = csv.reader(self.ifile)
     self.csvprovider = SimpleCsvProvider(
         {'id': 'MENU'},
         reader,
         uri_generator=UriPatternGenerator('http://id.python.org/menu/%s'),
         concept_scheme=ConceptScheme('http://id.python.org/menu'))
Exemplo n.º 2
0
    def setUp(self):
        from skosprovider.uri import UriPatternGenerator

        self.ifile = open(os.path.join(os.path.dirname(__file__), "data", "menu.csv"), "r")
        reader = csv.reader(self.ifile)
        self.csvprovider = SimpleCsvProvider(
            {"id": "MENU"}, reader, uri_generator=UriPatternGenerator("http://id.python.org/menu/%s")
        )
Exemplo n.º 3
0
class SimpleCsvProviderTests(unittest.TestCase):

    def setUp(self):
        from skosprovider.uri import UriPatternGenerator
        self.ifile = open(
            os.path.join(os.path.dirname(__file__), 'data', 'menu.csv'),
            "r"
        )
        reader = csv.reader(self.ifile)
        self.csvprovider = SimpleCsvProvider(
            {'id': 'MENU'},
            reader,
            uri_generator=UriPatternGenerator('http://id.python.org/menu/%s'),
            concept_scheme=ConceptScheme('http://id.python.org/menu')
        )

    def tearDown(self):
        self.ifile.close()
        del self.csvprovider

    def testCount(self):
        self.assertEqual(11, len(self.csvprovider.get_all()))

    def testGetEggAndBacon(self):
        eb = self.csvprovider.get_by_id(1)
        self.assertIsInstance(eb, Concept)
        self.assertEqual('1', eb.id)
        self.assertEqual('http://id.python.org/menu/1', eb.uri)
        self.assertEqual('Egg and Bacon', eb.label().label)
        self.assertEqual('prefLabel', eb.label().type)
        self.assertEqual([], eb.notes)
        assert 1 == len(eb.sources)

    def testGetEggAndSpamByUri(self):
        eb = self.csvprovider.get_by_uri('http://id.python.org/menu/3')
        self.assertIsInstance(eb, Concept)
        self.assertEqual('3', eb.id)
        self.assertEqual('http://id.python.org/menu/3', eb.uri)

    def testFindSpam(self):
        spam = self.csvprovider.find({'label': 'Spam'})
        self.assertEqual(8, len(spam))

    def testGetLobster(self):
        eb = self.csvprovider.get_by_id(11)
        self.assertIsInstance(eb, Concept)
        self.assertEqual('11', eb.id)
        self.assertEqual('Lobster Thermidor', eb.label().label)
        self.assertIsInstance(eb.notes[0], Note)
        self.assertIn('Mornay', eb.notes[0].note)
        self.assertEqual('note', eb.notes[0].type)

    def testFindSausageCaseInsensitive(self):
        sausages = self.csvprovider.find({'label': 'sausage'})
        self.assertEqual(4, len(sausages))

    def testFindSausageCaseSensitive(self):
        self.csvprovider.case_insensitive = False
        sausages = self.csvprovider.find({'label': 'Sausage'})
        self.assertEqual(1, len(sausages))
Exemplo n.º 4
0
def _get_menu():
    from skosprovider.providers import (SimpleCsvProvider)

    ifile = open(os.path.join(os.path.dirname(__file__), 'data', 'menu.csv'),
                 "r")
    reader = csv.reader(ifile)
    csvprovider = SimpleCsvProvider({'id': 'MENU'}, reader)
    ifile.close()
    return csvprovider
Exemplo n.º 5
0
class SimpleCsvProviderTests(unittest.TestCase):

    def setUp(self):
        from skosprovider.uri import UriPatternGenerator
        self.ifile = open(
            os.path.join(os.path.dirname(__file__), 'data', 'menu.csv'),
            "r"
        )
        reader = csv.reader(self.ifile)
        self.csvprovider = SimpleCsvProvider(
            {'id': 'MENU'},
            reader,
            uri_generator=UriPatternGenerator('http://id.python.org/menu/%s'),
            concept_scheme=ConceptScheme('http://id.python.org/menu')
        )

    def tearDown(self):
        self.ifile.close()
        del self.csvprovider

    def testCount(self):
        self.assertEqual(11, len(self.csvprovider.get_all()))

    def testGetEggAndBacon(self):
        eb = self.csvprovider.get_by_id(1)
        self.assertIsInstance(eb, Concept)
        self.assertEqual('1', eb.id)
        self.assertEqual('http://id.python.org/menu/1', eb.uri)
        self.assertEqual('Egg and Bacon', eb.label().label)
        self.assertEqual('prefLabel', eb.label().type)
        self.assertEqual([], eb.notes)

    def testGetEggAndSpamByUri(self):
        eb = self.csvprovider.get_by_uri('http://id.python.org/menu/3')
        self.assertIsInstance(eb, Concept)
        self.assertEqual('3', eb.id)
        self.assertEqual('http://id.python.org/menu/3', eb.uri)

    def testFindSpam(self):
        spam = self.csvprovider.find({'label': 'Spam'})
        self.assertEqual(8, len(spam))

    def testGetLobster(self):
        eb = self.csvprovider.get_by_id(11)
        self.assertIsInstance(eb, Concept)
        self.assertEqual('11', eb.id)
        self.assertEqual('Lobster Thermidor', eb.label().label)
        self.assertIsInstance(eb.notes[0], Note)
        self.assertIn('Mornay', eb.notes[0].note)
        self.assertEqual('note', eb.notes[0].type)

    def testFindSausageCaseInsensitive(self):
        sausages = self.csvprovider.find({'label': 'sausage'})
        self.assertEqual(4, len(sausages))

    def testFindSausageCaseSensitive(self):
        self.csvprovider.case_insensitive = False
        sausages = self.csvprovider.find({'label': 'Sausage'})
        self.assertEqual(1, len(sausages))
Exemplo n.º 6
0
class SimpleCsvProviderTests(unittest.TestCase):
    def setUp(self):
        from skosprovider.uri import UriPatternGenerator

        self.ifile = open(os.path.join(os.path.dirname(__file__), "data", "menu.csv"), "r")
        reader = csv.reader(self.ifile)
        self.csvprovider = SimpleCsvProvider(
            {"id": "MENU"},
            reader,
            uri_generator=UriPatternGenerator("http://id.python.org/menu/%s"),
            concept_scheme=ConceptScheme("http://id.python.org/menu"),
        )

    def tearDown(self):
        self.ifile.close()
        del self.csvprovider

    def testCount(self):
        self.assertEqual(11, len(self.csvprovider.get_all()))

    def testGetEggAndBacon(self):
        eb = self.csvprovider.get_by_id(1)
        self.assertIsInstance(eb, Concept)
        self.assertEqual("1", eb.id)
        self.assertEqual("http://id.python.org/menu/1", eb.uri)
        self.assertEqual("Egg and Bacon", eb.label().label)
        self.assertEqual("prefLabel", eb.label().type)
        self.assertEqual([], eb.notes)
        assert 1 == len(eb.sources)

    def testGetEggAndSpamByUri(self):
        eb = self.csvprovider.get_by_uri("http://id.python.org/menu/3")
        self.assertIsInstance(eb, Concept)
        self.assertEqual("3", eb.id)
        self.assertEqual("http://id.python.org/menu/3", eb.uri)

    def testFindSpam(self):
        spam = self.csvprovider.find({"label": "Spam"})
        self.assertEqual(8, len(spam))

    def testGetLobster(self):
        eb = self.csvprovider.get_by_id(11)
        self.assertIsInstance(eb, Concept)
        self.assertEqual("11", eb.id)
        self.assertEqual("Lobster Thermidor", eb.label().label)
        self.assertIsInstance(eb.notes[0], Note)
        self.assertIn("Mornay", eb.notes[0].note)
        self.assertEqual("note", eb.notes[0].type)

    def testFindSausageCaseInsensitive(self):
        sausages = self.csvprovider.find({"label": "sausage"})
        self.assertEqual(4, len(sausages))

    def testFindSausageCaseSensitive(self):
        self.csvprovider.case_insensitive = False
        sausages = self.csvprovider.find({"label": "Sausage"})
        self.assertEqual(1, len(sausages))
Exemplo n.º 7
0
 def setUp(self):
     from skosprovider.uri import UriPatternGenerator
     self.ifile = open(
         os.path.join(os.path.dirname(__file__), 'data', 'menu.csv'),
         "r"
     )
     reader = csv.reader(self.ifile)
     self.csvprovider = SimpleCsvProvider(
         {'id': 'MENU'},
         reader,
         uri_generator=UriPatternGenerator('http://id.python.org/menu/%s')
     )
Exemplo n.º 8
0
def file_to_csv_provider(**kwargs):
    """
    Create CSV 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 ifile:
        reader = csv.reader(ifile)
        uri_pattern = kwargs.get('uri_pattern')
        provider_kwargs = {
            'uri_generator': UriPatternGenerator(uri_pattern)
        } if uri_pattern else {}
        return SimpleCsvProvider({'id': input_name.upper()}, reader,
                                 **provider_kwargs)
Exemplo n.º 9
0
from skosprovider.skos import ConceptScheme, Label, Note, Source

from skosprovider_rdf.utils import rdf_dumper

ifile = open(os.path.join(os.path.dirname(__file__), 'data', 'menu.csv'), "r")

reader = csv.reader(ifile)

csvprovider = SimpleCsvProvider(
    {'id': 'MENU'},
    reader,
    uri_generator=UriPatternGenerator('http://id.python.org/menu/%s'),
    concept_scheme=ConceptScheme(
        uri='http://id.python.org/menu',
        labels=[
            Label(type='prefLabel', language='en', label='A pythonesque menu.')
        ],
        notes=[
            Note(
                type='changeNote',
                language='en',
                note=
                "<strong>We didn't need no change notes when I was younger.</strong>",
                markup='HTML')
        ],
        sources=[Source("Monthy Python's Flying Circus, 1970. Spam.")]))

graph = rdf_dumper(csvprovider)

print graph.serialize(format='n3')