Пример #1
0
 def get_w3c(self, bundle=None):
     """get this element in the prov version which is an implementation of the W3C PROV-DM standard"""
     if bundle is None:
         bundle = ProvBundle()
     w3c_record = ProvEntity(bundle, self.identifier, self.attributes)
     w3c_record.add_asserted_type(self._prov_type)  # self.__class__.__name__)
     return bundle.add_record(w3c_record)
Пример #2
0
 def get_w3c(self, bundle=None):
     if bundle is None:
         bundle = ProvBundle()
     w3c_record = ProvEntity(bundle, self.identifier, self.attributes)
     w3c_record.add_asserted_type(
         self._prov_type)  # self.__class__.__name__)
     return bundle.add_record(w3c_record)
Пример #3
0
def decode_json_document(content, document):
    bundles = dict()
    if 'bundle' in content:
        bundles = content['bundle']
        del content['bundle']

    decode_json_container(content, document)

    for bundle_id, bundle_content in bundles.items():
        bundle = ProvBundle(document=document)
        decode_json_container(bundle_content, bundle)
        document.add_bundle(bundle, bundle.valid_qualified_name(bundle_id))
Пример #4
0
    def _create_bundle(self, version):
        """
        Initialise NIDM-Results bundle.
        """
        # *** Bundle entity
        if not hasattr(self, 'bundle_ent'):
            self.bundle_ent = NIDMResultsBundle(nidm_version=version['num'])

        self.bundle = ProvBundle(identifier=self.bundle_ent.id)

        self.bundle_ent.export(self.version, self.export_dir)

        # # provn export
        # self.bundle = ProvBundle(identifier=bundle_id)

        self.doc.entity(self.bundle_ent.id,
                        other_attributes=self.bundle_ent.attributes)

        # *** NIDM-Results Export Activity
        if version['num'] not in ["1.0.0", "1.1.0"]:
            if not hasattr(self, 'export_act'):
                self.export_act = NIDMResultsExport()
            self.export_act.export(self.version, self.export_dir)
            # self.doc.update(self.export_act.p)
            self.doc.activity(self.export_act.id,
                              other_attributes=self.export_act.attributes)

        # *** bundle was Generated by NIDM-Results Export Activity
        if not hasattr(self, 'export_time'):
            self.export_time = str(datetime.datetime.now().time())

        if version['num'] in ["1.0.0", "1.1.0"]:
            self.doc.wasGeneratedBy(entity=self.bundle_ent.id,
                                    time=self.export_time)
        else:
            # provn
            self.doc.wasGeneratedBy(entity=self.bundle_ent.id,
                                    activity=self.export_act.id,
                                    time=self.export_time)

        # *** NIDM-Results Exporter (Software Agent)
        if version['num'] not in ["1.0.0", "1.1.0"]:
            if not hasattr(self, 'exporter'):
                self.exporter = self._get_exporter()
            self.exporter.export(self.version, self.export_dir)
            # self.doc.update(self.exporter.p)
            self.doc.agent(self.exporter.id,
                           other_attributes=self.exporter.attributes)

            self.doc.wasAssociatedWith(self.export_act.id, self.exporter.id)
Пример #5
0
    def get_w3c(self, bundle=None):
        """get this relation in the prov version which is an implementation of the W3C PROV-DM standard"""
        if bundle is None:
            bundle = ProvBundle()
        attribute = self.extra_attributes
        relation_formal_attribute = self.formal_attributes[0:2]

        w3c_record = ProvInfluence(bundle, self.identifier, attribute)
        namespaces = [list(i) for i in w3c_record.formal_attributes]
        for i in range(0, 2):
            namespaces[i][1] = relation_formal_attribute[i][1]
        w3c_record.add_attributes(namespaces)
        w3c_record.add_asserted_type(
            self._prov_type)  # self.__class__.__name__)
        return bundle.add_record(w3c_record)
    def test_add_bundle_document(self):
        d1 = self.document_1()
        d2 = self.document_2()

        def sub_test_1():
            d1.add_bundle(d2)

        self.assertRaises(ProvException, sub_test_1)

        ex2_b2 = d2.valid_qualified_name('ex:b2')
        d1.add_bundle(d2, 'ex:b2')
        self.assertEqual(ex2_b2, first(d1.bundles).identifier)
        self.assertNotIn(d2, d1.bundles)
        b2 = ProvBundle()
        b2.update(d2)
        self.assertIn(b2, d1.bundles)
Пример #7
0
    def _create_bundle(self, version):
        """ 
        Initialise NIDM-Results bundle.
        """
        software_lc = self.software.name.lower()
        software_uc = self.software.name.upper()

        bundle_id = NIIRI[str(uuid.uuid4())]
        self.bundle = ProvBundle(identifier=bundle_id)

        self.doc.entity(bundle_id,
                        other_attributes=((
                            PROV['type'],
                            PROV['Bundle'],
                        ), (PROV['label'], software_uc + " Results"),
                                          (NIDM['objectModel'],
                                           NIDM[software_uc + 'Results']),
                                          (NIDM['version'], version)))

        self.doc.wasGeneratedBy(NIIRI[software_lc + '_results_id'],
                                time=str(datetime.datetime.now().time()))
    def test_add_bundle_simple(self):
        d1 = self.document_1()
        b0 = self.bundle_0()

        def sub_test_1():
            d1.add_bundle(b0)

        self.assertRaises(ProvException, sub_test_1)
        self.assertFalse(d1.has_bundles())

        d1.add_bundle(b0, 'ex:b0')
        self.assertTrue(d1.has_bundles())
        self.assertIn(b0, d1.bundles)

        def sub_test_2():
            ex2_b0 = b0.identifier
            d1.add_bundle(ProvBundle(identifier=ex2_b0))

        self.assertRaises(ProvException, sub_test_2)

        d1.add_bundle(ProvBundle(), 'ex:b0')
        self.assertEqual(len(d1.bundles), 2)
 def sub_test_2():
     ex2_b0 = b0.identifier
     d1.add_bundle(ProvBundle(identifier=ex2_b0))
 def bundle_0(self):
     b = ProvBundle(namespaces={'ex': EX2_URI})
     return b
Пример #11
0
 def __init__(self, export_dir=None, coordinate_space_id=None):
     self.export_dir = export_dir
     self.coordinate_space_id = coordinate_space_id
     self.p = ProvBundle()
     self.id = None