Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: PrefLabels added & mapping between BIDS/NIDM-E #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

natachaperez
Copy link
Contributor

we add a PrefLabel for each attribute in the nidm-experiment.owl file to associate with the type:
http://www.w3.org/2004/02/skos/core#prefLabel "attribute name".
Then I created the nidme.json file to map JSON attributes in BIDS to NIDM-experiment URLs in the model of : https://github.com/incf-nidash/nidm-specs/blob/master/nidm/nidm-results/terms/nidmr.json.

@khelm
Copy link
Contributor

khelm commented Jul 30, 2019

Hi @natachaperez
The following terms are currently defined in the NIDM-E OWL file:

"ImagingInstrument": "http://uri.neuinfo.org/nif/nifstd/birnlex_2094", 
    "MagneticResonanceImagingScanner": "http://uri.neuinfo.org/nif/nifstd/birnlex_2100", 
    "MRIProtocol": "http://uri.neuinfo.org/nif/nifstd/birnlex_2177", 
    "FunctionalMRIProtocol": "http://uri.neuinfo.org/nif/nifstd/birnlex_2250", 
    "StructuralMRIProtocol": "http://uri.neuinfo.org/nif/nifstd/birnlex_2251", 
    "PositronEmissionTomographyScanner": "http://uri.neuinfo.org/nif/nifstd/ixl_0050000", 
    "SinglePhotonEmissionComputedTomographyScanner": "http://uri.neuinfo.org/nif/nifstd/ixl_0050001", 
    "MagnetoencephalographyMachine": "http://uri.neuinfo.org/nif/nifstd/ixl_0050002", 
    "ElectroencephalographyMachine": "http://uri.neuinfo.org/nif/nifstd/ixl_0050003", 
    "AnatomicalMRIProtocol": "http://uri.neuinfo.org/nif/nifstd/ixl_0050004", 
"DiffusionWeightedImagingProtocol": "http://uri.neuinfo.org/nif/nifstd/nlx_inv_20090249"

using what I believe is a more consistent naming convention, so you might want to take a look there before using these versions.

@natachaperez
Copy link
Contributor Author

 @khelm Could you specify me the corresponding lines in the NIDM-E owl files?
Cause the nidme json document above is generated by essentially using these following lines on PyNIDM/nidm/experiment/Core.py (with some changes made by myself) :

def createDefaultJSONLDcontext(self):

    from nidm.experiment.Utils import load_nidm_owl_files
    from nidm.core.Constants import namespaces

    #load current OWL files
    term_graph=load_nidm_owl_files()

    context=OrderedDict()
    context['@version'] = 1.1
    context['records'] = OrderedDict()
    context['records']['@id'] = "@graph"
    context['records']['@container'] = "@type"
    context['xsd'] = "http://www.w3.org/2001/XMLSchema#"
    context['prov'] = "http://www.w3.org/ns/prov#"
    context['agent'] = "http://www.w3.org/ns/prov#agent"
    context['entity'] = "http://www.w3.org/ns/prov#entity"
    context['activity'] = "http://www.w3.org/ns/prov#activity" 
    context['hadPlan'] = "http://www.w3.org/ns/prov#hadPlan"
    context['hadRole'] = "http://www.w3.org/ns/prov#hadRole"
    context['wasAttributedTo'] = "http://www.w3.org/ns/prov#wasAttributedTo"
    context['association'] = "http://www.w3.org/ns/prov#association"
    context['usage'] = "http://www.w3.org/ns/prov#usage"
    context['generation'] = "http://www.w3.org/ns/prov#generation"
    context['startedAtTime'] = OrderedDict()
    context['startedAtTime']['@id'] = "http://www.w3.org/ns/prov#startedAtTime"
    context['startedAtTime']['@type'] = "http://www.w3.org/2001/XMLSchema#dateTime"
    context['endedAtTime'] = OrderedDict()
    context['endedAtTime']['@id'] = "http://www.w3.org/ns/prov#endedAtTime"
    context['endedAtTime']['@type'] = "http://www.w3.org/2001/XMLSchema#dateTime"

    #load Constants.namespaces
    #context.update(Constants.namespaces)

    """context.update ({
        "xsd": {"@type": "@id","@id":"http://www.w3.org/2001/XMLSchema#"},
        "prov": {"@type": "@id","@id":"http://www.w3.org/ns/prov#"},
        "agent": { "@type": "@id", "@id": "prov:agent" },
        "entity": { "@type": "@id", "@id": "prov:entity" },
        "activity": { "@type": "@id", "@id": "prov:activity" },
        "hadPlan": { "@type": "@id", "@id": "prov:hadPlan" },
        "hadRole": { "@type": "@id", "@id": "prov:hadRole" },
        "wasAttributedTo": { "@type": "@id", "@id": "prov:wasAttributedTo" },
        "association": { "@type": "@id", "@id": "prov:qualifiedAssociation" },
        "usage": { "@type": "@id", "@id": "prov:qualifiedUsage" },
        "generation": { "@type": "@id", "@id": "prov:qualifiedGeneration" },
        "startedAtTime": { "@type": "xsd:dateTime", "@id": "prov:startedAtTime" },
        "endedAtTime": { "@type": "xsd:dateTime", "@id": "prov:endedAtTime" },
    })"""


    #add namespaces from Constants.namespaces
    for key,value in namespaces.items():
        #context['@context'][key] = value
        context[key] = value

    #add terms from Constants.nidm_experiment_terms
    for term in Constants.nidm_experiment_terms:
        #context['@context'][term.localpart] = term.uri
        context[term.localpart] = term.uri


    #add prefix's from current document...this accounts for new terms
    context.update ( self.prefix_to_context() )

    #WIP
    #link toward nidm-experiment owl file and 
    owls = '/udd/nperez/softs/nidm-specs/nidm/nidm-experiment/terms/nidm-experiment.owl'
    
    owl_imports = glob.glob(os.path.join(os.path.dirname(owls),os.pardir, os.pardir, "imports", '*.ttl'))

    # OwlReader to read and extract informations in owl file 
    owl = OwlReader(owls, import_owl_files=owl_imports)
    
    #cycle through OWL graph and add terms
    # For anything that has a label

    #for s, o in sorted(term_graph.subject_objects(Constants.RDFS['label'])):
    #    json_key = str(o)
    #    if '_' in json_key:
    #        json_key = str(o).split('_')[1]
    #    context['@context'][json_key] = OrderedDict()

    #    if s in term_graph.ranges:
    #        context['@context'][json_key]['@id'] = str(s)
    #        context['@context'][json_key]['@type'] = next(iter(term_graph.ranges[s]))
    #    else:
    #        context['@context'][json_key] = str(s)
   
    for s, o in sorted(owl.graph.subject_objects(Constants.SKOS['prefLabel'])):
        json_key = str(o)
        context[json_key] = OrderedDict()
        if s in owl.ranges:
            ranges = next(iter(owl.ranges[s]))
            if 'http://www.w3.org/2001/XMLSchema#int' in ranges or 'http://www.w3.org/2001/XMLSchema#double' in ranges or 'http://www.w3.org/2001/XMLSchema#integer' in ranges or  'http://www.w3.org/2001/XMLSchema#positiveInteger' in ranges:
                context[json_key]['@id'] = str(s)
                context[json_key]['@type'] = ranges
            else:
                context[json_key] = str(s)
        else:
            context[json_key] = str(s)
            
    return context

and I use the nidm-e owl file to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants