本文整理汇总了Python中rdflib.RDF.type方法的典型用法代码示例。如果您正苦于以下问题:Python RDF.type方法的具体用法?Python RDF.type怎么用?Python RDF.type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.RDF
的用法示例。
在下文中一共展示了RDF.type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_pkg_lic
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def handle_pkg_lic(self, p_term, predicate, builder_func):
"""
Handle package lics concluded or declared.
"""
try:
for _, _, licenses in self.graph.triples((p_term, predicate, None)):
if (licenses, RDF.type, self.spdx_namespace['ConjunctiveLicenseSet']) in self.graph:
lics = self.handle_conjunctive_list(licenses)
builder_func(self.doc, lics)
elif (licenses, RDF.type, self.spdx_namespace['DisjunctiveLicenseSet']) in self.graph:
lics = self.handle_disjunctive_list(licenses)
builder_func(self.doc, lics)
else:
try:
lics = self.handle_lics(licenses)
builder_func(self.doc, lics)
except SPDXValueError:
self.value_error('PKG_SINGLE_LICS', licenses)
except CardinalityError:
self.more_than_one_error('package {0}'.format(predicate))
示例2: p_file_type
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def p_file_type(self, f_term, predicate):
"""
Set file type.
"""
try:
for _, _, ftype in self.graph.triples((f_term, predicate, None)):
try:
if ftype.endswith('binary'):
ftype = 'BINARY'
elif ftype.endswith('source'):
ftype = 'SOURCE'
elif ftype.endswith('other'):
ftype = 'OTHER'
elif ftype.endswith('archive'):
ftype = 'ARCHIVE'
self.builder.set_file_type(self.doc, ftype)
except SPDXValueError:
self.value_error('FILE_TYPE', ftype)
except CardinalityError:
self.more_than_one_error('file type')
示例3: create_review_node
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def create_review_node(self, review):
"""
Return a review node.
"""
review_node = BNode()
type_triple = (review_node, RDF.type, self.spdx_namespace.Review)
self.graph.add(type_triple)
reviewer_node = Literal(review.reviewer.to_value())
self.graph.add((review_node, self.spdx_namespace.reviewer, reviewer_node))
reviewed_date_node = Literal(review.review_date_iso_format)
reviewed_triple = (review_node, self.spdx_namespace.reviewDate, reviewed_date_node)
self.graph.add(reviewed_triple)
if review.has_comment:
comment_node = Literal(review.comment)
comment_triple = (review_node, RDFS.comment, comment_node)
self.graph.add(comment_triple)
return review_node
示例4: create_annotation_node
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def create_annotation_node(self, annotation):
"""
Return an annotation node.
"""
annotation_node = URIRef(str(annotation.spdx_id))
type_triple = (annotation_node, RDF.type, self.spdx_namespace.Annotation)
self.graph.add(type_triple)
annotator_node = Literal(annotation.annotator.to_value())
self.graph.add((annotation_node, self.spdx_namespace.annotator, annotator_node))
annotation_date_node = Literal(annotation.annotation_date_iso_format)
annotation_triple = (annotation_node, self.spdx_namespace.annotationDate, annotation_date_node)
self.graph.add(annotation_triple)
if annotation.has_comment:
comment_node = Literal(annotation.comment)
comment_triple = (annotation_node, RDFS.comment, comment_node)
self.graph.add(comment_triple)
annotation_type_node = Literal(annotation.annotation_type)
annotation_type_triple = (annotation_node, self.spdx_namespace.annotationType, annotation_type_node)
self.graph.add(annotation_type_triple)
return annotation_node
示例5: package_verif_node
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def package_verif_node(self, package):
"""
Return a node representing package verification code.
"""
verif_node = BNode()
type_triple = (verif_node, RDF.type, self.spdx_namespace.PackageVerificationCode)
self.graph.add(type_triple)
value_triple = (verif_node, self.spdx_namespace.packageVerificationCodeValue, Literal(package.verif_code))
self.graph.add(value_triple)
excl_file_nodes = map(
lambda excl: Literal(excl), package.verif_exc_files)
excl_predicate = self.spdx_namespace.packageVerificationCodeExcludedFile
excl_file_triples = [(verif_node, excl_predicate, xcl_file) for xcl_file in excl_file_nodes]
for trp in excl_file_triples:
self.graph.add(trp)
return verif_node
示例6: create_doc
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def create_doc(self):
"""
Add and return the root document node to graph.
"""
doc_node = URIRef('http://www.spdx.org/tools#SPDXRef-DOCUMENT')
# Doc type
self.graph.add((doc_node, RDF.type, self.spdx_namespace.SpdxDocument))
# Version
vers_literal = Literal(str(self.document.version))
self.graph.add((doc_node, self.spdx_namespace.specVersion, vers_literal))
# Data license
data_lics = URIRef(self.document.data_license.url)
self.graph.add((doc_node, self.spdx_namespace.dataLicense, data_lics))
if self.document.name:
doc_name = URIRef(self.document.name)
self.graph.add((doc_node, self.spdx_namespace.name, doc_name))
return doc_node
示例7: rdfs_classes
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def rdfs_classes(rdf):
"""Perform RDFS subclass inference.
Mark all resources with a subclass type with the upper class."""
# find out the subclass mappings
upperclasses = {} # key: class val: set([superclass1, superclass2..])
for s, o in rdf.subject_objects(RDFS.subClassOf):
upperclasses.setdefault(s, set())
for uc in rdf.transitive_objects(s, RDFS.subClassOf):
if uc != s:
upperclasses[s].add(uc)
# set the superclass type information for subclass instances
for s, ucs in upperclasses.items():
logging.debug("setting superclass types: %s -> %s", s, str(ucs))
for res in rdf.subjects(RDF.type, s):
for uc in ucs:
rdf.add((res, RDF.type, uc))
示例8: init_prov_graph
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def init_prov_graph(self):
"""
Initialize PROV graph with all we know at the start of the recording
"""
try:
# Use git2prov to get prov on the repo
repo_prov = check_output(
['node_modules/git2prov/bin/git2prov', 'https://github.com/{}/{}/'.format(self.user, self.repo),
'PROV-O']).decode("utf-8")
repo_prov = repo_prov[repo_prov.find('@'):]
# glogger.debug('Git2PROV output: {}'.format(repo_prov))
glogger.debug('Ingesting Git2PROV output into RDF graph')
with open('temp.prov.ttl', 'w') as temp_prov:
temp_prov.write(repo_prov)
self.prov_g.parse('temp.prov.ttl', format='turtle')
except Exception as e:
glogger.error(e)
glogger.error("Couldn't parse Git2PROV graph, continuing without repo PROV")
pass
self.prov_g.add((self.agent, RDF.type, self.prov.Agent))
self.prov_g.add((self.entity_d, RDF.type, self.prov.Entity))
self.prov_g.add((self.activity, RDF.type, self.prov.Activity))
# entity_d
self.prov_g.add((self.entity_d, self.prov.wasGeneratedBy, self.activity))
self.prov_g.add((self.entity_d, self.prov.wasAttributedTo, self.agent))
# later: entity_d genereated at time (when we know the end time)
# activity
self.prov_g.add((self.activity, self.prov.wasAssociatedWith, self.agent))
self.prov_g.add((self.activity, self.prov.startedAtTime, Literal(datetime.now())))
# later: activity used entity_o_1 ... entity_o_n
# later: activity endedAtTime (when we know the end time)
示例9: add_used_entity
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def add_used_entity(self, entity_uri):
"""
Add the provided URI as a used entity by the logged activity
"""
entity_o = URIRef(entity_uri)
self.prov_g.add((entity_o, RDF.type, self.prov.Entity))
self.prov_g.add((self.activity, self.prov.used, entity_o))
示例10: add_children_to_collection
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def add_children_to_collection(self, source_graph, out_graph, parent_id, topconcept_id):
children = [i for i in source_graph.triples((topconcept_id, SKOS["narrower"], None))]
for child in children:
out_graph.add((ARCHES[parent_id], SKOS["member"], child[2]))
out_graph.add((child[2], RDF.type, SKOS["Concept"]))
self.add_children_to_collection(source_graph, out_graph, child[2], child[2])
return out_graph
示例11: remove_ontology_axioms
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def remove_ontology_axioms(graph):
"""
Given an rdflib graph, remove any triples
connected to an ontology node:
{} a owl:Ontology
:param graph: RDFGraph
:return: None
"""
ontology_iri = URIRef("http://www.w3.org/2002/07/owl#Ontology")
for subject in graph.subjects(RDF.type, ontology_iri):
for predicate, obj in graph.predicate_objects(subject):
graph.remove((subject, predicate, obj))
graph.remove((subject, RDF.type, ontology_iri))
示例12: save_keywords_in_bulk
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def save_keywords_in_bulk(self, graph):
keywords = []
for subject in graph.subjects(RDF.type, SKOS.Concept):
keyword = self.create_keyword(graph, subject)
if keyword:
keywords.append(keyword)
Keyword.objects.bulk_create(keywords, batch_size=1000)
示例13: handle_lics
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def handle_lics(self, lics):
"""
Return a License from a `lics` license resource.
"""
# Handle extracted licensing info type.
if (lics, RDF.type, self.spdx_namespace['ExtractedLicensingInfo']) in self.graph:
return self.parse_only_extr_license(lics)
# Assume resource, hence the path separator
ident_start = lics.rfind('/') + 1
if ident_start == 0:
# special values such as spdx:noassertion
special = self.to_special_value(lics)
if special == lics:
if self.LICS_REF_REGEX.match(lics):
# Is a license ref i.e LicenseRef-1
return document.License.from_identifier(six.text_type(lics))
else:
# Not a known license form
raise SPDXValueError('License')
else:
# is a special value
return special
else:
# license url
return document.License.from_identifier(lics[ident_start:])
示例14: p_pkg_lics_info_from_files
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def p_pkg_lics_info_from_files(self, p_term, predicate):
for _, _, lics in self.graph.triples((p_term, predicate, None)):
try:
if (lics, RDF.type, self.spdx_namespace['ExtractedLicensingInfo']) in self.graph:
self.builder.set_pkg_license_from_file(self.doc, self.parse_only_extr_license(lics))
else:
self.builder.set_pkg_license_from_file(self.doc, self.handle_lics(lics))
except SPDXValueError:
self.value_error('PKG_LICS_INFO_FILES', lics)
示例15: p_file_artifact
# 需要导入模块: from rdflib import RDF [as 别名]
# 或者: from rdflib.RDF import type [as 别名]
def p_file_artifact(self, f_term, predicate):
"""
Handle file artifactOf.
Note: does not handle artifact of project URI.
"""
for _, _, project in self.graph.triples((f_term, predicate, None)):
if (project, RDF.type, self.doap_namespace['Project']):
self.p_file_project(project)
else:
self.error = True
msg = 'File must be artifact of doap:Project'
self.logger.log(msg)