def ctfToProv(): d1 = ProvDocument() dummy = ProvDocument() ex = Namespace( 'ex', 'http://example/' ) # namespaces do not need to be explicitly added to a document #data = event_field(os.path.join(trace_path,'../config.yaml')) counter = 0 counter_1 = 0 relationships = [] entities = [] activities = [] for event in trace_collection.events: dataset = { 'ex:' + k: event[k] for k in event.field_list_with_scope( babeltrace.CTFScope.EVENT_FIELDS) } dataset.update( {'ex:' + 'timestamp': (event['timestamp'] / 1000000000)}) #dataset.update({'ex:'+'name':event.name}) e1 = d1.entity(ex['event' + str(counter)], dataset) entities.append(e1) producer_agent = d1.agent('ex:' + event['producer_id']) controller_agent = d1.agent('ex:' + event['controller_id']) activity = d1.activity('ex:' + event['activity'] + str(counter_1)) activities.append(activity) d1.wasGeneratedBy(e1, activity) # strings used to detect if the relationship already exists in the d1 document association_relationship = str( dummy.wasAssociatedWith(activity, producer_agent)) used_relationship = str(dummy.used(controller_agent, producer_agent)) # Add activity to producer agent if it has not been added before. d1.wasAssociatedWith(activity, producer_agent) # if association_relationship not in relationships: # d1.wasAssociatedWith(activity, producer_agent) # relationships.append(association_relationship) # Add producer agent to controller agent if it has not been added yet. if used_relationship not in relationships: d1.used(controller_agent, producer_agent) relationships.append(used_relationship) # Add temporal relationship between this event and the previous one. if counter > 0: d1.wasAssociatedWith(entities[counter - 1], e1) counter += 1 counter_1 += 1 return d1
def get_document_as_prov(self, document_id=None): """ Get a ProvDocument from the database based on the document_id :param document_id: The id as a sting value :return: ProvDocument """ if type(document_id) is not str: raise InvalidArgumentTypeException() raw_doc = self._adapter.get_document(document_id) # parse document prov_document = ProvDocument() for record in raw_doc.document.records: self._parse_record(prov_document, record) for bundle in raw_doc.bundles: prefixed_identifier = bundle.bundle_record.metadata[ METADATA_KEY_IDENTIFIER] # remove prefix identifier = prefixed_identifier[ len(PROV_API_BUNDLE_IDENTIFIER_PREFIX) - 2:] prov_bundle = prov_document.bundle(identifier=identifier) for record in bundle.records: self._parse_record(prov_bundle, record) return prov_document
def base_connector_record_parameter_example(): """ Returns a dict with attributes and metadata for a simple node :return:dict with attributes metadata :rtype: dict """ doc = ProvDocument() namespaces = dict() namespaces.update({"ex": "http://example.com"}) namespaces.update({"custom": "http://custom.com"}) type_map = dict() type_map.update({"int value": "int"}) type_map.update({"date value": "xds:datetime"}) metadata = dict() metadata.update( {METADATA_KEY_PROV_TYPE: doc.valid_qualified_name("prov:Activity")}) metadata.update({ METADATA_KEY_IDENTIFIER: doc.valid_qualified_name("prov:example_node") }) metadata.update({METADATA_KEY_TYPE_MAP: type_map}) metadata.update({METADATA_KEY_NAMESPACES: namespaces}) return_data = dict() return_data.update({"attributes": attributes_dict_example()}) return_data.update({"metadata": metadata}) return return_data
def base_connector_bundle_parameter_example(): """ This example returns a dict with example arguments for a db_adapter :return: dict {attributes, metadata} :rtype: dict """ doc = ProvDocument() doc.add_namespace("ex", "http://example.com") attributes = dict() attributes.update({"prov:type": "prov:Bundle"}) namespaces = dict() namespaces.update({"ex": "http://example.com"}) type_map = dict() type_map.update({"int value": "int"}) type_map.update({"date value": "xds:datetime"}) metadata = dict() metadata.update( {METADATA_KEY_PROV_TYPE: doc.valid_qualified_name("prov:Entity")}) metadata.update( {METADATA_KEY_IDENTIFIER: doc.valid_qualified_name("ex:bundle name")}) metadata.update({METADATA_KEY_TYPE_MAP: type_map}) metadata.update({METADATA_KEY_NAMESPACES: namespaces}) return_data = dict() return_data.update({"attributes": attributes}) return_data.update({"metadata": metadata}) return return_data
def prov_db_unknown_prov_typ_example(): doc = ProvDocument() doc.add_namespace("ex", "https://example.com") doc.entity(identifier="ex:Entity1") doc.entity(identifier="ex:Entity2") doc.influence(influencee="ex:Entity1", influencer="ex:Entity2") return doc
def __init__(self, database_helper, full_provenance=False): """ Initializes the provenance for the mjclawar_rarshad project Parameters ---------- database_helper: DatabaseHelper full_provenance: bool Returns ------- """ assert isinstance(database_helper, DatabaseHelper) self.database_helper = database_helper if full_provenance: self.prov_doc = ProvDocument.deserialize(dir_info.plan_json) else: self.prov_doc = ProvDocument() self.prov_doc.add_namespace(mcras.BDP_NAMESPACE.name, mcras.BDP_NAMESPACE.link) self.prov_doc.add_namespace(mcras.ALG_NAMESPACE.name, mcras.ALG_NAMESPACE.link) self.prov_doc.add_namespace(mcras.DAT_NAMESPACE.name, mcras.DAT_NAMESPACE.link) self.prov_doc.add_namespace(mcras.LOG_NAMESPACE.name, mcras.LOG_NAMESPACE.link) self.prov_doc.add_namespace(mcras.ONT_NAMESPACE.name, mcras.ONT_NAMESPACE.link)
def primer(): a = ProvDocument() script_path = os.path.dirname(os.path.abspath(__file__)) # with open(str(script_path) + "/output.json") as json_file: line = json_file.readline() a = a.deserialize(content=line) return a
def __init__( self, research_object: "ResearchObject", full_name: str, host_provenance: bool, user_provenance: bool, orcid: str, fsaccess: StdFsAccess, run_uuid: Optional[uuid.UUID] = None, ) -> None: """Initialize the provenance profile.""" self.fsaccess = fsaccess self.orcid = orcid self.research_object = research_object self.folder = self.research_object.folder self.document = ProvDocument() self.host_provenance = host_provenance self.user_provenance = user_provenance self.engine_uuid = research_object.engine_uuid # type: str self.add_to_manifest = self.research_object.add_to_manifest if self.orcid: _logger.debug("[provenance] Creator ORCID: %s", self.orcid) self.full_name = full_name if self.full_name: _logger.debug("[provenance] Creator Full name: %s", self.full_name) self.workflow_run_uuid = run_uuid or uuid.uuid4() self.workflow_run_uri = self.workflow_run_uuid.urn # type: str self.generate_prov_doc()
def test_namespace_inheritance(self): prov_doc = ProvDocument() prov_doc.add_namespace('ex', 'http://www.example.org/') bundle = prov_doc.bundle('ex:bundle') e1 = bundle.entity('ex:e1') self.assertIsNotNone(e1.identifier, "e1's identifier is None!") self.do_tests(prov_doc)
def parse(self): """ Parse a result directory to extract the pieces information to be stored in NIDM-Results. """ # Methods: find_software, find_model_fitting, find_contrasts and # find_inferences should be defined in the children classes and return # a list of NIDM Objects as specified in the objects module # Object of type Software describing the neuroimaging software package # used for the analysis self.software = self._find_software() # List of objects of type ModelFitting describing the model fitting # step in NIDM-Results (main activity: Model Parameters Estimation) self.model_fittings = self._find_model_fitting() # Dictionary of (key, value) pairs where where key is a tuple # containing the identifier of a ModelParametersEstimation object and a # tuple of identifiers of ParameterEstimateMap objects and value is an # object of type Contrast describing the contrast estimation step in # NIDM-Results (main activity: Contrast Estimation) self.contrasts = self._find_contrasts() # Inference activity and entities # Dictionary of (key, value) pairs where key is the identifier of a # ContrastEstimation object and value is an object of type Inference # describing the inference step in NIDM-Results (main activity: # Inference) self.inferences = self._find_inferences() # Initialise prov document self.doc = ProvDocument() self._add_namespaces()
def postprocess(self, graph, url): """Prepend project identifier to identifiers of activities and entities. Add project identifier to node attributes of activities and entities.""" records = list(graph.get_records(ProvAgent)) id_map = {agent.identifier: agent.identifier for agent in records} project = url_encoded_path(url).replace("%2F", "/") for record in graph.get_records((ProvActivity, ProvEntity)): attributes = [*record.attributes, *record.formal_attributes] attributes.append(("project", project)) identifier = record.identifier namespace, localpart = identifier.namespace, identifier.localpart unique_id = QualifiedName(namespace, q_name(f"{project}-{localpart}")) id_map[identifier] = unique_id if isinstance(record, ProvEntity): records.append(ProvEntity(record.bundle, unique_id, attributes)) else: records.append( ProvActivity(record.bundle, unique_id, attributes)) records.extend(graph.get_records(ProvRelation)) graph = ProvDocument(records) graph = self.update_relations(graph, id_map) return graph
def test_references(tmp_path, monkeypatch): """Test1: references are replaced with bibtex.""" # Create fake provenance provenance = ProvDocument() provenance.add_namespace('file', uri=ESMVALTOOL_URI_PREFIX + 'file') provenance.add_namespace('attribute', uri=ESMVALTOOL_URI_PREFIX + 'attribute') filename = str(tmp_path / 'output.nc') attributes = { 'attribute:references': 'test_tag', 'attribute:script_file': 'diagnostics.py' } provenance.entity('file:' + filename, attributes) # Create fake bibtex references tag file references_path = tmp_path / 'references' references_path.mkdir() monkeypatch.setattr(esmvalcore._citation.DIAGNOSTICS, 'path', tmp_path) fake_bibtex_file = references_path / 'test_tag.bibtex' fake_bibtex = "Fake bibtex file content\n" fake_bibtex_file.write_text(fake_bibtex) _write_citation_files(filename, provenance) citation_file = tmp_path / 'output_citation.bibtex' citation = citation_file.read_text() assert citation == '\n'.join([ESMVALTOOL_PAPER, fake_bibtex])
def test_cmip6_data_citation_url(tmp_path): """Test3: CMIP6 info_url is retrieved from ES-DOC.""" # Create fake provenance provenance = ProvDocument() provenance.add_namespace('file', uri=ESMVALTOOL_URI_PREFIX + 'file') provenance.add_namespace('attribute', uri=ESMVALTOOL_URI_PREFIX + 'attribute') attributes = { 'attribute:mip_era': 'CMIP6', 'attribute:activity_id': 'activity', 'attribute:institution_id': 'institution', 'attribute:source_id': 'source', 'attribute:experiment_id': 'experiment', } filename = str(tmp_path / 'output.nc') provenance.entity('file:' + filename, attributes) _write_citation_files(filename, provenance) citation_url = tmp_path / 'output_data_citation_info.txt' # Create fake info url fake_url_prefix = '.'.join(attributes.values()) text = '\n'.join([ "Follow the links below to find more information about CMIP6 data:", f"- {CMIP6_URL_STEM}/cmip6?input={fake_url_prefix}", '', ]) assert citation_url.read_text() == text
def test_default_namespace_inheritance(self): prov_doc = ProvDocument() prov_doc.set_default_namespace("http://www.example.org/") bundle = prov_doc.bundle("bundle") e1 = bundle.entity("e1") self.assertIsNotNone(e1.identifier, "e1's identifier is None!") self.do_tests(prov_doc)
def base_connector_relation_parameter_example(): doc = ProvDocument() doc.add_namespace("ex", "http://example.com") doc.add_namespace("custom", "http://custom.com") namespaces = dict() namespaces.update({"ex": "http://example.com"}) namespaces.update({"custom": "http://custom.com"}) type_map = dict() type_map.update({"int value": "int"}) type_map.update({"date value": "xds:datetime"}) metadata = dict() metadata.update({METADATA_KEY_PROV_TYPE: PROV_RECORD_IDS_MAP["mentionOf"]}) metadata.update({METADATA_KEY_IDENTIFIER: "identifier for the relation"}) metadata.update({METADATA_KEY_TYPE_MAP: type_map}) metadata.update({METADATA_KEY_NAMESPACES: namespaces}) return_data = dict() return_data.update({"attributes": attributes_dict_example()}) return_data.update({"metadata": metadata}) return_data.update({"from_node": doc.valid_qualified_name("ex:Yoda")}) return_data.update( {"to_node": doc.valid_qualified_name("ex:Luke Skywalker")}) return_data.update({"doc": doc}) return return_data
def base_connector_bundle_parameter_example(): doc = ProvDocument() doc.add_namespace("ex", "http://example.com") attributes = dict() namespaces = dict() namespaces.update({"ex": "http://example.com"}) type_map = dict() type_map.update({"int value": "int"}) type_map.update({"date value": "xds:datetime"}) metadata = dict() metadata.update( {METADATA_KEY_PROV_TYPE: doc.valid_qualified_name("prov:Bundle")}) metadata.update( {METADATA_KEY_IDENTIFIER: doc.valid_qualified_name("ex:bundle name")}) metadata.update({METADATA_KEY_TYPE_MAP: type_map}) metadata.update({METADATA_KEY_NAMESPACES: namespaces}) return_data = dict() return_data.update({"attributes": attributes}) return_data.update({"metadata": metadata}) return return_data
def datatypes(): g = ProvDocument() ex = Namespace('ex', 'http://example.org/') g.add_namespace(ex) attributes = { 'ex:int': 100, 'ex:float': 100.123456, 'ex:long': 123456789000, 'ex:bool': True, 'ex:str': 'Some string', 'ex:unicode': u'Some unicode string with accents: Huỳnh Trung Đông', 'ex:timedate': datetime.datetime(2012, 12, 12, 14, 7, 48), 'ex:intstr': Literal("PROV Internationalized string", PROV["InternationalizedString"], "en"), } multiline = """Line1 Line2 Line3""" attributes['ex:multi-line'] = multiline g.entity('ex:e1', attributes) return g
def datatypes(): g = ProvDocument() ex = Namespace("ex", "http://example.org/") g.add_namespace(ex) attributes = { "ex:int": 100, "ex:float": 100.123456, "ex:long": 123456789000, "ex:bool": True, "ex:str": "Some string", "ex:unicode": "Some unicode string with accents: Huỳnh Trung Đông", "ex:timedate": datetime.datetime(2012, 12, 12, 14, 7, 48), "ex:intstr": Literal("PROV Internationalized string", PROV["InternationalizedString"], "en"), } multiline = """Line1 Line2 Line3""" attributes["ex:multi-line"] = multiline g.entity("ex:e1", attributes) return g
def enforce_uniqueness_constraints(graph: ProvDocument) -> ProvDocument: """Enforce model uniqueness constraints. Remove node duplicates: - ProvDocument.unified takes care of this by removing nodes with the same id. Remove relation duplicates: - Allow only one relation of a certain type between two nodes. Enforcing this constraint after having populated the model instead of during population simplifies the model creation. """ records, known = [], set() for relation in graph.get_records(ProvRelation): (_, source), (_, target) = relation.formal_attributes[:2] rel_tuple = (type(relation), source, target) if rel_tuple in known: continue known.add(rel_tuple) records.append(relation) records.extend(graph.get_records(ProvElement)) g = ProvDocument(records) return g.unified()
def test_xsd_qnames(self): prov_doc = ProvDocument() ex = Namespace('ex', 'http://www.example.org') prov_doc.add_namespace(ex) an_xsd_qname = XSDQName(ex['a_value']) prov_doc.entity('ex:e1', {'prov:value': an_xsd_qname}) self.assertPROVJSONRoundTripEquivalence(prov_doc)
def collections(): g = ProvDocument() ex = Namespace('ex', 'http://example.org/') c1 = g.collection(ex['c1']) e1 = g.entity('ex:e1') g.hadMember(c1, e1) return g
def document_with_n_bundles_having_default_namespace(n): prov_doc = ProvDocument() prov_doc.add_namespace('ex', 'http://www.example.org/') for i in range(n): x = str(i + 1) bundle = prov_doc.bundle('ex:bundle/' + x) bundle.set_default_namespace('http://www.example.org/default/' + x) bundle.entity('e') return prov_doc
def document_with_n_bundles_having_default_namespace(n): prov_doc = ProvDocument() prov_doc.add_namespace("ex", "http://www.example.org/") for i in range(n): x = str(i + 1) bundle = prov_doc.bundle("ex:bundle/" + x) bundle.set_default_namespace("http://www.example.org/default/" + x) bundle.entity("e") return prov_doc
def __init__( self, project, add_attributes=False, add_users=True, _add_project_namespaces=True, _iter_samples=True, _iter_project=True, ): """ Constructs the W3C-PROV document for a project. :param Project project: instance of bioprov.src.Project. :param bool add_attributes: whether to add object attributes. :param bool add_users: whether to add users and environments. :param bool _add_project_namespaces: :param bool _iter_samples: :param bool _iter_project: """ # Assert Project is good before constructing instance assert isinstance(project, Project), Warnings()["incorrect_type"](project, Project) self.ProvDocument = ProvDocument() self.project = project self.project.document = self.ProvDocument self._dot = prov_to_dot(self.ProvDocument) self._provn = self.ProvDocument.get_provn() self._entities = dict() self._activities = dict() self._agents = dict() self._user_bundles = dict() self._provstore_document = None # Don't add attributes if you plan on exporting to graphic format self.add_attributes = add_attributes # Set this before running Namespaces if add_users: self._create_envs_and_users = True else: self._create_envs_and_users = False # Default actions to create the document if _add_project_namespaces: self._add_project_namespaces() if self._create_envs_and_users: self._iter_envs_and_users() if _iter_project: self._iter_project() if _iter_samples: self._iter_samples()
def collections(): g = ProvDocument() ex = Namespace("ex", "http://example.org/") c1 = g.collection(ex["c1"]) e1 = g.entity("ex:e1") g.hadMember(c1, e1) return g
def bundles2(): # https://github.com/lucmoreau/ProvToolbox/blob/master/prov-n/src/test/resources/prov/bundles2.provn #=========================================================================== # document g = ProvDocument() # prefix ex <http://example.org/example/> g.add_namespace("ex", "http://www.example.com/") # prefix alice <http://example.org/alice/> # prefix bob <http://example.org/bob/> g.add_namespace('alice', 'http://example.org/alice/') g.add_namespace('bob', 'http://example.org/bob/') # entity(bob:bundle4, [prov:type='prov:Bundle']) # wasGeneratedBy(bob:bundle4, -, 2012-05-24T10:30:00) # agent(ex:Bob) # wasAttributedTo(bob:bundle4, ex:Bob) g.entity('bob:bundle4', {'prov:type': PROV['Bundle']}) g.wasGeneratedBy('bob:bundle4', time='2012-05-24T10:30:00') g.agent('ex:Bob') g.wasAttributedTo('bob:bundle4', 'ex:Bob') # entity(alice:bundle5, [ prov:type='prov:Bundle' ]) # wasGeneratedBy(alice:bundle5, -, 2012-05-25T11:15:00) # agent(ex:Alice) # wasAttributedTo(alice:bundle5, ex:Alice) g.entity('alice:bundle5', {'prov:type': PROV['Bundle']}) g.wasGeneratedBy('alice:bundle5', time='2012-05-25T11:15:00') g.agent('ex:Alice') g.wasAttributedTo('alice:bundle5', 'ex:Alice') # bundle bob:bundle4 # entity(ex:report1, [ prov:type="report", ex:version=1 ]) # wasGeneratedBy(ex:report1, -, 2012-05-24T10:00:01) # endBundle b4 = g.bundle('bob:bundle4') b4.entity('ex:report1', {'prov:type': "report", 'ex:version': 1}) b4.wasGeneratedBy('ex:report1', time='2012-05-24T10:00:01') # bundle alice:bundle5 # entity(ex:report1bis) # mentionOf(ex:report1bis, ex:report1, bob:bundle4) # entity(ex:report2, [ prov:type="report", ex:version=2 ]) # wasGeneratedBy(ex:report2, -, 2012-05-25T11:00:01) # wasDerivedFrom(ex:report2, ex:report1bis) # endBundle b5 = g.bundle('alice:bundle5') b5.entity('ex:report1bis') b5.mentionOf('ex:report1bis', 'ex:report1', 'bob:bundle4') b5.entity('ex:report2', [('prov:type', "report"), ('ex:version', 2)]) b5.wasGeneratedBy('ex:report2', time='2012-05-25T11:00:01') b5.wasDerivedFrom('ex:report2', 'ex:report1bis') # endDocument return g
def bundles2(): # https://github.com/lucmoreau/ProvToolbox/blob/master/prov-n/src/test/resources/prov/bundles2.provn # =========================================================================== # document g = ProvDocument() # prefix ex <http://example.org/example/> g.add_namespace("ex", "http://www.example.com/") # prefix alice <http://example.org/alice/> # prefix bob <http://example.org/bob/> g.add_namespace("alice", "http://example.org/alice/") g.add_namespace("bob", "http://example.org/bob/") # entity(bob:bundle4, [prov:type='prov:Bundle']) # wasGeneratedBy(bob:bundle4, -, 2012-05-24T10:30:00) # agent(ex:Bob) # wasAttributedTo(bob:bundle4, ex:Bob) g.entity("bob:bundle4", {"prov:type": PROV["Bundle"]}) g.wasGeneratedBy("bob:bundle4", time="2012-05-24T10:30:00") g.agent("ex:Bob") g.wasAttributedTo("bob:bundle4", "ex:Bob") # entity(alice:bundle5, [ prov:type='prov:Bundle' ]) # wasGeneratedBy(alice:bundle5, -, 2012-05-25T11:15:00) # agent(ex:Alice) # wasAttributedTo(alice:bundle5, ex:Alice) g.entity("alice:bundle5", {"prov:type": PROV["Bundle"]}) g.wasGeneratedBy("alice:bundle5", time="2012-05-25T11:15:00") g.agent("ex:Alice") g.wasAttributedTo("alice:bundle5", "ex:Alice") # bundle bob:bundle4 # entity(ex:report1, [ prov:type="report", ex:version=1 ]) # wasGeneratedBy(ex:report1, -, 2012-05-24T10:00:01) # endBundle b4 = g.bundle("bob:bundle4") b4.entity("ex:report1", {"prov:type": "report", "ex:version": 1}) b4.wasGeneratedBy("ex:report1", time="2012-05-24T10:00:01") # bundle alice:bundle5 # entity(ex:report1bis) # mentionOf(ex:report1bis, ex:report1, bob:bundle4) # entity(ex:report2, [ prov:type="report", ex:version=2 ]) # wasGeneratedBy(ex:report2, -, 2012-05-25T11:00:01) # wasDerivedFrom(ex:report2, ex:report1bis) # endBundle b5 = g.bundle("alice:bundle5") b5.entity("ex:report1bis") b5.mentionOf("ex:report1bis", "ex:report1", "bob:bundle4") b5.entity("ex:report2", [("prov:type", "report"), ("ex:version", 2)]) b5.wasGeneratedBy("ex:report2", time="2012-05-25T11:00:01") b5.wasDerivedFrom("ex:report2", "ex:report1bis") # endDocument return g
def get_esmvaltool_provenance(): """Create an esmvaltool run activity.""" provenance = ProvDocument() namespace = 'software' create_namespace(provenance, namespace) attributes = {} # TODO: add dependencies with versions here activity = provenance.activity(namespace + ':esmvaltool==' + __version__, other_attributes=attributes) return activity
def bundles1(): # https://github.com/lucmoreau/ProvToolbox/blob/master/prov-n/src/test/resources/prov/bundles1.provn # =============================================================================== # document g = ProvDocument() # prefix ex <http://example.org/example/> EX = Namespace("ex", "http://www.example.com/") g.add_namespace(EX) # prefix alice <http://example.org/alice/> # prefix bob <http://example.org/bob/> g.add_namespace("alice", "http://example.org/alice/") g.add_namespace("bob", "http://example.org/bob/") # entity(bob:bundle1, [prov:type='prov:Bundle']) g.entity("bob:bundle1", {"prov:type": PROV["Bundle"]}) # wasGeneratedBy(bob:bundle1, -, 2012-05-24T10:30:00) g.wasGeneratedBy("bob:bundle1", time="2012-05-24T10:30:00") # agent(ex:Bob) g.agent("ex:Bob") # wasAttributedTo(bob:bundle1, ex:Bob) g.wasAttributedTo("bob:bundle1", "ex:Bob") # entity(alice:bundle2, [ prov:type='prov:Bundle' ]) g.entity("alice:bundle2", {"prov:type": PROV["Bundle"]}) # wasGeneratedBy(alice:bundle2, -, 2012-05-25T11:15:00) g.wasGeneratedBy("alice:bundle2", time="2012-05-25T11:15:00") # agent(ex:Alice) g.agent("ex:Alice") # wasAttributedTo(alice:bundle2, ex:Alice) g.wasAttributedTo("alice:bundle2", "ex:Alice") # bundle bob:bundle1 b1 = g.bundle("bob:bundle1") # entity(ex:report1, [ prov:type="report", ex:version=1 ]) b1.entity("ex:report1", {"prov:type": "report", "ex:version": 1}) # wasGeneratedBy(ex:report1, -, 2012-05-24T10:00:01) b1.wasGeneratedBy("ex:report1", time="2012-05-24T10:00:01") # endBundle # bundle alice:bundle2 b2 = g.bundle("alice:bundle2") # entity(ex:report1) b2.entity("ex:report1") # entity(ex:report2, [ prov:type="report", ex:version=2 ]) b2.entity("ex:report2", {"prov:type": "report", "ex:version": 2}) # wasGeneratedBy(ex:report2, -, 2012-05-25T11:00:01) b2.wasGeneratedBy("ex:report2", time="2012-05-25T11:00:01") # wasDerivedFrom(ex:report2, ex:report1) b2.wasDerivedFrom("ex:report2", "ex:report1") # endBundle # endDocument return g
def start(self, workflow=False): from daops import __version__ as daops_version from flamingo import __version__ as flamingo_version self.doc = ProvDocument() # Declaring namespaces for various prefixes self.doc.set_default_namespace(uri="http://purl.org/roocs/prov#") self.doc.add_namespace("prov", uri="http://www.w3.org/ns/prov#") self.doc.add_namespace( "provone", uri="http://purl.dataone.org/provone/2015/01/15/ontology#") self.doc.add_namespace("dcterms", uri="http://purl.org/dc/terms/") # Define entities project_cds = self.doc.agent( ":copernicus_CDS", { "prov:type": "prov:Organization", "dcterms:title": "Copernicus Climate Data Store", }, ) self.sw_flamingo = self.doc.agent( ":flamingo", { "prov:type": "prov:SoftwareAgent", "dcterms:source": f"https://github.com/cedadev/flamingo/releases/tag/v{flamingo_version}", }, ) self.doc.wasAttributedTo(self.sw_flamingo, project_cds) self.sw_daops = self.doc.agent( ":daops", { "prov:type": "prov:SoftwareAgent", "dcterms:source": f"https://github.com/roocs/daops/releases/tag/v{daops_version}", }, ) # workflow if workflow is True: self.workflow = self.doc.entity(":workflow", {"prov:type": "provone:Workflow"}) orchestrate = self.doc.activity( ":orchestrate", other_attributes={ "prov:startedAtTime": "2020-11-26T09:15:00", "prov:endedAtTime": "2020-11-26T09:30:00", }, ) self.doc.wasAssociatedWith(orchestrate, agent=self.sw_flamingo, plan=self.workflow)