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


Python namespace.RDF属性代码示例

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


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

示例1: create_or_replace

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def create_or_replace(self, create_only=False):
        """
        Create a new binary resource with a corresponding RDF representation.

        :param bool create_only: Whether the resource is being created or
            updated.
        """
        # Persist the stream.
        self.digest, self.size = nonrdfly.persist(
                self.uid, self.stream, prov_cksum_algo=self.prov_cksum_algo,
                prov_cksum=self.prov_cksum)

        # Try to persist metadata. If it fails, delete the file.
        logger.debug('Persisting LDP-NR triples in {}'.format(self.uri))
        try:
            ev_type = super().create_or_replace(create_only)
        except:
            # self.digest is also the file UID.
            nonrdfly.delete(self.digest)
            raise
        else:
            return ev_type


    ## PROTECTED METHODS ## 
开发者ID:scossu,项目名称:lakesuperior,代码行数:27,代码来源:ldp_nr.py

示例2: setUp

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def setUp(self):
        # for RDF/JSON-LD export tests
        self.DT = DataTypeFactory() 
开发者ID:archesproject,项目名称:arches,代码行数:5,代码来源:datatype_to_rdf_tests.py

示例3: add_property_to_graph

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def add_property_to_graph(results, graph, property_type, property_list):

        for row in results:
            if row in property_list:
                graph.add((row, RDF['type'], property_type))
        return graph 
开发者ID:monarch-initiative,项目名称:dipper,代码行数:8,代码来源:GraphUtils.py

示例4: digest_id

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def digest_id(wordage):   # same as source/Source.hash_id(wordage)
        '''
        Form a deterministic digest of input
        Leading 'b' is an experiment forcing the first char to be non numeric
        but valid hex
        Not required for RDF but some other contexts do not want the leading
        char to be a digit

        : param str wordage arbitrary string
        : return str
        '''
        return 'b' + hashlib.sha1(wordage.encode('utf-8')).hexdigest()[1:20] 
开发者ID:monarch-initiative,项目名称:dipper,代码行数:14,代码来源:GraphUtils.py

示例5: to_rdfbykey

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def to_rdfbykey(request,model,key):
    """
        take a model name + object id reference to an instance and apply any RDF serialisers defined for this
        allows a key to de appended to the uri or supplied by parameter (easier for uri values)
    """
    if request.GET.get('key'):
        key = request.GET.get('key')
    try: 
        return _tordf(request,model,None,key)
    except Exception as e: 
        return HttpResponse("Model not serialisable to RDF: %s" % e, status=500) 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:13,代码来源:serialize.py

示例6: to_rdfbyid

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def to_rdfbyid(request,model,id):
    """
        take a model name + object id reference to an instance and apply any RDF serialisers defined for this
    """
    try: 
        return _tordf(request,model,id,None)
    except Exception as e: 
        return HttpResponse("Model not serialisable to RDF: %s" % e, status=500) 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:10,代码来源:serialize.py

示例7: pub_rdf

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def pub_rdf(request,model,id):
    """
        take a model name + object id reference to an instance serialise and push to the configured triplestore
    """
    if request.GET.get('pdb') :
        import pdb; pdb.set_trace()
    # find the model type referenced
    try:
        (app,model) = model.split('.')
        ct = ContentType.objects.get(app_label=app,model=model)
    except:
        ct = ContentType.objects.get(model=model)
    if not ct :
        raise Http404("No such model found")
    oml = ObjectMapping.objects.filter(content_type=ct)
    if not oml :
        raise HttpResponse("Model not serialisable to RDF", status=410 )
    
    obj = get_object_or_404(ct.model_class(), pk=id)
    # ok so object exists and is mappable, better get down to it..

    try:
        rdfstore = get_rdfstore(model,name=request.GET.get('rdfstore') )
    except:
        return  HttpResponse("RDF store not configured", status=410 )
    
    try:
        result = publish(obj, model, oml,rdfstore)
    except Exception as e:
        return HttpResponse("Exception publishing remote RDF content %s" % e,status=500 )
    return HttpResponse("Server reports %s" % result.content,status=result.status_code ) 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:33,代码来源:serialize.py

示例8: _add_srv_mgd_triples

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def _add_srv_mgd_triples(self, *args, **kwargs):
        """
        Add all metadata for the RDF representation of the LDP-NR.

        :param BufferedIO stream: The uploaded data stream.
        :param str mimetype: MIME type of the uploaded file.
        :param defaultdict disposition: The ``Content-Disposition`` header
            content, parsed through ``parse_rfc7240``.
        """
        super()._add_srv_mgd_triples(*args, **kwargs)

        # File size.
        logger.debug('Data stream size: {}'.format(self.size))
        self.provided_imr.set((
            self.uri, nsc['premis'].hasSize, Literal(self.size)))

        # Checksum.
        cksum_term = URIRef(f'urn:{default_hash_algo}:{self.digest}')
        self.provided_imr.set((
            self.uri, nsc['premis'].hasMessageDigest, cksum_term))

        # MIME type.
        self.provided_imr.set((
            self.uri, nsc['ebucore']['hasMimeType'], Literal(self.mimetype)))

        # File name.
        logger.debug('Disposition: {}'.format(self.disposition))
        try:
            self.provided_imr.set((
                self.uri, nsc['ebucore']['filename'], Literal(
                self.disposition['attachment']['parameters']['filename'])))
        except (KeyError, TypeError) as e:
            pass 
开发者ID:scossu,项目名称:lakesuperior,代码行数:35,代码来源:ldp_nr.py

示例9: _tordf

# 需要导入模块: from rdflib import namespace [as 别名]
# 或者: from rdflib.namespace import RDF [as 别名]
def _tordf(request,model,id,key):
    if request.GET.get('pdb') :
        import pdb; pdb.set_trace()
    format = request.GET.get('_format')
    if format not in ('turtle','json-ld'):
        if format == 'json':
            format = "json-ld"
        else:
            format = "turtle"

    # find the model type referenced
    try:
        (app,model) = model.split('.')
        ct = ContentType.objects.get(app_label=app,model=model)
    except:
        ct = ContentType.objects.get(model=model)
    if not ct :
        raise Http404("No such model found")
    oml = ObjectMapping.objects.filter(content_type=ct)
    if not oml :
        return HttpResponse("Model not serialisable to RDF", status=410 )
    if id :    
        obj = get_object_or_404(ct.model_class(), pk=id)
    else :
        try:
            obj = ct.model_class().objects.get_by_natural_key(key)
        except Exception as e:
            try:
                (prefix,term) = key.split(':')
                ns = Namespace.objects.get(prefix=prefix)
                urikey = "".join((ns.uri,term))
                obj = ct.model_class().objects.get_by_natural_key(urikey)
            except Exception as e2:
                raise e
    
    # ok so object exists and is mappable, better get down to it..
 
    includemembers = True
    if request.GET.get('skip') :
        includemembers = request.GET.get('skip') != 'True'
        
    gr = Graph()
#    import pdb; pdb.set_trace()
#    ns_mgr = NamespaceManager(Graph())
#    gr.namespace_manager = ns_mgr
    try:
        gr = build_rdf(gr, obj, oml, includemembers)
    except Exception as e:
        raise Http404("Error during serialisation: " + str(e) )
    return HttpResponse(content_type="text/turtle; charset=utf-8", content=gr.serialize(format=format)) 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:52,代码来源:serialize.py


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