本文整理汇总了Python中rdflib.Graph.set方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.set方法的具体用法?Python Graph.set怎么用?Python Graph.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.Graph
的用法示例。
在下文中一共展示了Graph.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_user
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def update_user(request, username):
if request.user.is_authenticated():
try:
input_graph = parse_request_into_graph(request)
except (ParserError, SyntaxError) as e:
return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)
if permission_updates_are_allowed(request, input_graph):
user_uri = URIRef(uris.uri('semantic_store_users', username=username))
user_graph = Graph(store=rdfstore(), identifier=USER_GRAPH_IDENTIFIER)
with transaction.commit_on_success():
try:
user = User.objects.get(username=username)
except ObjectDoesNotExist:
return HttpResponse('User %s does not exist' % (username), status=400)
else:
for t in input_graph.triples((user_uri, NS.dm.lastOpenProject, None)):
user_graph.set(t)
for project in input_graph.objects(user_uri, NS.perm.mayRead):
grant_read_permissions(project, user=user)
for project in input_graph.objects(user_uri, NS.perm.mayUpdate):
grant_write_permissions(project, user=user)
for project in input_graph.objects(user_uri, NS.perm.mayAdminister):
grant_admin_permissions(project, user=user)
return HttpResponse(status=204)
else:
return HttpResponseForbidden('The PUT graph contained permissions updates which were not allowed')
else:
return HttpResponse(status=401)
示例2: test_parse_temporal_is_failsafe
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_parse_temporal_is_failsafe(self):
node = URIRef('http://nowhere.org')
g = Graph()
g.set((node, RDF.type, DCT.PeriodOfTime))
assert temporal_from_rdf(g.resource(node)) is None
assert temporal_from_rdf(Literal('unparseable')) is None
示例3: update_specific_resource
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def update_specific_resource(graph, project_uri, specific_resource_uri):
project_identifier = uris.uri('semantic_store_projects', uri=project_uri)
db_project_graph = Graph(store=rdfstore(), identifier=project_identifier)
for t in specific_resource_subgraph(graph, specific_resource_uri):
db_project_graph.add(t)
for selector in graph.objects(specific_resource_uri, NS.oa.hasSelector):
for i in graph.triples((selector, None, None)):
db_project_graph.set(i)
示例4: test_parse_temporal_as_gov_uk_format
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_parse_temporal_as_gov_uk_format(self):
node = URIRef('http://reference.data.gov.uk/id/year/2017')
g = Graph()
g.set((node, RDF.type, DCT.PeriodOfTime))
daterange = temporal_from_rdf(g.resource(node))
assert isinstance(daterange, db.DateRange)
assert daterange.start, date(2017, 1 == 1)
assert daterange.end, date(2017, 12 == 31)
示例5: test_resource_generic_title
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_resource_generic_title(self):
node = BNode()
g = Graph()
url = 'https://www.somewhere.com/no-extension/'
g.set((node, RDF.type, DCAT.Distribution))
g.set((node, DCAT.downloadURL, URIRef(url)))
resource = resource_from_rdf(g)
resource.validate()
assert resource.title == 'Nameless resource'
示例6: test_resource_title_from_url
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_resource_title_from_url(self):
node = BNode()
g = Graph()
url = 'https://www.somewhere.com/somefile.csv'
g.set((node, RDF.type, DCAT.Distribution))
g.set((node, DCAT.downloadURL, URIRef(url)))
resource = resource_from_rdf(g)
resource.validate()
assert resource.title == 'somefile.csv'
示例7: test_resource_title_ignore_dynamic_url
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_resource_title_ignore_dynamic_url(self):
node = BNode()
g = Graph()
url = 'https://www.somewhere.com/endpoint.json?param=value'
g.set((node, RDF.type, DCAT.Distribution))
g.set((node, DCAT.downloadURL, URIRef(url)))
resource = resource_from_rdf(g)
resource.validate()
assert resource.title == 'Nameless resource'
示例8: test_put_legal_rdf
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_put_legal_rdf(self):
reqhead = { "accept": "text/nt" }
resp_get, content_get = self.request(URL, headers=reqhead)
graph = Graph()
graph.parse(data=content_get, publicID=URL, format="nt")
graph.set((URIRef(URL), RDFS.label, Literal("label has been changed")))
new_content = graph.serialize(format="nt")
assert resp_get.etag is not None
reqhead = {
"if-match": resp_get.etag,
"content-type": "text/nt",
}
resp_put, content_put = self.request(URL, "PUT", new_content,
reqhead)
eq_(resp_put.status_int, 200)
assert "etag" in resp_put.headers
示例9: test_dataset_has_resources
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_dataset_has_resources(self):
node = BNode()
g = Graph()
g.add((node, RDF.type, DCAT.Dataset))
g.add((node, DCT.title, Literal(faker.sentence())))
for i in range(3):
rnode = BNode()
g.set((rnode, RDF.type, DCAT.Distribution))
g.set((rnode, DCAT.downloadURL, URIRef(faker.uri())))
g.add((node, DCAT.distribution, rnode))
dataset = dataset_from_rdf(g)
dataset.validate()
assert isinstance(dataset, Dataset)
assert len(dataset.resources) == 3
示例10: test_dataset_has_resources_from_buggy_plural_distribution
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_dataset_has_resources_from_buggy_plural_distribution(self):
'''Try to extract resources from the wrong distributions attribute'''
node = BNode()
g = Graph()
g.add((node, RDF.type, DCAT.Dataset))
g.add((node, DCT.title, Literal(faker.sentence())))
rnode = BNode()
g.set((rnode, RDF.type, DCAT.Distribution))
g.set((rnode, DCAT.downloadURL, URIRef(faker.uri())))
g.add((node, DCAT.distributions, rnode)) # use plural name
dataset = dataset_from_rdf(g)
dataset.validate()
assert isinstance(dataset, Dataset)
assert len(dataset.resources) == 1
示例11: test_dataset_has_resources_from_literal_instead_of_uriref
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_dataset_has_resources_from_literal_instead_of_uriref(self):
node = BNode()
g = Graph()
g.add((node, RDF.type, DCAT.Dataset))
g.add((node, DCT.title, Literal(faker.sentence())))
rnode = BNode()
g.set((rnode, RDF.type, DCAT.Distribution))
# Resource URL is expressed as a Literal
g.set((rnode, DCAT.downloadURL, Literal(faker.uri())))
g.add((node, DCAT.distribution, rnode))
dataset = dataset_from_rdf(g)
dataset.validate()
assert isinstance(dataset, Dataset)
assert len(dataset.resources) == 1
示例12: test_match_license_from_rights_uri
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_match_license_from_rights_uri(self):
license = LicenseFactory()
node = BNode()
g = Graph()
g.set((node, RDF.type, DCAT.Dataset))
g.set((node, DCT.title, Literal(faker.sentence())))
rnode = BNode()
g.set((rnode, RDF.type, DCAT.Distribution))
g.set((rnode, DCAT.downloadURL, URIRef(faker.uri())))
g.set((rnode, DCT.rights, URIRef(license.url)))
g.add((node, DCAT.distribution, rnode))
dataset = dataset_from_rdf(g)
assert isinstance(dataset.license, License)
assert dataset.license == license
示例13: test_resource_title_from_format
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_resource_title_from_format(self):
node = BNode()
g = Graph()
url = 'https://www.somewhere.com/no-extension/'
g.set((node, RDF.type, DCAT.Distribution))
g.set((node, DCAT.downloadURL, URIRef(url)))
g.set((node, DCT.term('format'), Literal('CSV')))
resource = resource_from_rdf(g)
resource.validate()
assert resource.title == 'csv resource'
示例14: test_parse_temporal_as_schema_format
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
def test_parse_temporal_as_schema_format(self):
node = BNode()
g = Graph()
start = faker.past_date(start_date='-30d')
end = faker.future_date(end_date='+30d')
g.set((node, RDF.type, DCT.PeriodOfTime))
g.set((node, SCHEMA.startDate, Literal(start)))
g.set((node, SCHEMA.endDate, Literal(end)))
daterange = temporal_from_rdf(g.resource(node))
assert isinstance(daterange, db.DateRange)
assert daterange.start == start
assert daterange.end == end
示例15: Namespace
# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import set [as 别名]
class Datasource:
"""A data source
Represents a data source in qrcan, including loading from/storing
to a file using VoID and other vocabularies to persist the state.
"""
ACCESS_DOCUMENT = "doc"
ACCESS_SPARQL_ENDPOINT = "sparql"
MODE_REMOTE = "remote"
MODE_LOCAL = "local"
NAMESPACES = {
"void": Namespace("http://rdfs.org/ns/void#"),
"dcterms": Namespace("http://purl.org/dc/terms/"),
"qrcan": Namespace("http://vocab.deri.ie/qrcan#"),
}
def __init__(self, base_uri, store_dir):
"""Inits the data source.
The base_uri is used for generating the data source ID and
store_dir is the relative directory used for making the
data source persistent, for example:
Datasource('http://example.org/', 'datasources/')
"""
tmp_id = str(uuid.uuid1())
self.g = Graph()
if base_uri.endswith("/"):
self.base_uri = base_uri
else:
self.base_uri = "".join([base_uri, "/"])
if store_dir.endswith("/"):
self.file_name = "".join([store_dir, tmp_id, ".ttl"])
else:
self.file_name = "".join([store_dir, "/", tmp_id, ".ttl"])
self.id = "".join([self.base_uri, tmp_id])
self.name = ""
self.updated = self._timestamp_now()
self.access_method = Datasource.ACCESS_DOCUMENT
self.access_uri = ""
self.access_mode = Datasource.MODE_REMOTE
self.last_sync = None
self.num_triples = 0
self.delta_triples = 0
self.g.bind("void", Datasource.NAMESPACES["void"], True)
self.g.bind("dcterms", Datasource.NAMESPACES["dcterms"], True)
self.g.bind("qrcan", Datasource.NAMESPACES["qrcan"], True)
def identify(self):
"""Returns the ID of the data source as string.
"""
return str(self.id)
def sync_status(self):
"""Returns the synchronisation status of the data source.
False if not yet synced, True otherwise.
"""
if self.last_sync:
return True
else:
return False
def is_local(self):
if self.access_mode == Datasource.MODE_LOCAL:
return True
else:
return False
def location(self):
"""Returns the path to the VoID file where the data source is made persistent.
"""
return self.file_name
def load(self, file_name):
"""Loads the data source description from a VoID file.
"""
self.file_name = file_name
self.g.parse(self.file_name, format="n3")
querystr = """ SELECT *
WHERE {
?ds a void:Dataset ;
dcterms:title ?title;
dcterms:modified ?modified;
qrcan:mode ?accessMode .
OPTIONAL { ?ds void:dataDump ?dumpURI . }
OPTIONAL { ?ds void:sparqlEndpoint ?sparqlURI . }
OPTIONAL { ?ds qrcan:synced ?lastSync . }
OPTIONAL { ?ds void:triples ?numTriples . }
OPTIONAL { ?ds qrcan:delta ?deltaTriples . }
}
"""
res = self.g.query(querystr, initNs=Datasource.NAMESPACES)
for r in res.bindings:
if r["ds"]:
self.id = r["ds"]
if r["title"]:
self.name = r["title"]
if r["modified"]:
#.........这里部分代码省略.........