• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python plugin.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中rdflib.plugin.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: query

    def query(
        self,
        strOrQuery,
        initBindings={},
        initNs={},
        DEBUG=False,
        PARSE_DEBUG=False,
        dataSetBase=None,
        processor="sparql",
        extensionFunctions={sparql.DESCRIBE: describe},
    ):
        """
        Executes a SPARQL query (eventually will support Versa queries with
        same method) against this Graph.

         - `strOrQuery`: Either a string consisting of the SPARQL query or
         	 an instance of rdflib.sparql.bison.Query.Query
         - `initBindings`: A mapping from a Variable to an RDFLib term (used
         	 as initial bindings for SPARQL query)
         - `initNS`: A mapping from a namespace prefix to an instance of
         	 rdflib.Namespace (used for SPARQL query)
         - `DEBUG`: A boolean flag passed on to the SPARQL parser and
         	 evaluation engine
         - `processor`: The kind of RDF query (must be 'sparql' until Versa
         	 is ported)
         - `USE_PYPARSING`: A flag indicating whether to use the
         	 experimental pyparsing parser for SPARQL
        """
        assert processor == "sparql", "SPARQL is currently the only supported RDF query language"
        p = plugin.get(processor, sparql.Processor)(self)
        return plugin.get("SPARQLQueryResult", query.result.QueryResult)(
            p.query(strOrQuery, initBindings, initNs, DEBUG, PARSE_DEBUG, dataSetBase, extensionFunctions)
        )
开发者ID:pombredanne,项目名称:mediatypes,代码行数:33,代码来源:graph.py


示例2: query

    def query(self, strOrQuery, initBindings={}, initNs={}, DEBUG=False,
              dataSetBase=None,
              processor="sparql",
              extensionFunctions={sparql.DESCRIBE:describe}):
        """
        Executes a SPARQL query (eventually will support Versa queries with same method) against this Graph
        strOrQuery - Is either a string consisting of the SPARQL query or an instance of rdflib.sparql.bison.Query.Query
        initBindings - A mapping from a Variable to an RDFLib term (used as initial bindings for SPARQL query)
        initNS - A mapping from a namespace prefix to an instance of rdflib.Namespace (used for SPARQL query)
        DEBUG - A boolean flag passed on to the SPARQL parser and evaluation engine
        processor - The kind of RDF query (must be 'sparql' until Versa is ported)
        """
        assert processor == 'sparql',"SPARQL is currently the only supported RDF query language"
        p = plugin.get(processor, sparql.Processor)(self)
        return plugin.get('SPARQLQueryResult',QueryResult)(p.query(strOrQuery,
                                                                   initBindings,
                                                                   initNs, 
                                                                   DEBUG, 
                                                                   dataSetBase,
                                                                   extensionFunctions))

        processor_plugin = plugin.get(processor, sparql.Processor)(self.store)
        qresult_plugin = plugin.get('SPARQLQueryResult', QueryResult)

        res = processor_plugin.query(strOrQuery, 
                                     initBindings, 
                                     initNs, 
                                     DEBUG, 
                                     extensionFunctions=extensionFunctions)
        return qresult_plugin(res)
开发者ID:ResearchEngr,项目名称:openpowersystem,代码行数:30,代码来源:Graph.py


示例3: sample_query

	def sample_query(self, querystring):
	    print "Query enter"
	    processor = plugin.get('sparql', rdflib.query.Processor)(self.graph)
	    result = plugin.get('sparql', rdflib.query.Result)
	    
	    ns = dict(self.graph.namespace_manager.namespaces())
	    return result(processor.query(querystring, initNs=ns))
开发者ID:shreeshga,项目名称:BlogCrawler,代码行数:7,代码来源:rdflibmethods.py


示例4: __query

def __query(self, query_object, processor='sparql', result='sparql',
        initBindings={}):
    if not isinstance(processor, query.Processor):
        processor = plugin.get(processor, query.Processor)(self)
    if not isinstance(result, query.Result):
        result = plugin.get(result, query.Result)
    return result(processor.query(query_object, initBindings, namespaces))
开发者ID:ugeuder-kata,项目名称:ckanext-kata,代码行数:7,代码来源:vocab.py


示例5: query

 def query(self, query_object, processor='sparql', result='sparql'):
     """
     """
     if not isinstance(processor, query.Processor):
         processor = plugin.get(processor, query.Processor)(self)
     if not isinstance(result, query.Result):
         result = plugin.get(result, query.Result)
     return result(processor.query(query_object))
开发者ID:semantalytics,项目名称:SemanticNationalMap,代码行数:8,代码来源:graph.py


示例6: __init__

 def __init__(self, configuration, db, create):
     self.configuration = configuration
     self.create = create
     self.db = db
     if db:
         self.store = plugin.get(self.storeType, store.Store)(db)
     else:
         self.store = plugin.get(self.storeType, store.Store)()
     self.store.open(configuration, create)
开发者ID:qqmyers,项目名称:foresite-toolkit,代码行数:9,代码来源:tripleStore.py


示例7: query

    def query(self, query_object, processor='sparql', result='sparql', initNs={}, initBindings={}, use_store_provided=True, **kwargs):
        """
        """

        

        if hasattr(self.store, "query") and use_store_provided:
            return self.store.query(self,query_object, initNs, initBindings, **kwargs)

        if not isinstance(result, query.Result):
            result = plugin.get(result, query.Result)
        if not isinstance(processor, query.Processor):
            processor = plugin.get(processor, query.Processor)(self)

        return result(processor.query(query_object, initBindings, initNs, **kwargs))
开发者ID:agarrido,项目名称:ro-manager,代码行数:15,代码来源:graph.py


示例8: main

def main(fd, store_type=None, store_id=None, graph_id=None, gzipped=False):
    """
    Converts MARC21 data stored in fd to a RDFlib graph.
    """
    from rdflib import plugin

    if store_type:
        msg = "Need a {} identifier for a disk-based store."
        assert store_id, msg.format('store')
        assert graph_id, msg.format('graph')
        store = plugin.get(store_type, Store)(store_id)
    else:
        store = 'default'

    graph = Graph(store=store, identifier=graph_id)

    try:
        records = MARCReader(open(fd))

        for i, triple in enumerate(process_records(records)):
            graph.add(triple)
            if i % 100 == 0:
                graph.commit()
            if i % 10000 == 0:
                print i

    finally:
        graph.commit()

    return graph
开发者ID:stuartyeates,项目名称:okrand,代码行数:30,代码来源:okrand.py


示例9: registerplugins

def registerplugins():
    """
    Register plugins.

    If setuptools is used to install rdflib-sqlalchemy, all the provided
    plugins are registered through entry_points. This is strongly recommended.

    However, if only distutils is available, then the plugins must be
    registed manually.

    This method will register all of the rdflib-sqlalchemy Store plugins.

    """
    from rdflib.store import Store
    from rdflib import plugin

    try:
        x = plugin.get("SQLAlchemy", Store)
        del x
        return  # plugins already registered
    except:
        pass  # must register plugins

    # Register the plugins ...

    plugin.register(
        "SQLAlchemy",
        Store,
        "rdflib_sqlalchemy.store",
        "SQLAlchemy",
    )
开发者ID:RDFLib,项目名称:rdflib-sqlalchemy,代码行数:31,代码来源:__init__.py


示例10: testAggregateRaw

def testAggregateRaw():
    memStore = plugin.get('IOMemory',Store)()
    graph1 = Graph(memStore)
    graph2 = Graph(memStore)
    graph3 = Graph(memStore)

    for n3Str,graph in [(testGraph1N3,graph1),
                        (testGraph2N3,graph2),
                        (testGraph3N3,graph3)]:
        graph.parse(StringIO(n3Str),format='n3')

    G = ReadOnlyGraphAggregate([graph1,graph2,graph3])

    #Test triples
    assert len(list(G.triples((None,RDF.type,None))))                  == 4
    assert len(list(G.triples((URIRef("http://test/bar"),None,None)))) == 2
    assert len(list(G.triples((None,URIRef("http://test/d"),None))))   == 3

    #Test __len__
    assert len(G) == 8

    #Test __contains__
    assert (URIRef("http://test/foo"),RDF.type,RDFS.Resource) in G

    barPredicates = [URIRef("http://test/d"),RDFS.isDefinedBy]
    assert len(list(G.triples_choices((URIRef("http://test/bar"),barPredicates,None)))) == 2
开发者ID:AuroraSkywalker,项目名称:watchdog,代码行数:26,代码来源:aggregate_graphs.py


示例11: process_request

 def process_request(self, request):
     request.store = plugin.get(settings.STORE['TYPE'], Store)(
         URIRef(settings.STORE['ID']) 
         if 'ID' in settings.STORE else None,
         Literal(settings.STORE['CONFIG']) 
         if 'CONFIG' in settings.STORE else None)
     return None
开发者ID:editorsnotes,项目名称:django-graphs,代码行数:7,代码来源:middleware.py


示例12: get_rdflib_serializer

def get_rdflib_serializer(name, media_type, plugin_name):
    rdflib_serializer = plugin.get(plugin_name, Serializer)
    return type(name,
                (RDFLibSerializer,),
                {'plugin_name': plugin_name,
                 'media_type': media_type,
                 'rdflib_serializer': rdflib_serializer})
开发者ID:ox-it,项目名称:humfrey,代码行数:7,代码来源:wrapper.py


示例13: test_concurrent2

def test_concurrent2(): 
    dns = Namespace(u"http://www.example.com/")

    store = plugin.get("IOMemory", Store)()
    g1 = Graph(store=store)
    g2 = Graph(store=store)

    g1.add((dns.Name, dns.prop, Literal(u"test")))
    g1.add((dns.Name, dns.prop, Literal(u"test2")))
    g1.add((dns.Name, dns.prop, Literal(u"test3")))

    n = len(g1)
    i = 0

    for t in g1.triples((None, None, None)):
        i+=1
        g2.add(t)
        # next line causes problems because it adds a new Subject that needs
        # to be indexed  in __subjectIndex dictionary in IOMemory Store.
        # which invalidates the iterator used to iterate over g1
        g2.add((dns.Name1, dns.prop1, Literal(u"test")))
        g2.add((dns.Name1, dns.prop, Literal(u"test")))
        g2.add((dns.Name, dns.prop, Literal(u"test4")))

    assert i == n
开发者ID:Dataliberate,项目名称:rdflib,代码行数:25,代码来源:test_iomemory.py


示例14: main

def main():
   # root = tk.Tk()
    #root.withdraw()
    #inFile = filedialog.askopenfilename()
    pathf="/Users/patrick/3cixty/IN/RM/"
    inFile = pathf+"bus-stops-10-06-15.csv"
    outFile=pathf+"bus.ttl"
    csv=readCsv(inFile)
    next(csv, None)  #FILE WITH HEADERS

    store = plugin.get('IOMemory', Store)()
    g = Graph(store)
    graph = ConjunctiveGraph(store)
    prefixes=definePrefixes()
    print('Binding Prefixes')
    bindingPrefixes(graph,prefixes)
    print('Creating graph...')

    for row in csv:
        lstData = createRDF(row)
        createGraph(lstData,g)
    createGraph(lstData,g).serialize(outFile,format='turtle')
    nzip = pathf+time.strftime("%Y-%m-%d")+'.zip'
    zf = zipfile.ZipFile(nzip, mode='w')
    try:
        print ('Creating zip file...')
        zf.write(outFile)
    finally:
        zf.close()
        print ('DONE!')
开发者ID:rmurcioUCL,项目名称:objRDF,代码行数:30,代码来源:iF2RDF04.py


示例15: registerplugins

def registerplugins():
    """
    If rdfextras is installed with setuptools, all plugins are registered
    through entry_points. This is strongly recommended. 

    If only distutils is available, the plugins must be registed manually
    This method will register all rdfextras plugins

    """
    from rdflib import plugin
    from rdflib.query import Processor

    try:
        x=plugin.get('sparql',Processor)
        return # plugins already registered
    except:
        pass # must register plugins    

    from rdflib.query import ResultParser, ResultSerializer, Result

    plugin.register('sparql', Result,
        'rdfextras.sparql.query', 'SPARQLQueryResult')
    plugin.register('sparql', Processor,
        'rdfextras.sparql.processor', 'Processor')

    plugin.register('html', ResultSerializer,
        'rdfextras.sparql.results.htmlresults', 'HTMLResultSerializer')
    plugin.register('xml', ResultSerializer,
        'rdfextras.sparql.results.xmlresults', 'XMLResultSerializer')
    plugin.register('json', ResultSerializer,
        'rdfextras.sparql.results.jsonresults', 'JSONResultSerializer')
    plugin.register('xml', ResultParser,
        'rdfextras.sparql.results.xmlresults', 'XMLResultParser')
    plugin.register('json', ResultParser,
        'rdfextras.sparql.results.jsonresults', 'JSONResultParser')
开发者ID:april1452,项目名称:annotaria,代码行数:35,代码来源:__init__.py


示例16: make_ktbs

def make_ktbs(root_uri="ktbs:/", repository=None, create=None):
    """I create a kTBS engine conforming with the `abstract-ktbs-api`:ref:.

    :param root_uri:    the URI to use as the root of this kTBS
                        (defaults to <ktbs:/>)
    :param repository:  where to store kTBS data
    :param create:      whether the data repository should be initialized;
                        (see below)

    Parameter `repository` can be either a path (in which case data will be
    stored in a directory of that name, which will be created if needed), or a
    string of the form ``":store_type:configuration_string"`` where `store_type`
    is a registered store type in :mod:`rdflib`, and `configuration_string` is
    used to initialize this store.

    If `repository` is omitted or None, a volatile in-memory repository will be
    created.

    Parameter `create` defaults to True if `repository` is None or if it is an
    non-existing path; in other cases, it defaults to False.
    """
    if repository is None:
        if create is None:
            create = True
        repository = ":IOMemory:"
    elif repository[0] != ":":
        if create is None:
            create = not exists(repository)
        repository = ":Sleepycat:%s" % repository
    _, store_type, config_str = repository.split(":", 2)
    store = rdflib_plugin.get(store_type, Store)(config_str)
    service = KtbsService(root_uri, store, create)
    ret = service.get(service.root_uri, _rdf_type=KTBS.KtbsRoot)
    assert isinstance(ret, KtbsRoot)
    return ret
开发者ID:fderbel,项目名称:ktbs,代码行数:35,代码来源:service.py


示例17: __init__

 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,代码行数:7,代码来源:backend.py


示例18: open_store

	def open_store(self):
		default_graph_uri = "http://rdflib.net/rdfstore"
		# open existing store or create new one
		#store = getStore() # if store does not exist, then new store returned
		
		# RDF store section:
		configString = "/var/tmp/rdfstore"
		
		# Get the Sleepycat plugin.
		store = plugin.get('Sleepycat', Store)('rdfstore')		
		# Open previously created store, or create it if it doesn't exist yet
		path = mkdtemp()
		rt = store.open('rdfstore', create=False)
		#print rt
		#print path
		
		if rt == NO_STORE:
			print "Creating new store"
			# There is no underlying Sleepycat infrastructure, create it
			store.open('rdfstore', create=True)        
		else:
			print "store exists "
			#assert rt == VALID_STORE, "The underlying store is corrupt"

		self.graph = Graph(store,identifier = URIRef(default_graph_uri))		
		self.build_graph()	
		        				        
		'''
开发者ID:shreeshga,项目名称:BlogCrawler,代码行数:28,代码来源:rdflibmethods.py


示例19: serialize

    def serialize(self, destination=None, format="xml", base=None, encoding=None, **args):
        """Serialize the Graph to destination

        If destination is None serialize method returns the serialization as a
        string. Format defaults to xml (AKA rdf/xml).
        """
        serializer = plugin.get(format, Serializer)(self)
        if destination is None:
            stream = StringIO()
            serializer.serialize(stream, base=base, encoding=encoding, **args)
            return stream.getvalue()
        if hasattr(destination, "write"):
            stream = destination
            serializer.serialize(stream, base=base, encoding=encoding, **args)
        else:
            location = destination
            scheme, netloc, path, params, query, fragment = urlparse(location)
            if netloc!="":
                print "WARNING: not saving as location is not a local file reference"
                return
            path = location
            name = tempfile.mktemp()
            stream = open(name, 'wb')
            serializer.serialize(stream, base=base, encoding=encoding, **args)
            stream.close()
            if hasattr(shutil,"move"):
                shutil.move(name, path)
            else:
                print("Copying to: " + path)
                shutil.copy(name, path)
                os.remove(name)
开发者ID:semantalytics,项目名称:SemanticNationalMap,代码行数:31,代码来源:graph.py


示例20: serialize

    def serialize(
                self, destination=None, format="xml", 
                base=None, encoding=None, **args):
        """Serialize the Graph to destination

        If destination is None serialize method returns the serialization as a
        string. Format defaults to xml (AKA rdf/xml).

        Format support can be extended with plugins, 
        but 'xml', 'n3', 'turtle', 'nt', 'pretty-xml', trix' are built in.
        """
        serializer = plugin.get(format, Serializer)(self)
        if destination is None:
            stream = StringIO()
            serializer.serialize(stream, base=base, encoding=encoding, **args)
            return stream.getvalue()
        if hasattr(destination, "write"):
            stream = destination
            serializer.serialize(stream, base=base, encoding=encoding, **args)
        else:
            location = destination
            scheme, netloc, path, params, query, fragment = urlparse(location)
            if netloc!="":
                print("WARNING: not saving as location" + \
                      "is not a local file reference")
                return
            name = tempfile.mktemp()
            stream = open(name, 'wb')
            serializer.serialize(stream, base=base, encoding=encoding, **args)
            stream.close()
            if hasattr(shutil,"move"):
                shutil.move(name, path)
            else:
                shutil.copy(name, path)
                os.remove(name)
开发者ID:agarrido,项目名称:ro-manager,代码行数:35,代码来源:graph.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python plugin.register函数代码示例发布时间:2022-05-26
下一篇:
Python namespace.NamespaceManager类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap