当前位置: 首页>>代码示例>>Python>>正文


Python Graph.open方法代码示例

本文整理汇总了Python中rdflib.Graph.open方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.open方法的具体用法?Python Graph.open怎么用?Python Graph.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdflib.Graph的用法示例。


在下文中一共展示了Graph.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CoreSQLiteStoreTestCase

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class CoreSQLiteStoreTestCase(unittest.TestCase):
    """
    Test case for SQLite core.
    """

    store = "SQLite"
    path = None
    storetest = True

    def setUp(self):
        self.graph = Graph(store=self.store)
        fp, self.path = tempfile.mkstemp(suffix=".sqlite")
        self.graph.open(self.path, create=True)

    def tearDown(self):
        # TODO: delete a_tmp_dir
        self.graph.close()
        del self.graph
        if hasattr(self, "path") and self.path is not None:
            if os.path.exists(self.path):
                if os.path.isdir(self.path):
                    for f in os.listdir(self.path):
                        os.unlink(self.path + "/" + f)
                    os.rmdir(self.path)
                elif len(self.path.split(":")) == 1:
                    os.unlink(self.path)
                else:
                    os.remove(self.path)

    def test_escape_quoting(self):
        test_string = "This's a Literal!!"
        self.graph.add((URIRef("http://example.org/foo"), RDFS.label, Literal(test_string, datatype=XSD.string)))
        self.graph.commit()
        assert b("This's a Literal!!") in self.graph.serialize(format="xml")
开发者ID:RDFLib,项目名称:rdflib-sqlite,代码行数:36,代码来源:test_core_sqlite.py

示例2: open_store

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
def open_store(identifier):
    ident = URIRef(identifier)
    store = plugin.get("SQLAlchemy", Store)(identifier=ident)
    graph = Graph(store, identifier=ident)
    uri = Literal(os.environ.get("DATABASE_URL"))
    graph.open(uri, create=False)
    return graph
开发者ID:skebix,项目名称:ocl-manager,代码行数:9,代码来源:views.py

示例3: __init__

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
 def __init__(self):
     from django.conf import settings
     store = plugin.get("SQLAlchemy", Store)(identifier='demo')
     graph = Graph(store, identifier='demo')
     graph.namespace_manager = ns_mgr
     graph.open(Literal("sqlite:///" + settings.BASE_DIR + "demo.db"), create=True)
     self.graph = graph
开发者ID:shaswatgupta,项目名称:triple-edit,代码行数:9,代码来源:backend.py

示例4: create_store_with_identifier

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
def create_store_with_identifier(identifier):
    ident = URIRef(identifier)
    store = plugin.get("SQLAlchemy", Store)(identifier=ident)
    graph = Graph(store, identifier=ident)
    uri = Literal(os.environ.get("DATABASE_URL"))
    graph.open(uri, create=True)
    graph.parse(join(join(settings.BASE_DIR, 'static'), 'output.xml'))
开发者ID:skebix,项目名称:ocl-manager,代码行数:9,代码来源:views.py

示例5: __init__

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class Store:
    def __init__(self):
        self.graph = Graph()

        rt = self.graph.open(storeuri, create=False)
        if rt == None:
            # There is no underlying Sleepycat infrastructure, create it
            self.graph.open(storeuri, create=True)
        else:
            assert rt == VALID_STORE, 'The underlying store is corrupt'

        self.graph.bind('os', OS)
        self.graph.bind('rdfs', RDFS)
        self.graph.bind('geo', GEO)
        self.graph.bind('vcard', VCARD)
        self.graph.bind('scheme', SCHEME)

    def save(self):
        self.graph.serialize(storeuri, format='pretty-xml')

    def new_bandvalue(self, band, charge):
        allotment = al[band] # @@ humanize the identifier (something like #rev-$date)
        self.graph.add((allotment, RDF.type, URIRef('http://data.gmdsp.org.uk/def/council/counciltax/CouncilTaxCharge')))
        self.graph.add((allotment, URIRef('http://data.gmdsp.org.uk/def/council/counciltax/charge'), Literal(charge)))
        self.graph.add((allotment, URIRef('http://data.gmdsp.org.uk/def/council/counciltax/councilTaxBand'), URIRef('http://data.gmdsp.org.uk/def/council/counciltax/council-tax-bands/'+band)))
        self.graph.add((allotment, RDFS.label, Literal('Council tax valuation charges for band '+band, lang='en')))
        self.save()
开发者ID:GMDSP-Linked-Data,项目名称:RDF-work-in-progress,代码行数:29,代码来源:councilbandvalue.py

示例6: __init__

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class Store:
    def __init__(self):

        self.graph = Graph(identifier=URIRef('http://www.google.com'))

        rt = self.graph.open(storeuri, create=False)
        if rt == None:
            # There is no underlying Sleepycat infrastructure, create it
            self.graph.open(storeuri, create=True)
        else:
            assert rt == VALID_STORE, 'The underlying store is corrupt'

        self.graph.bind('os', OS)
        self.graph.bind('rdfs', RDFS)
        self.graph.bind('geo', GEO)
        self.graph.bind('schema', SCHEMA)
        self.graph.bind('spacial', SPACIAL)
        self.graph.bind('streetlamp', streetdef)

    def save(self):
        self.graph.serialize(storeuri, format='pretty-xml')

    #def new_streetlight(self, height, easting, eligible, lamp, lampwatts, location, mintyn, northing, objectId, street, unitid, unitno):
    def new_streetlight(self, height, easting, northing, street, objectId, lamptype, watt):
        streetlamp = sl[objectId] # @@ humanize the identifier (something like #rev-$date)
        self.graph.add((streetlamp, RDF.type, URIRef('http://data.gmdsp.org.uk/def/council/streetlighting/Streetlight')))
       # self.graph.add((streetlamp, streetdef['columnHeight'], Literal(height)))
        self.graph.add((streetlamp, SPACIAL['easting'], Literal(easting)))
        self.graph.add((streetlamp, SPACIAL['northing'], Literal(northing)))
        self.graph.add((streetlamp, VCARD['street-address'], Literal(street)))
        self.graph.add((streetlamp, streetdef['lampType'], Literal(lamptype)))
        self.graph.add((streetlamp, streetdef['wattage'], Literal(watt)))
开发者ID:GMDSP-Linked-Data,项目名称:RDF-work-in-progress,代码行数:34,代码来源:streetLights.py

示例7: DeepGraphStore

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class DeepGraphStore():
    store_name = settings.DEEPGRAPHS_DEFAULT_STORAGE

    def __init__(self, create=True):
        self.create = create
        self.path = "databases/" + random_file_generating()

    def setUp(self):
        self.graph = Graph(store=self.store_name)
        self.graph.open(self.path, create=self.create)

        if self.create:
            self.graph.parse("http://njh.me/foaf.rdf", format='xml')
            self.graph.commit()

    def open(self, path):
        self.graph = Graph(self.store_name).open(path, False)
        return self.graph.__len__

    def query(self, sparql_query):
        return self.graph.query(sparql_query)

    def parse(self, path_to_file_):
        self.graph.parse(path_to_file_)

    def load(self, triples):
        self.graph.load(triples)

    def close(self):
        self.graph.close()

    def size(self):
        size = self.graph.__len__
        self.close()
        return size
开发者ID:deepgraphs,项目名称:dgraphdb,代码行数:37,代码来源:dgraphdbstore.py

示例8: __init__

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class Store:
    def __init__(self):

        self.graph = Graph(identifier=URIRef('http://www.google.com'))

        rt = self.graph.open(storeuri, create=False)
        if rt == None:
            # There is no underlying Sleepycat infrastructure, create it
            self.graph.open(storeuri, create=True)
        else:
            assert rt == VALID_STORE, 'The underlying store is corrupt'

        self.graph.bind('os', OS)
        self.graph.bind('rdfs', RDFS)
        self.graph.bind('geo', GEO)
        self.graph.bind('schema', SCHEMA)
        self.graph.bind('spacial', SPACIAL)

    def save(self):
        self.graph.serialize(storeuri, format='turtle')

    #def new_streetlight(self, height, easting, eligible, lamp, lampwatts, location, mintyn, northing, objectId, street, unitid, unitno):
    def new_streetlight(self, lable, filename, ):
        streetlamp = sl[lable] # @@ humanize the identifier (something like #rev-$date)
        self.graph.add((streetlamp, RDF.type, URIRef('http://data.gmdsp.org.uk/def/council/gritting/GrittingRoute')))
        self.graph.add((streetlamp, RDFS['label'], Literal(lable)))
        self.graph.add((streetlamp, URIRef('http://data.gmdsp.org.uk/def/council/gritting/routeFile'), URIRef(filename)))
        self.save()
开发者ID:GMDSP-Linked-Data,项目名称:RDF-work-in-progress,代码行数:30,代码来源:grittingroutes.py

示例9: _get_graph

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
def _get_graph():
    cat_ident = app.config['CATALOG_ID']
    cat_db = app.config['DATABASE_URI']
    cat_store = plugin.get('SQLAlchemy', Store)(identifier=cat_ident)
    graph = Graph(cat_store, identifier=cat_ident)
    graph.open(cat_db, create=True)
    prepare_graph(graph)
    return graph
开发者ID:rshk,项目名称:datapub,代码行数:10,代码来源:graph.py

示例10: rdf

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
    def rdf(urlrdf, f):
        input = Graph()
        input.open("store2", create=True)
        input.parse(urlrdf, format=f)
        
        for s, p, o in input:
            g.add((s, p, o))

        input.close()
开发者ID:catalogue-of-services-isa,项目名称:cpsv-ap_harvester,代码行数:11,代码来源:harvester.py

示例11: StoreTestCase

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class StoreTestCase(unittest.TestCase):
    """
    Test case for testing store performance... probably should be
    something other than a unit test... but for now we'll add it as a
    unit test.
    """
    store = 'IOMemory'
    path = None
    storetest = True
    performancetest = True

    def setUp(self):
        self.gcold = gc.isenabled()
        gc.collect()
        gc.disable()

        self.graph = Graph(store=self.store)
        from test_postgresql import configString
        from rdflib_postgresql.PostgreSQL import PostgreSQL
        path = configString
        PostgreSQL().destroy(path)
        self.path = path
        self.graph.open(self.path, create=True)
        self.input = Graph()

    def tearDown(self):
        self.graph.close()
        if self.gcold:
            gc.enable()
        # TODO: delete a_tmp_dir
        self.graph.close()

    def testTime(self):
        # number = 1
        print('"%s": [' % self.store)
        for i in ['500triples', '1ktriples', '2ktriples',
                  '3ktriples', '5ktriples', '10ktriples',
                  '25ktriples']:
            inputloc = os.getcwd() + '/test/sp2b/%s.n3' % i
            res = self._testInput(inputloc)
            print("%s," % res.strip())
        print("],")

    def _testInput(self, inputloc):
        number = 1
        store = self.graph
        self.input.parse(location=inputloc, format="n3")

        def add_from_input():
            for t in self.input:
                store.add(t)
        it = itertools.repeat(None, number)
        t0 = time()
        for _i in it:
            add_from_input()
        t1 = time()
        return "%.3g " % (t1 - t0)
开发者ID:RDFLib,项目名称:rdflib-postgresql,代码行数:59,代码来源:test_store_performance.py

示例12: __init__

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class Store:
    def __init__(self):
        self.graph = Graph()
        self.disc = []
        self.applic = []
        rt = self.graph.open(storeuri, create=False)
        if rt == None:
            # There is no underlying Sleepycat infrastructure, create it
            self.graph.open(storeuri, create=True)
        else:
            assert rt == VALID_STORE, 'The underlying store is corrupt'

        self.graph.bind('os', OS)
        self.graph.bind('rdfs', RDFS)
        self.graph.bind('geo', GEO)
        self.graph.bind('vcard', VCARD)
        self.graph.bind('dissision',DISSISION)
        self.graph.bind('sub',SUB)
        self.graph.bind('planing', PLANNING)
        self.graph.bind('plurel', PLUREL)
        self.graph.bind('id', PLANNINGID)

    def save(self):
        self.graph.serialize(storeuri, format='pretty-xml')

    #def new_allotment(self, address, dateapval, datdeciss, code_codetext, decsn_code, dtypnumbco, refval, plot_size, ward):
    def new_plan(self, address, ward, refval, dateapval, datdeciss, dissision, application_type, proposal, DTYPNUMBCO_CODETEXT):
        if dissision not in self.disc:
            print dissision
            self.new_dission(dissision)
            self.disc.append(dissision)

        if application_type not in self.applic:
            print application_type
        #     self.new_application_type(application_type)
            self.applic.append(application_type)

        applicatinon = PLANNINGID[refval.replace ("/", "-").lower()] # @@ humanize the identifier (something like #rev-$date)
        self.graph.add((applicatinon, RDF.type, URIRef('http://data.gmdsp.org.uk/def/council/planning/PlanningApplication')))
        self.graph.add((applicatinon, VCARD['street-address'], Literal(address)))
        self.graph.add((applicatinon, PLANNING['decisionDate'], URIRef('http://reference.data.gov.uk/id/day/'+time.strftime('%Y-%m-%d',datdeciss))))
        self.graph.add((applicatinon, PLANNING['validatedDate'], URIRef('http://reference.data.gov.uk/id/day/'+time.strftime('%Y-%m-%d',dateapval))))
        self.graph.add((applicatinon, PLANNING['decision'], URIRef('http://data.gmdsp.org.uk/def/council/planning/planning-application-status/'+dissision.replace (" ", "-").lower())))
        self.graph.add((applicatinon, PLANNING['applicationType'], URIRef('http://data.gmdsp.org.uk/def/council/planning/planning-application-type/'+application_type.replace (" ", "-").lower())))
        self.graph.add((applicatinon, OS["ward"], URIRef("http://data.ordnancesurvey.co.uk/id/"+ward)))
        self.graph.add((applicatinon, PLANNING["proposal"], Literal(proposal)))
        #self.graph.add((applicatinon, PLANNING["other"], Literal(DTYPNUMBCO_CODETEXT)))

    def new_dission(self, dissision):
        dissision = PLANNINGID[dissision.replace (" ", "-").lower()]
        self.graph.add((dissision, RDF.type, URIRef('http://data.gmdsp.org.uk/def/council/planning/decision')))
        self.graph.add((dissision, RDFS["label"], Literal(dissision)))

    def new_application_type(self, aplication_type):
        application_type = PLANNINGID[aplication_type.replace (" ", "-").lower()]
        self.graph.add((application_type, RDF.type, URIRef('http://data.gmdsp.org.uk/def/council/neighbourhood/planning/application-type')))
        self.graph.add((application_type, RDFS["label"], Literal(aplication_type)))
开发者ID:GMDSP-Linked-Data,项目名称:RDF-work-in-progress,代码行数:59,代码来源:planning.py

示例13: SPARQLStoreDBPediaTestCase

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class SPARQLStoreDBPediaTestCase(unittest.TestCase):
    store_name = 'SPARQLStore'
    path = "http://dbpedia.org/sparql"
    storetest = True
    create = False

    def setUp(self):
        self.graph = Graph(store="SPARQLStore")
        self.graph.open(self.path, create=self.create)
        ns = list(self.graph.namespaces())
        assert len(ns) > 0, ns

    def tearDown(self):
        self.graph.close()

    def test_Query(self):
        query = "select distinct ?Concept where {[] a ?Concept} LIMIT 1"
        res = self.graph.query(query, initNs={})
        for i in res:
            assert type(i[0]) == URIRef, i[0].n3()

    def test_initNs(self):
        query = """\
        SELECT ?label WHERE
            { ?s a xyzzy:Concept ; xyzzy:prefLabel ?label . } LIMIT 10
        """
        res = self.graph.query(
            query,
            initNs={"xyzzy": "http://www.w3.org/2004/02/skos/core#"})
        for i in res:
            assert type(i[0]) == Literal, i[0].n3()

    def test_noinitNs(self):
        query = """\
        SELECT ?label WHERE
            { ?s a xyzzy:Concept ; xyzzy:prefLabel ?label . } LIMIT 10
        """
        self.assertRaises(
            SPARQLWrapper.Wrapper.QueryBadFormed,
            self.graph.query,
            query)

    def test_query_with_added_prolog(self):
        prologue = """\
        PREFIX xyzzy: <http://www.w3.org/2004/02/skos/core#>
        """
        query = """\
        SELECT ?label WHERE
            { ?s a xyzzy:Concept ; xyzzy:prefLabel ?label . } LIMIT 10
        """
        res = self.graph.query(prologue + query)
        for i in res:
            assert type(i[0]) == Literal, i[0].n3()
开发者ID:Dataliberate,项目名称:rdflib,代码行数:55,代码来源:test_sparqlstore.py

示例14: __init__

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
class Store:
    def __init__(self):
        self.graph = Graph()

        rt = self.graph.open(storeuri, create=False)
        if rt == None:
            # There is no underlying Sleepycat infrastructure, create it
            self.graph.open(storeuri, create=True)
        else:
            assert rt == VALID_STORE, 'The underlying store is corrupt'

        self.graph.bind('os', OS)
        self.graph.bind('rdfs', RDFS)
        self.graph.bind('geo', GEO)
        self.graph.bind('vcard', VCARD)
        self.graph.bind('scheme', SCHEME)

    def save(self):
        self.graph.serialize(storeuri, format='pretty-xml')

    def new_address(self, address):
        addr = al["address/"+address.replace(" ", "_").replace(",","-").lower()]
        self.graph.add((addr, RDF.type, VCARD["Location"]))
        self.graph.add((addr, VCARD['street-address'], Literal(address.split(", ")[0])))
        self.graph.add((addr, VCARD['locality'], Literal(address.split(", ")[1])))
        self.graph.add((addr, POST['postcode'], URIRef("http://data.ordnancesurvey.co.uk/id/postcodeunit/"+address.split(", ")[2].replace(" ",""))))

        self.save()

    def new_allotment(self, address, application, disabled_access, external_link, guidence, location, name, plot_size, rent, Easting, Northing):
        print '1'

        #self.new_address(address)
        print '2'
        #print utm.from_latlon(float(location.split(',')[0]), float(location.split(',')[1]))[1]

        allotment = al[name.replace(" ", "-").lower()] # @@ humanize the identifier (something like #rev-$date)
        print '3'
        self.graph.add((allotment, RDF.type, URIRef('http://data.gmdsp.org.uk/def/council/allotment/Allotment')))
        self.graph.add((allotment, COUNCIL['application'], URIRef(application)))
        self.graph.add((allotment, COUNCIL['information'], URIRef(external_link)))
        print '3'
        self.graph.add((allotment, COUNCIL['guidance'], URIRef("http://www.manchester.gov.uk"+guidence)))
       # self.graph.add((allotment, GEO["lat"], Literal(location.split(',')[0])))
        print '4'
       # self.graph.add((allotment, GEO["long"], Literal(location.split(',')[1])))
        print '4'
        self.graph.add((allotment, OS["northing"], Literal(Easting)))
        self.graph.add((allotment, OS["easting"],  Literal(Northing)))
        self.graph.add((allotment, RDFS['label'], Literal(name)))
        self.graph.add((allotment,VCARD['hasAddress'], URIRef("http://data.gmdsp.org.uk/id/manchester/allotments/address/"+address.replace(" ", "_").replace(",","-").lower())))
        self.save()
开发者ID:GMDSP-Linked-Data,项目名称:RDF-work-in-progress,代码行数:54,代码来源:StockPortAllotments.py

示例15: investigate_len_issue

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import open [as 别名]
def investigate_len_issue():
    import shutil, commands
    store = plugin.get('SQLAlchemy', Store)(
        identifier=URIRef("rdflib_test"),
        configuration=Literal("sqlite:///%(here)s/development.sqlite" % {
                                                        "here": os.getcwd()}))
    g0 = Graph('Sleepycat')
    g0.open('/tmp/foo', create=True)
    print("Len g0 on opening: %s\n" % len(g0))
    g1 = Graph(store)
    print("Len g1 on opening: %s\n" % len(g1))
    statementId = BNode()
    print("Adding %s\n\t%s\n\t%s\n" % (statementId, RDF.type, RDF.Statement))
    g0.add((statementId, RDF.type, RDF.Statement))
    g1.add((statementId, RDF.type, RDF.Statement))
    print("Adding %s\n\t%s\n\t%s\n" % (statementId, RDF.subject,
           URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
    g0.add((statementId, RDF.subject,
           URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
    g1.add((statementId, RDF.subject,
           URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
    print("Adding %s\n\t%s\n\t%s\n" % (statementId, RDF.predicate, RDFS.label))
    g0.add((statementId, RDF.predicate, RDFS.label))
    g1.add((statementId, RDF.predicate, RDFS.label))
    print("Adding %s\n\t%s\n\t%s\n" % (
        statementId, RDF.object, Literal("Conjunctive Graph")))
    g0.add((statementId, RDF.object, Literal("Conjunctive Graph")))
    print("Len g0 after adding 4 triples %s\n" % len(g0))
    g1.add((statementId, RDF.object, Literal("Conjunctive Graph")))
    print("Len g1 after adding 4 triples %s\n" % len(g1))
    print(g0.serialize(format="nt") + "\n")
    for s, p, o in g0:
        print("s = %s\n\tp = %s\n\to = %s\n" % (
            repr(s), repr(p), repr(o)))
    print(g1.serialize(format="nt") + "\n")
    for s, p, o in g1:
        print("s = %s\n\tp = %s\n\to = %s\n" % (
            repr(s), repr(p), repr(o)))
    commands.getoutput('cp development.sqlite devcopy.sqlite')
    print("Removing %s\n\t%s\n\t%s\n" % (statementId, RDF.type, RDF.Statement))
    g0.remove((statementId, RDF.type, RDF.Statement))
    print("Len g0 after removal %s\n" % len(g0))
    g1.remove((statementId, RDF.type, RDF.Statement))
    print("Len g1 after removal %s\n" % len(g1))
    print(g0.serialize(format="nt") + "\n")
    print(g1.serialize(format="nt") + "\n")
    g0.close()
    shutil.rmtree('/tmp/foo')
    g1.close()
    os.unlink("%(here)s/development.sqlite" % {"here": os.getcwd()})
开发者ID:IRI-Research,项目名称:rdflib-sqlalchemy,代码行数:52,代码来源:test.py


注:本文中的rdflib.Graph.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。