本文整理汇总了Python中rdfrest.util.coerce_to_uri函数的典型用法代码示例。如果您正苦于以下问题:Python coerce_to_uri函数的具体用法?Python coerce_to_uri怎么用?Python coerce_to_uri使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coerce_to_uri函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: del_source_trace
def del_source_trace(self, val):
"""I break the link between this trace and one of its source traces
"""
source_uri = coerce_to_uri(val)
# do not trust edit, as there are many verifications to make
with self.edit() as editable:
editable.remove((self.uri, KTBS.hasSource, source_uri))
示例2: add_origin
def add_origin(self, origin):
"""
I add an obsel type to this attribute.
"""
origin_uri = coerce_to_uri(origin)
with self.edit(_trust=True) as editable:
editable.add((self.uri, _HAS_REL_ORIGIN, origin_uri))
示例3: remove_parent
def remove_parent(self, model):
"""
I remove model as a parent model to this model.
"""
with self.edit(_trust=True) as graph:
graph.remove((self.uri, KTBS.hasParentModel,
coerce_to_uri(model, self.uri)))
示例4: create_obsel_type
def create_obsel_type(self, id=None, supertypes=(), label=None):
"""
I create a new obsel type in this model.
:param id: see :ref:`ktbs-resource-creation`
:param supertypes: explain.
:param label: explain.
:rtype: `ObselTypeMixin`:class:
"""
# redefining built-in 'id' #pylint: disable=W0622
if id is None and label is None:
raise ValueError("id or label must be supplied")
uri = mint_uri_from_label(label, self, id)
with self.edit(_trust=True) as graph:
base_uri = self.uri
graph_add = graph.add
graph_add((uri, RDF.type, KTBS.ObselType))
if label is not None:
graph_add((uri, SKOS.prefLabel, Literal(label)))
for i in supertypes:
graph_add((uri, KTBS.hasSuperObselType,
coerce_to_uri(i, base_uri)))
ret = self.factory(uri, [KTBS.ObselType])
assert isinstance(ret, ObselTypeMixin)
return ret
示例5: add_source_trace
def add_source_trace(self, val):
"""I add a source trace to this trace
"""
source_uri = coerce_to_uri(val)
# do not trust edit, as there are many verifications to make
with self.edit() as editable:
editable.add((self.uri, KTBS.hasSource, source_uri))
示例6: add_obsel_type
def add_obsel_type(self, obsel_type):
"""
I add an obsel type to this attribute.
"""
obsel_type_uri = coerce_to_uri(obsel_type)
with self.edit(_trust=True) as editable:
editable.add((self.uri, _HAS_ATT_OBSELTYPE, obsel_type_uri))
示例7: serialize_json_method
def serialize_json_method(graph, method, bindings=None):
valconv = ValueConverter(method.uri)
valconv_uri = valconv.uri
yield u"""{
"@context": "%s",
"@id": "%s",
"@type": "Method",
"hasParentMethod": "%s",
"parameter": [""" % (
CONTEXT_URI, method.uri, valconv_uri(coerce_to_uri(method.parent))
)
own_params = method.iter_parameters_with_values(False)
yield u",".join(
u"\n %s" % dumps("%s=%s" % item)
for item in own_params
) + "]"
used_by = list(method.state.subjects(KTBS.hasMethod, method.uri))
if used_by:
yield u""",\n "isMethodOf": %s""" \
% dumps([ valconv_uri(i) for i in used_by ])
children = list(method.state.subjects(KTBS.hasParentMethod, method.uri))
if children:
yield u""",\n "isParentMethodOf": %s""" \
% dumps([ valconv_uri(i) for i in children])
for i in iter_other_arcs(graph, method.uri, valconv):
yield i
yield u""",\n "inBase": "%s"\n}\n""" % valconv_uri(method.base.uri)
示例8: add_destination
def add_destination(self, destination):
"""
I add an obsel type to this attribute.
"""
destination_uri = coerce_to_uri(destination)
with self.edit(_trust=True) as editable:
editable.add((self.uri, _HAS_REL_DESTINATION, destination_uri))
示例9: remove_destination
def remove_destination(self, destination):
"""
I remove an obsel type from this attribute.
"""
destination_uri = coerce_to_uri(destination)
with self.edit(_trust=True) as editable:
editable.remove((self.uri, _HAS_REL_DESTINATION, destination_uri))
示例10: remove_obsel_type
def remove_obsel_type(self, obsel_type):
"""
I remove an obsel type from this attribute.
"""
obsel_type_uri = coerce_to_uri(obsel_type)
with self.edit(_trust=True) as editable:
editable.remove((self.uri, _HAS_ATT_OBSELTYPE, obsel_type_uri))
示例11: remove_origin
def remove_origin(self, origin):
"""
I remove an obsel type from this attribute.
"""
origin_uri = coerce_to_uri(origin)
with self.edit(_trust=True) as editable:
editable.remove((self.uri, _HAS_REL_ORIGIN, origin_uri))
示例12: remove_data_type
def remove_data_type(self, data_type):
"""
I remove the data type from this attribute.
"""
data_type_uri = coerce_to_uri(data_type)
with self.edit(_trust=True) as editable:
editable.remove((self.uri, _HAS_ATT_DATATYPE, data_type_uri))
示例13: mint_uri_from_label
def mint_uri_from_label(label, target, uri=None, suffix=""):
"""
Mint a URI for a resource posted to `target` based on `label`.
:param label: the label for the resource to create
:param target: the resource "containing" the resource to create
:param uri: if provided, will be used instead (must be fresh)
:param suffix: if provided, will be added to the end of the URI
:return: a URI not present in `target.state`
:rtype: rdflib.URIRef
:raise: InvalidDataError if `uri` is provided and not acceptable
"""
if uri is not None:
uri = coerce_to_uri(uri, target.uri)
if not check_new(target.state, uri):
raise InvalidDataError("URI already in use <%s>" % uri)
if not uri.startswith(target.uri):
raise InvalidDataError(
"URI is wrong <%s> (did you forget a leading '#'?)" % uri)
else:
label = label.lower()
prefix = target.uri
if prefix[-1] != "/":
prefix = "%s#" % prefix
prefix = "%s%s" % (prefix, _NON_ALPHA.sub("-", label))
uri = URIRef("%s%s" % (prefix, suffix))
if not check_new(target.state, uri):
prefix = "%s-" % prefix
uri = make_fresh_uri(target.state, prefix, suffix)
return uri
示例14: __init__
def __init__(self, uri, collection, host_graph, host_parameters):
# not calling parents __init__ #pylint: disable=W0231
self.uri = coerce_to_uri(uri, collection.uri)
self.collection = collection
self.host_graph = host_graph
self.host_parameters = host_parameters
if __debug__:
self._readonly_graph = ReadOnlyGraph(host_graph)
示例15: set_model
def set_model(self, model):
"""I set the model of this trace.
model can be a Model or a URI; relative URIs are resolved against this
trace's URI.
"""
model_uri = coerce_to_uri(model, self.uri)
with self.edit(_trust=True) as graph:
graph.set((self.uri, KTBS.hasModel, model_uri))