本文整理汇总了Python中rdflib.namespace.RDFS.label方法的典型用法代码示例。如果您正苦于以下问题:Python RDFS.label方法的具体用法?Python RDFS.label怎么用?Python RDFS.label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.namespace.RDFS
的用法示例。
在下文中一共展示了RDFS.label方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: append_to_document
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def append_to_document(self, document, nodevalue, nodeid, tile, provisional=False):
try:
assert isinstance(nodevalue, (list, tuple)) # assert nodevalue is an array
except AssertionError:
nodevalue = [nodevalue]
for valueid in nodevalue:
value = self.get_value(valueid)
date_range = self.get_concept_dates(value.concept)
if date_range is not None:
min_date = ExtendedDateFormat(date_range["min_year"]).lower
max_date = ExtendedDateFormat(date_range["max_year"]).upper
if {"gte": min_date, "lte": max_date} not in document["date_ranges"]:
document["date_ranges"].append(
{"date_range": {"gte": min_date, "lte": max_date}, "nodegroup_id": tile.nodegroup_id, "provisional": provisional}
)
document["domains"].append(
{
"label": value.value,
"conceptid": value.concept_id,
"valueid": valueid,
"nodegroup_id": tile.nodegroup_id,
"provisional": provisional,
}
)
document["strings"].append({"string": value.value, "nodegroup_id": tile.nodegroup_id, "provisional": provisional})
示例2: test_rdf_concept
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def test_rdf_concept(self):
dt = self.DT.get_instance("concept")
# d75977c1-635b-41d5-b53d-1c82d2237b67 should be the ConceptValue for "junk sculpture"
# Main concept should be 0ad97528-0fb0-43bf-afee-0fb9dde78b99
# should also have an identifier of http://vocab.getty.edu/aat/300047196
edge_info = {}
edge_info["range_tile_data"] = "d75977c1-635b-41d5-b53d-1c82d2237b67"
edge_info["r_uri"] = URIRef("http://vocab.getty.edu/aat/300047196")
edge_info["d_uri"] = URIRef("test")
edge = Mock()
edge.ontologyproperty = CIDOC_NS["P2_has_type"]
edge.rangenode.ontologyclass = CIDOC_NS["E55_Type"]
graph = dt.to_rdf(edge_info, edge)
print(graph.serialize(format="ttl"))
self.assertTrue((edge_info["d_uri"], edge.ontologyproperty, URIRef("http://vocab.getty.edu/aat/300047196")) in graph)
self.assertTrue((URIRef("http://vocab.getty.edu/aat/300047196"), RDFS.label, Literal("junk sculpture")) in graph)
示例3: test_rdf_concept_list
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def test_rdf_concept_list(self):
dt = self.DT.get_instance("concept-list")
concept_list = [
"d75977c1-635b-41d5-b53d-1c82d2237b67", # junk sculpture@en, has aat identifier
"4beb7055-8a6e-45a3-9bfb-32984b6f82e0", # "example document type"@en-us, no ext id}
]
edge_info = {}
edge_info["range_tile_data"] = concept_list
edge_info["r_uri"] = URIRef("http://vocab.getty.edu/aat/300047196")
edge_info["d_uri"] = URIRef("test")
edge = Mock()
edge.ontologyproperty = CIDOC_NS["P2_has_type"]
edge.rangenode.ontologyclass = CIDOC_NS["E55_Type"]
graph = dt.to_rdf(edge_info, edge)
edge_info["r_uri"] = ARCHES_NS["concepts/037daf4d-054a-44d2-9c0a-108b59e39109"]
graph += dt.to_rdf(edge_info, edge)
self.assertTrue((edge_info["d_uri"], edge.ontologyproperty, URIRef("http://vocab.getty.edu/aat/300047196")) in graph)
self.assertTrue((URIRef("http://vocab.getty.edu/aat/300047196"), RDFS.label, Literal("junk sculpture")) in graph)
self.assertTrue((edge_info["d_uri"], edge.ontologyproperty, ARCHES_NS["concepts/037daf4d-054a-44d2-9c0a-108b59e39109"]) in graph)
self.assertTrue((ARCHES_NS["concepts/037daf4d-054a-44d2-9c0a-108b59e39109"], RDFS.label, Literal("example document type")) in graph)
示例4: __init__
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def __init__(self, node, sht_graph, result_node, data_graph, shapes_graph, label=None, status=None):
"""
:param sht_graph:
:type sht_graph: rdflib.Graph
:param data_graph:
:type data_graph: rdflib.Graph
:param shapes_graph:
:type shapes_graph: rdflib.Graph
:param label:
"""
self.node = node
self.sht_graph = sht_graph
self.sht_result = result_node
self.data_graph = data_graph
self.shapes_graph = shapes_graph
self.label = label
self.status = status
示例5: test_all_fields
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def test_all_fields(self):
user = UserFactory(website=faker.uri())
user_url = url_for('users.show_redirect',
user=user.id,
_external=True)
u = user_to_rdf(user)
g = u.graph
self.assertIsInstance(u, RdfResource)
self.assertEqual(len(list(g.subjects(RDF.type, FOAF.Person))), 1)
self.assertEqual(u.value(RDF.type).identifier, FOAF.Person)
self.assertIsInstance(u.identifier, URIRef)
self.assertEqual(u.identifier.toPython(), user_url)
self.assertEqual(u.value(FOAF.name), Literal(user.fullname))
self.assertEqual(u.value(RDFS.label), Literal(user.fullname))
self.assertEqual(u.value(FOAF.homepage).identifier,
URIRef(user.website))
示例6: test_all_fields
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def test_all_fields(self):
org = OrganizationFactory(url=faker.uri())
org_url = url_for('organizations.show_redirect',
org=org.id,
_external=True)
o = organization_to_rdf(org)
g = o.graph
self.assertIsInstance(o, RdfResource)
self.assertEqual(len(list(g.subjects(RDF.type, FOAF.Organization))), 1)
self.assertEqual(o.value(RDF.type).identifier, FOAF.Organization)
self.assertIsInstance(o.identifier, URIRef)
self.assertEqual(o.identifier.toPython(), org_url)
self.assertEqual(o.value(FOAF.name), Literal(org.name))
self.assertEqual(o.value(RDFS.label), Literal(org.name))
self.assertEqual(o.value(FOAF.homepage).identifier, URIRef(org.url))
示例7: user_to_rdf
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def user_to_rdf(user, graph=None):
'''
Map a Resource domain model to a DCAT/RDF graph
'''
graph = graph or Graph(namespace_manager=namespace_manager)
if user.id:
user_url = url_for('users.show_redirect',
user=user.id,
_external=True)
id = URIRef(user_url)
else:
id = BNode()
o = graph.resource(id)
o.set(RDF.type, FOAF.Person)
o.set(FOAF.name, Literal(user.fullname))
o.set(RDFS.label, Literal(user.fullname))
if user.website:
o.set(FOAF.homepage, URIRef(user.website))
return o
示例8: save_entity_labels
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def save_entity_labels(self):
""" saves labels of entities in a vocabulary """
output = False
if self.graph is not False and self.vocabulary_uri is not False:
output = []
if self.replace_old:
LinkEntity.objects.filter(vocab_uri=self.vocabulary_uri).delete()
for s, p, o in self.graph.triples((None,
RDFS.label,
None)):
subject_uri = s.__str__() # get the URI of the subject as a string
label = o.__str__() # get the Label of from object as a string
le_ents = LinkEntity.objects.filter(uri=subject_uri)[:1]
if len(le_ents) < 1 or self.replace_old:
newr = LinkEntity()
newr.uri = subject_uri
newr.label = label
newr.alt_label = label
newr.ent_type = 'class'
newr.vocab_uri = self.vocabulary_uri
newr.save()
act_t = {'s': subject_uri,
'o': label}
output.append(act_t)
return output
示例9: initialize_concept_scheme
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def initialize_concept_scheme(rdf, cs, label, language, set_modified):
"""Initialize a concept scheme: Optionally add a label if the concept
scheme doesn't have a label, and optionally add a dct:modified
timestamp."""
# check whether the concept scheme is unlabeled, and label it if possible
labels = list(rdf.objects(cs, RDFS.label)) + \
list(rdf.objects(cs, SKOS.prefLabel))
if len(labels) == 0:
if not label:
logging.warning(
"Concept scheme has no label(s). "
"Use --label option to set the concept scheme label.")
else:
logging.info(
"Unlabeled concept scheme detected. Setting label to '%s'" %
label)
rdf.add((cs, RDFS.label, Literal(label, language)))
if set_modified:
curdate = datetime.datetime.utcnow().replace(microsecond=0).isoformat() + 'Z'
rdf.remove((cs, DCTERMS.modified, None))
rdf.add((cs, DCTERMS.modified, Literal(curdate, datatype=XSD.dateTime)))
示例10: transform_export_values
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def transform_export_values(self, value, *args, **kwargs):
ret = ""
if (
kwargs["concept_export_value_type"] is None
or kwargs["concept_export_value_type"] == ""
or kwargs["concept_export_value_type"] == "label"
):
ret = self.get_option_text(models.Node.objects.get(nodeid=kwargs["node"]), value)
elif kwargs["concept_export_value_type"] == "both":
ret = value + "|" + self.get_option_text(models.Node.objects.get(nodeid=kwargs["node"]), value)
elif kwargs["concept_export_value_type"] == "id":
ret = value
return ret
示例11: ignore_keys
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def ignore_keys(self):
return ["http://www.w3.org/2000/01/rdf-schema#label http://www.w3.org/2000/01/rdf-schema#Literal"]
示例12: get_concept_export_value
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def get_concept_export_value(self, valueid, concept_export_value_type=None):
ret = ""
if valueid is None or valueid.strip() == "":
pass
elif concept_export_value_type is None or concept_export_value_type == "" or concept_export_value_type == "label":
ret = self.get_value(valueid).value
elif concept_export_value_type == "both":
ret = valueid + "|" + self.get_value(valueid).value
elif concept_export_value_type == "id":
ret = valueid
return ret
示例13: collect_tests
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def collect_tests(self):
if not self.has_entries:
return []
tests = []
g = self.sht_graph
for entry in self.entries:
test_types = set(g.objects(entry, RDF.type))
if SHT.Validate not in test_types:
continue
try:
label = next(iter(g.objects(entry, RDFS.label)))
label = str(label)
except StopIteration:
label = None
try:
action = next(iter(g.objects(entry, MF.action)))
except StopIteration:
raise RuntimeError("MF Validate has no value for mf:action")
try:
result = next(iter(g.objects(entry, MF.result)))
except StopIteration:
raise RuntimeError("MF Validate has no value for mf:result")
try:
data_graph = next(iter(g.objects(action, SHT.dataGraph)))
except StopIteration:
raise RuntimeError("mf:action has no value for sht:dataGraph")
try:
shapes_graph = next(iter(g.objects(action, SHT.shapesGraph)))
except StopIteration:
raise RuntimeError("mf:action has no value for sht:shapesGraph")
try:
status = next(iter(g.objects(entry, MF.status)))
except StopIteration:
raise RuntimeError("MF Validate has no value for mf:status")
if str(shapes_graph) == str(data_graph):
shapes_graph = None
if str(data_graph) == self.base:
data_graph = self.sht_graph
test = SHTValidate(entry, self.sht_graph, result, data_graph, shapes_graph, label=label, status=status)
tests.append(test)
return tests
示例14: test_minimal
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def test_minimal(self):
user = UserFactory.build() # Does not have an URL
u = user_to_rdf(user)
g = u.graph
self.assertIsInstance(u, RdfResource)
self.assertEqual(len(list(g.subjects(RDF.type, FOAF.Person))), 1)
self.assertEqual(u.value(RDF.type).identifier, FOAF.Person)
self.assertIsInstance(u.identifier, BNode)
self.assertEqual(u.value(FOAF.name), Literal(user.fullname))
self.assertEqual(u.value(RDFS.label), Literal(user.fullname))
示例15: test_minimal
# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import label [as 别名]
def test_minimal(self):
org = OrganizationFactory.build() # Does not have an URL
o = organization_to_rdf(org)
g = o.graph
self.assertIsInstance(o, RdfResource)
self.assertEqual(len(list(g.subjects(RDF.type, FOAF.Organization))), 1)
self.assertEqual(o.value(RDF.type).identifier, FOAF.Organization)
self.assertIsInstance(o.identifier, BNode)
self.assertEqual(o.value(FOAF.name), Literal(org.name))
self.assertEqual(o.value(RDFS.label), Literal(org.name))