Example #1
0
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
Example #2
0
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_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 insert_document_with_bundles(instance):
    args_record = base_connector_record_parameter_example()
    args_bundle = base_connector_bundle_parameter_example()
    doc = ProvDocument()
    doc.add_namespace("ex", "http://example.com")
    # document with 1 record
    doc_id = instance.save_document()
    doc_record_id = instance.save_record(doc_id, args_record["attributes"], args_record["metadata"])

    # bundle with 1 record
    bundle_id = instance.save_bundle(doc_id, args_bundle["attributes"], args_bundle["metadata"])
    bundle_record_id = instance.save_record(bundle_id, args_record["attributes"], args_record["metadata"])

    # add relation

    from_record_args = base_connector_record_parameter_example()
    to_record_args = base_connector_record_parameter_example()
    relation_args = base_connector_relation_parameter_example()

    from_label = doc.valid_qualified_name("ex:FROM NODE")
    to_label = doc.valid_qualified_name("ex:TO NODE")
    from_record_args["metadata"][METADATA_KEY_IDENTIFIER] = from_label
    to_record_args["metadata"][METADATA_KEY_IDENTIFIER] = to_label

    from_record_id = instance.save_record(doc_id, from_record_args["attributes"], from_record_args["metadata"])
    to_record_id = instance.save_record(doc_id, to_record_args["attributes"], to_record_args["metadata"])

    relation_id = instance.save_relation(doc_id, from_label, doc_id, to_label, relation_args["attributes"],
                                         relation_args["metadata"])

    return {
        "relation_id": relation_id,
        "from_record_id": from_record_id,
        "to_record_id": to_record_id,
        "bundle_id": bundle_id,
        "bundle_record_id": bundle_record_id,
        "doc_id": doc_id,
        "doc_record_id": doc_record_id
    }
Example #6
0
    def test_get_element_invalid(self):
        """
        Test get element with error

        """

        with self.assertRaises(InvalidArgumentTypeException):
            self.provapi.get_element(None)

        with self.assertRaises(NotFoundException):
            doc = ProvDocument()
            name = doc.valid_qualified_name("prov:Some unused name")
            self.provapi.get_element(name)
Example #7
0
    def _create_unknown_node(self, bundle_id):
        """
        If a relation end or start is "Unknown" (yes this is allowed in PROV) we create a specific node to create the relation
        :param bundle_id: The database bundle id
        :return: The identifier of the Unknown node
        """
        uid = uuid4()
        doc = ProvDocument()
        identifier = doc.valid_qualified_name("prov:Unknown-{}".format(uid))
        record = ProvRecord(bundle=doc, identifier=identifier)

        (metadata,
         attributes) = self._get_metadata_and_attributes_for_record(record)
        self._adapter.save_record(bundle_id, attributes, metadata)
        return identifier
Example #8
0
def prov_api_record_example():
    doc = ProvDocument()
    doc.add_namespace("ex", "http://example.com")
    doc.add_namespace("custom", "http://custom.com")

    attributes = attributes_dict_example()
    del attributes[
        "ex:dict value"]  # remove dict value because it is not allowed in a prov_record, but for low level adapter tests necessary
    del attributes[
        "ex:list value"]  # remove dict value because it is not allowed in a prov_record, but for low level adapter tests necessary
    attributes.update({
        "ex:Qualified name ":
        doc.valid_qualified_name("custom:qualified name")
    })
    attributes.update({"ex:Qualified name 2": "ex:unqualified_name"})
    attributes.update({"ex:Literal": Literal("test literal", langtag="en")})
    attributes.update({
        "ex:Literal 2":
        Literal("test literal with datatype",
                langtag="en",
                datatype=PROV["InternationalizedString"])
    })
    attributes.update(
        {"ex:identifier type": Identifier("http://example.com/#test")})

    expected_attributes = dict()
    for key, value in attributes.items():
        new_key = doc.valid_qualified_name(key)
        expected_attributes.update({new_key: value})

    # The prov lib don't require to auto convert string values into qualified names
    # valid_name = doc.valid_qualified_name("ex:Qualified name 2")
    # expected_attributes[valid_name] = doc.valid_qualified_name("ex:unqualified_name")

    namespaces = dict()
    namespaces.update({"ex": "http://example.com"})
    namespaces.update({"custom": "http://custom.com"})
    namespaces.update({"prov": "http://www.w3.org/ns/prov#"})

    type_map = dict()
    type_map.update({"ex:date value": {"type": "xsd:dateTime"}})
    type_map.update({"ex:double value": {"type": "xsd:double"}})
    type_map.update({"ex:int value": {"type": "xsd:int"}})

    type_map.update({"ex:Qualified name ": {'type': 'prov:QUALIFIED_NAME'}})
    # type_map.update({"ex:Qualified name 2":{'type': 'prov:QUALIFIED_NAME'}}) #The prov lib don't require to auto convert strings into qualified names
    type_map.update({"ex:Literal": {'lang': 'en'}})
    type_map.update({"ex:Literal 2": {'lang': 'en'}})
    type_map.update({"ex:identifier type": {'type': 'xsd:anyURI'}})

    metadata = dict()
    metadata.update({METADATA_KEY_PROV_TYPE: PROV_RECORD_IDS_MAP["activity"]})
    metadata.update(
        {METADATA_KEY_IDENTIFIER: doc.valid_qualified_name("ex:record")})
    metadata.update({METADATA_KEY_NAMESPACES: namespaces})
    metadata.update({METADATA_KEY_TYPE_MAP: type_map})

    record = ProvActivity(doc, "ex:record", attributes)
    Example = namedtuple(
        "prov_api_metadata_record_example",
        "metadata, attributes, prov_record, expected_attributes")

    return Example(metadata, attributes, record, expected_attributes)