예제 #1
0
    def export(self, nidm_version, export_dir):
        """
        Create prov entities and activities.
        """
        if nidm_version['num'] in ["1.0.0", "1.1.0"]:
            self.label = self.label.replace("Supra-Threshold", "Significant")

        # FIXME deal with multiple contrasts
        atts = ((PROV['type'], NIDM_SIGNIFICANT_CLUSTER),
                (PROV['label'], self.label), (NIDM_CLUSTER_LABEL_ID, self.num),
                (NIDM_CLUSTER_SIZE_IN_VOXELS, self.size))

        if self.clust_size_resels is not None:
            atts = atts + (
                (NIDM_CLUSTER_SIZE_IN_RESELS, self.clust_size_resels), )

        if self.punc is not None:
            atts = atts + ((NIDM_P_VALUE_UNCORRECTED,
                            Literal(self.punc, datatype=XSD_FLOAT)), )

        if self.pFDR is not None:
            atts = atts + (
                (NIDM_Q_VALUE_FDR, Literal(self.pFDR, datatype=XSD_FLOAT)), )

        if self.pFWER is not None:
            atts = atts + (
                (NIDM_P_VALUE_FWER, Literal(self.pFWER, datatype=XSD_FLOAT)), )

        self.add_attributes(atts)
예제 #2
0
    def export(self, nidm_version, export_dir):
        """
        Create prov entities and activities.
        """
        if self.p_unc is None:
            norm_cdf_z = (1.0 + erf(self.equiv_z / sqrt(2.0))) / 2.0
            self.p_unc = 1 - norm_cdf_z

        atts = ((PROV['type'], self.type), (PROV['label'], self.label),
                (PROV['location'], self.coordinate.id))

        if self.value is not None:
            atts = atts + ((PROV['value'], self.value), )

        if self.p_unc is not None:
            atts = atts + ((NIDM_P_VALUE_UNCORRECTED,
                            Literal(self.p_unc, datatype=XSD_FLOAT)), )

        if self.equiv_z is not None:
            atts = atts + ((NIDM_EQUIVALENT_ZSTATISTIC,
                            Literal(self.equiv_z, datatype=XSD_FLOAT)), )

        if self.p_fdr is not None:
            atts = atts + (
                (NIDM_Q_VALUE_FDR, Literal(self.p_fdr, datatype=XSD_FLOAT)), )

        if self.p_fwer is not None:
            atts = atts + ((NIDM_P_VALUE_FWER,
                            Literal(self.p_fwer, datatype=XSD_FLOAT)), )

        self.add_attributes(atts)
예제 #3
0
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
예제 #4
0
파일: provrdf.py 프로젝트: vreuter/prov
 def decode_rdf_representation(self, literal, graph):
     if isinstance(literal, RDFLiteral):
         value = literal.value if literal.value is not None else literal
         datatype = literal.datatype if hasattr(literal,
                                                'datatype') else None
         langtag = literal.language if hasattr(literal,
                                               'language') else None
         if datatype and 'XMLLiteral' in datatype:
             value = literal
         if datatype and 'base64Binary' in datatype:
             value = base64.standard_b64encode(value)
         if datatype == XSD['QName']:
             return pm.Literal(literal, datatype=XSD_QNAME)
         if datatype == XSD['dateTime']:
             return dateutil.parser.parse(literal)
         else:
             # The literal of standard Python types is not converted here
             # It will be automatically converted when added to a record by _auto_literal_conversion()
             return Literal(value, self.valid_identifier(datatype), langtag)
     elif isinstance(literal, URIRef):
         rval = self.valid_identifier(literal)
         if rval is None:
             prefix, iri, _ = graph.namespace_manager.compute_qname(literal)
             ns = self.document.add_namespace(prefix, iri)
             rval = pm.QualifiedName(ns, literal.replace(ns.uri, ''))
         return rval
     else:
         # simple type, just return it
         return literal
예제 #5
0
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
예제 #6
0
def decode_json_representation(value, type, bundle):
    """
    Return the value based on the type see also encode_json_representation

    :param value:
    :param type:
    :param bundle:
    :return:
    """
    if isinstance(type, dict):
        # complex type
        datatype = type['type'] if 'type' in type else None
        datatype = bundle.valid_qualified_name(datatype)
        langtag = type['lang'] if 'lang' in type else None
        if datatype == XSD_ANYURI:
            return Identifier(value)
        elif datatype == PROV_QUALIFIEDNAME:
            return bundle.valid_qualified_name(value)
        else:
            # The literal of standard Python types is not converted here
            # It will be automatically converted when added to a record by
            # _auto_literal_conversion()
            return Literal(value, datatype, langtag)
    else:
        # simple type, just return it
        return value
예제 #7
0
    def export(self, nidm_version, export_dir):
        """
        Create prov entities and activities.
        """
        if nidm_version['major'] < 1 or \
                (nidm_version['major'] == 1 and nidm_version['minor'] < 3):
            self.type = NLX_OLD_FSL

        atts = ((PROV['type'], self.type), (PROV['type'],
                                            PROV['SoftwareAgent']),
                (PROV['label'], Literal(self.label, datatype=XSD_STRING)),
                (NIDM_SOFTWARE_VERSION, self.version))

        if self.feat_version:
            atts = atts + ((FSL_FEAT_VERSION, self.feat_version), )

        self.add_attributes(atts)
예제 #8
0
파일: provjson.py 프로젝트: vreuter/prov
def decode_json_representation(literal, bundle):
    if isinstance(literal, dict):
        # complex type
        value = literal['$']
        datatype = literal['type'] if 'type' in literal else None
        datatype = valid_qualified_name(bundle, datatype)
        langtag = literal['lang'] if 'lang' in literal else None
        if datatype == XSD_ANYURI:
            return Identifier(value)
        elif datatype == PROV_QUALIFIEDNAME:
            return valid_qualified_name(bundle, value)
        else:
            # The literal of standard Python types is not converted here
            # It will be automatically converted when added to a record by
            # _auto_literal_conversion()
            return Literal(value, datatype, langtag)
    else:
        # simple type, just return it
        return literal
 def test_literal_provn_with_triple_quotes(self):
     l = Literal('"""foo\\nbar"""')
     string_rep = l.provn_representation()
     self.assertTrue('\\"\\"\\"f' in string_rep)
 def test_literal_provn_with_single_quotes(self):
     l = Literal('{"foo": "bar"}')
     string_rep = l.provn_representation()
     self.assertTrue('{\\"f' in string_rep)
예제 #11
0
    VOPROV_ATTR_REFERRER,
})

VOPROV_ATTR_TIME = VOPROV['time']
VOPROV_ATTR_STARTTIME = VOPROV['startTime']
VOPROV_ATTR_ENDTIME = VOPROV['endTime']

#   adding the voprov identifier for the literals attribute
PROV_ATTRIBUTE_LITERALS.update({
    # update of prov literals to voprov literals
    VOPROV_ATTR_TIME,
    VOPROV_ATTR_STARTTIME,
    VOPROV_ATTR_ENDTIME,

    # voprov description
    Literal(VOPROV_ATTR_NAME),
    Literal(VOPROV_ATTR_ROLE),
    Literal(VOPROV_ATTR_VALUE_TYPE),
    Literal(VOPROV_ATTR_CONTENT_TYPE),

    # voprov configuration
    Literal(VOPROV_ATTR_LOCATION),
    Literal(VOPROV_ATTR_VALUE),
    Literal(VOPROV_ATTR_ARTEFACT_TYPE),
})

# Extra definition for convenience
VOPROV_TYPE = VOPROV['type']
VOPROV_LABEL = VOPROV['label']
VOPROV_VALUE = VOPROV['value']
VOPROV_LOCATION = VOPROV['location']
예제 #12
0
파일: test_model.py 프로젝트: cmaumet/prov
 def test_literal_provn_with_triple_quotes(self):
     l = Literal('"""foo\\nbar"""')
     string_rep = l.provn_representation()
     self.assertTrue('\\"\\"\\"f' in string_rep)
예제 #13
0
파일: test_model.py 프로젝트: cmaumet/prov
 def test_literal_provn_with_single_quotes(self):
     l = Literal('{"foo": "bar"}')
     string_rep = l.provn_representation()
     self.assertTrue('{\\"f' in string_rep)
예제 #14
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)