Skip to content

Commit

Permalink
fix predicates used to camelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Mar 20, 2024
1 parent 7ddcf1e commit 37318af
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 75 deletions.
4 changes: 2 additions & 2 deletions backend/src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ async def __call__(self, request: Request) -> Optional[str]:


auth_params = {
# "audience": "https://explorer.icare4cvd.eu",
"audience": "https://other-ihi-app",
"audience": "https://explorer.icare4cvd.eu",
# "audience": "https://other-ihi-app",
"redirect_uri": settings.redirect_uri,
}

Expand Down
8 changes: 4 additions & 4 deletions backend/src/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,25 @@ async def search_concepts(
}}
GRAPH ?cohortVarGraph {{
?cohort icare:has_variable ?variable .
?cohort icare:hasVariable ?variable .
?variable a icare:Variable ;
dc:identifier ?varName ;
rdfs:label ?varLabel ;
icare:var_type ?varType ;
icare:varType ?varType ;
icare:index ?index .
OPTIONAL {{ ?variable icare:omop ?omopDomain }}
}}
{{
GRAPH ?cohortMappingsGraph {{
?variable icare:mapped_id ?mappedId .
?variable icare:mappedId ?mappedId .
}}
}} UNION {{
GRAPH ?cohortVarGraph {{
?variable icare:categories ?category.
}}
GRAPH ?cohortMappingsGraph {{
?category icare:mapped_id ?mappedId .
?category icare:mappedId ?mappedId .
}}
}}
OPTIONAL {{ ?mappedId rdfs:label ?mappedLabel }}
Expand Down
27 changes: 16 additions & 11 deletions backend/src/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
from datetime import datetime
from typing import Any
from re import sub

import pandas as pd
import requests
Expand Down Expand Up @@ -164,6 +165,10 @@ def create_uri_from_id(row):
ACCEPTED_DATATYPES = ["STR", "FLOAT", "INT", "DATETIME"]


def to_camelcase(s: str) -> str:
s = sub(r"(_|-)+", " ", s).title().replace(" ", "")
return ''.join([s[0].lower(), s[1:]])

def load_cohort_dict_file(dict_path: str, cohort_id: str, user_email: str) -> Dataset:
"""Parse the cohort dictionary uploaded as excel or CSV spreadsheet, and load it to the triplestore"""
# print(f"Loading dictionary {dict_path}")
Expand Down Expand Up @@ -199,7 +204,7 @@ def load_cohort_dict_file(dict_path: str, cohort_id: str, user_email: str) -> Da

# Create a URI for the variable
variable_uri = get_var_uri(cohort_id, row["VARIABLE NAME"])
g.add((cohort_uri, ICARE.has_variable, variable_uri, cohort_uri))
g.add((cohort_uri, ICARE.hasVariable, variable_uri, cohort_uri))

# Add the type of the resource
g.add((variable_uri, RDF.type, ICARE.Variable, cohort_uri))
Expand All @@ -211,7 +216,7 @@ def load_cohort_dict_file(dict_path: str, cohort_id: str, user_email: str) -> Da
for column, value in row.items():
# if value and column not in ["categories"]:
if column not in ["categories"] and value:
property_uri = ICARE[column.replace(" ", "_").lower()]
property_uri = ICARE[to_camelcase(column)]
if (
isinstance(value, str)
and (value.startswith("http://") or value.startswith("https://"))
Expand All @@ -230,8 +235,8 @@ def load_cohort_dict_file(dict_path: str, cohort_id: str, user_email: str) -> Da
continue
for index, category in enumerate(value):
cat_uri = get_category_uri(variable_uri, index)
g.add((variable_uri, ICARE["categories"], cat_uri, cohort_uri))
g.add((cat_uri, RDF.type, ICARE.Category, cohort_uri))
g.add((variable_uri, ICARE.categories, cat_uri, cohort_uri))
g.add((cat_uri, RDF.type, ICARE.VariableCategory, cohort_uri))
g.add((cat_uri, RDF.value, Literal(category["value"]), cohort_uri))
g.add((cat_uri, RDFS.label, Literal(category["label"]), cohort_uri))
# TODO: add categories
Expand Down Expand Up @@ -359,19 +364,19 @@ def cohorts_metadata_file_to_graph(filepath: str) -> Dataset:
for email in row["Email"].split(";"):
g.add((cohort_uri, ICARE.email, Literal(email.strip()), cohorts_graph))
if row["Type"]:
g.add((cohort_uri, ICARE.cohort_type, Literal(row["Type"]), cohorts_graph))
g.add((cohort_uri, ICARE.cohortType, Literal(row["Type"]), cohorts_graph))
if row["Study type"]:
g.add((cohort_uri, ICARE.study_type, Literal(row["Study type"]), cohorts_graph))
g.add((cohort_uri, ICARE.studyType, Literal(row["Study type"]), cohorts_graph))
if row["N"]:
g.add((cohort_uri, ICARE.study_participants, Literal(row["N"]), cohorts_graph))
g.add((cohort_uri, ICARE.studyParticipants, Literal(row["N"]), cohorts_graph))
if row["Study duration"]:
g.add((cohort_uri, ICARE.study_duration, Literal(row["Study duration"]), cohorts_graph))
g.add((cohort_uri, ICARE.studyDuration, Literal(row["Study duration"]), cohorts_graph))
if row["Ongoing"]:
g.add((cohort_uri, ICARE.study_ongoing, Literal(row["Ongoing"]), cohorts_graph))
g.add((cohort_uri, ICARE.studyOngoing, Literal(row["Ongoing"]), cohorts_graph))
if row["Patient population"]:
g.add((cohort_uri, ICARE.study_population, Literal(row["Patient population"]), cohorts_graph))
g.add((cohort_uri, ICARE.studyPopulation, Literal(row["Patient population"]), cohorts_graph))
if row["Primary objective"]:
g.add((cohort_uri, ICARE.study_objective, Literal(row["Primary objective"]), cohorts_graph))
g.add((cohort_uri, ICARE.studyObjective, Literal(row["Primary objective"]), cohorts_graph))
return g


Expand Down
24 changes: 12 additions & 12 deletions backend/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ def run_query(query: str) -> dict[str, Any]:
?cohort a icare:Cohort ;
dc:identifier ?cohortId ;
icare:institution ?cohortInstitution .
OPTIONAL { ?cohort icare:cohort_type ?cohortType . }
OPTIONAL { ?cohort icare:cohortType ?cohortType . }
OPTIONAL { ?cohort icare:email ?cohortEmail . }
OPTIONAL { ?cohort icare:study_type ?study_type . }
OPTIONAL { ?cohort icare:study_participants ?study_participants . }
OPTIONAL { ?cohort icare:study_duration ?study_duration . }
OPTIONAL { ?cohort icare:study_ongoing ?study_ongoing . }
OPTIONAL { ?cohort icare:study_population ?study_population . }
OPTIONAL { ?cohort icare:study_objective ?study_objective . }
OPTIONAL { ?cohort icare:studyType ?study_type . }
OPTIONAL { ?cohort icare:studyParticipants ?study_participants . }
OPTIONAL { ?cohort icare:studyDuration ?study_duration . }
OPTIONAL { ?cohort icare:studyOngoing ?study_ongoing . }
OPTIONAL { ?cohort icare:studyPopulation ?study_population . }
OPTIONAL { ?cohort icare:studyObjective ?study_objective . }
}
OPTIONAL {
GRAPH ?cohortVarGraph {
?cohort icare:has_variable ?variable .
?cohort icare:hasVariable ?variable .
?variable a icare:Variable ;
dc:identifier ?varName ;
rdfs:label ?varLabel ;
icare:var_type ?varType ;
icare:varType ?varType ;
icare:index ?index .
OPTIONAL { ?variable icare:count ?count }
OPTIONAL { ?variable icare:na ?na }
Expand All @@ -72,7 +72,7 @@ def run_query(query: str) -> dict[str, Any]:
OPTIONAL { ?variable icare:units ?units }
OPTIONAL { ?variable icare:formula ?formula }
OPTIONAL { ?variable icare:definition ?definition }
OPTIONAL { ?variable icare:concept_id ?conceptId }
OPTIONAL { ?variable icare:conceptId ?conceptId }
OPTIONAL { ?variable icare:omop ?omopDomain }
OPTIONAL { ?variable icare:visits ?visits }
OPTIONAL {
Expand All @@ -86,11 +86,11 @@ def run_query(query: str) -> dict[str, Any]:
OPTIONAL {
GRAPH ?cohortMappingsGraph {
OPTIONAL {
?variable icare:mapped_id ?mappedId .
?variable icare:mappedId ?mappedId .
OPTIONAL { ?mappedId rdfs:label ?mappedLabel }
}
OPTIONAL {
?category icare:mapped_id ?categoryMappedId .
?category icare:mappedId ?categoryMappedId .
OPTIONAL { ?categoryMappedId rdfs:label ?categoryMappedLabel }
}
}
Expand Down
Loading

0 comments on commit 37318af

Please sign in to comment.