當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。