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


Python ConjunctiveGraph.update方法代码示例

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


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

示例1: processDELETE

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import update [as 别名]
def processDELETE(request):
    graph = get_graph_from_request(request)
    
    g = None
    query_object = None
    if graph is None:
        g = ConjunctiveGraph(store=CharmeMiddleware.get_store())        
        query_object = '''
            DROP DEFAULT;
            '''
        query_object = ''
    else:
        g = ConjunctiveGraph(store=CharmeMiddleware.get_store())        
        query_object = '''
            DROP GRAPH <%s>;
            '''
        query_object = query_object % (graph)        
    g.update(query_object)
    
    return HttpResponse(status = 204)  
开发者ID:CHARMe-Project,项目名称:djcharme,代码行数:22,代码来源:endpoint.py

示例2: processPUT

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import update [as 别名]
def processPUT(request):
    graph = get_graph_from_request(request)
    payload = request.body
    
    g = None
    query_object = None
    if graph is None:
        g = ConjunctiveGraph(store=CharmeMiddleware.get_store())        
        query_object = '''
            DROP SILENT DEFAULT;
            '''
        query_object = ''
    else:
        g = ConjunctiveGraph(store=CharmeMiddleware.get_store())        
        query_object = '''
            DROP SILENT GRAPH <%s>;
            '''
        query_object = query_object % (graph)        
    g.update(query_object)
    insert_rdf(payload, 
               content_type(request), 
               graph)
    
    return HttpResponse(status = 204) 
开发者ID:CHARMe-Project,项目名称:djcharme,代码行数:26,代码来源:endpoint.py

示例3: __init__

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import update [as 别名]
class Project:

    def __init__(self, uri, storePath):
        if (uri[-1] != "/"):
            raise SemPipeException("A Module must be a directory and its URI must end with a /")

        self.n = URIRef(uri)

        self.g = ConjunctiveGraph('IOMemory')
        self.storePath = storePath
        if storePath and os.path.exists(storePath+"/store.nquads"):
            self.g.parse(storePath + "/store.nq", format='nquads')
            self.confGraph = self.g.get_context(URIRef("sempipe:confgraph"))
            #self.storePath = storePath
            ## Get the Sleepycat plugin.
            #self.store = plugin.get('Sleepycat', Store)('rdfstore')

            ## Open previously created store, or create it if it doesn't exist yet
            #self.g = ConjunctiveGraph(store="Sleepycat",
            #               identifier = URIRef(self.default_graph_uri))
            ##path = mkdtemp()
            #rt = self.g.open(self.storePath, create=False)
            #if rt == NO_STORE:
            #    # There is no underlying Sleepycat infrastructure, create it
            #    self.g.open(self.storePath, create=True)
            #else:
            #    assert rt == VALID_STORE, "The underlying store is corrupt"
        else:
            #Aggregate graphs
            self.confGraph = self.g.get_context(URIRef("sempipe:confgraph"))
            self._loadconf()
            for graph in self.confGraph.objects(self.n, semp.dataGraph):
                self.loadData(graph)
        for updateList in self.confGraph.objects(self.n, semp.update):
            for updateInstruction in Collection(self.confGraph, updateList):
                self.updateGraph(str(updateInstruction))
        self.commit()
        # Cache HostedSpaces
        self.hostedSpaces = []
        res = self.confGraph.query("""
            SELECT ?baseURI ?mapTo ?index ?htaccess {
                ?baseURI a semp:HostedSpace ;
                semp:mapTo ?mapTo ;
                semp:mapIndexTo ?index ;
                semp:mapHTAccessTo ?htaccess .
            }
        """, initNs={"semp": semp})
        for s in res:
            self.hostedSpaces.append(HostedSpace._make(s))

    def __str__(self):
        return str(self.n)
            
    def __repr__(self):
        return "{0}({1},{2})".format(self.__class__.__name__, repr(self.n), repr(self.storePath))

    def _loadconf(self, uri=None):
        """Loads a graph and all config-graphs it references as configuration graphs

        @param uri: a URIRef, defaults to self.n+SempPipe.conffilename"""
        uri = uri or URIRef(self.n + conffilename)

        if self.g.get_context(uri):
            print("ConfGraph {} already in database".format(uri), file=sys.stderr)
            return

        print("Loading {} as config graph".format(uri), file=sys.stderr)
        newgraph = self.g.parse(uri, format="n3")
        self.confGraph += newgraph
        self.confGraph.add((uri, rdf.type, semp.ConfGraph))
        imports = set(newgraph.objects(uri, semp.confGraph))
        imports |= set(newgraph.objects(self.n, semp.confGraph))
        imports = filter(lambda x: not self.g.get_context(x), imports)
        #Recursively load additional graphs
        for imp in imports:
            self._loadconf(imp)

    def loadData(self, url):
        """Loads a data graph"""
        return parse(self.g, url)

    def updateGraph(self, sparql):
        try:
            self.g.update(sparql)
        except:
            raise SemPipeException("Update instruction failed:\n{}".format(str(sparql)))

    def hostedSpace(self, resource, reverse=False):
        """Picks the best matching hostedSpace for the given resource.

        If reverse is set, resource is considered to be a path
        relative to the buildDir and the corresponding URIRef is
        returned."""
        if reverse:
            hostedSpaces = filter(lambda s: resource.startswith(self.buildDir + s.mapTo), self.hostedSpaces)
        else:
            hostedSpaces = filter(lambda s: resource.startswith(s.baseURI), self.hostedSpaces)
        # Find the best match, which is the most specific one:
        try:
            return max(hostedSpaces, key=lambda s: len(s.baseURI))
#.........这里部分代码省略.........
开发者ID:uholzer,项目名称:sempipe,代码行数:103,代码来源:__init__.py


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