本文整理汇总了Python中prov.model.ProvDocument.add_bundle方法的典型用法代码示例。如果您正苦于以下问题:Python ProvDocument.add_bundle方法的具体用法?Python ProvDocument.add_bundle怎么用?Python ProvDocument.add_bundle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prov.model.ProvDocument
的用法示例。
在下文中一共展示了ProvDocument.add_bundle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NIDMExporter
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_bundle [as 别名]
#.........这里部分代码省略.........
def _get_model_parameters_estimations(self, error_model):
"""
Infer model estimation method from the 'error_model'. Return an object
of type ModelParametersEstimation.
"""
if error_model.dependance == NIDM_INDEPEDENT_ERROR:
if error_model.variance_homo:
estimation_method = STATO_OLS
else:
estimation_method = STATO_WLS
else:
estimation_method = STATO_GLS
mpe = ModelParametersEstimation(estimation_method, self.software.id)
return mpe
def use_prefixes(self, ttl):
prefix_file = os.path.join(os.path.dirname(__file__), 'prefixes.csv')
context = dict()
with open(prefix_file, encoding="ascii") as csvfile:
reader = csv.reader(csvfile)
next(reader, None) # skip the headers
for alphanum_id, prefix, uri in reader:
if alphanum_id in ttl:
context[prefix] = uri
ttl = "@prefix " + prefix + ": <" + uri + "> .\n" + ttl
ttl = ttl.replace(alphanum_id, prefix + ":")
if uri in ttl:
ttl = ttl.replace(alphanum_id, prefix + ":")
elif uri in ttl:
context[prefix] = uri
ttl = "@prefix " + prefix + ": <" + uri + "> .\n" + ttl
ttl = ttl.replace(alphanum_id, prefix + ":")
return (ttl, context)
def save_prov_to_files(self, showattributes=False):
"""
Write-out provn serialisation to nidm.provn.
"""
self.doc.add_bundle(self.bundle)
# provn_file = os.path.join(self.export_dir, 'nidm.provn')
# provn_fid = open(provn_file, 'w')
# # FIXME None
# # provn_fid.write(self.doc.get_provn(4).replace("None", "-"))
# provn_fid.close()
ttl_file = os.path.join(self.export_dir, 'nidm.ttl')
ttl_txt = self.doc.serialize(format='rdf', rdf_format='turtle')
ttl_txt, json_context = self.use_prefixes(ttl_txt)
# Add namespaces to json-ld context
for namespace in self.doc._namespaces.get_registered_namespaces():
json_context[namespace._prefix] = namespace._uri
for namespace in \
list(self.doc._namespaces._default_namespaces.values()):
json_context[namespace._prefix] = namespace._uri
json_context["xsd"] = "http://www.w3.org/2000/01/rdf-schema#"
# Work-around to issue with INF value in rdflib (reported in
# https://github.com/RDFLib/rdflib/pull/655)
ttl_txt = ttl_txt.replace(' inf ', ' "INF"^^xsd:float ')
with open(ttl_file, 'w') as ttl_fid:
ttl_fid.write(ttl_txt)
# print(json_context)
jsonld_file = os.path.join(self.export_dir, 'nidm.json')
jsonld_txt = self.doc.serialize(format='rdf', rdf_format='json-ld',
context=json_context)
with open(jsonld_file, 'w') as jsonld_fid:
jsonld_fid.write(jsonld_txt)
# provjsonld_file = os.path.join(self.export_dir, 'nidm.provjsonld')
# provjsonld_txt = self.doc.serialize(format='jsonld')
# with open(provjsonld_file, 'w') as provjsonld_fid:
# provjsonld_fid.write(provjsonld_txt)
# provn_file = os.path.join(self.export_dir, 'nidm.provn')
# provn_txt = self.doc.serialize(format='provn')
# with open(provn_file, 'w') as provn_fid:
# provn_fid.write(provn_txt)
# Post-processing
if not self.zipped:
# Just rename temp directory to output_path
os.rename(self.export_dir, self.out_dir)
else:
# Create a zip file that contains the content of the temp directory
os.chdir(self.export_dir)
zf = zipfile.ZipFile(os.path.join("..", self.out_dir), mode='w')
try:
for root, dirnames, filenames in os.walk("."):
for filename in filenames:
zf.write(os.path.join(filename))
finally:
zf.close()
# Need to move up before deleting the folder
os.chdir("..")
shutil.rmtree(os.path.join("..", self.export_dir))