Skip to content

Commit

Permalink
#10 : subrecords' final visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastiano-G committed Mar 7, 2024
1 parent 606e246 commit c923a54
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 34 deletions.
8 changes: 8 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,14 @@ def GET(self, name):
and k == field['id'])][0]
except Exception as e:
title = "No title"

try:
subtemplates = [data[k][0] for k,v in data.items() \
for field in fields if (field['type'] == "Subtemplate" \
and k == field['id'])]
except Exception as e:
subtemplates = None
print(subtemplates)
properties = {field["label"]:[field["property"], field["type"]] for field in fields if 'property' in field}
data_labels = { field['label']:v for k,v in data.items() \
for field in fields if k == field['id'] and field['hidden'] == 'False' }
Expand Down
3 changes: 2 additions & 1 deletion forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
classes = classes+' oneVocableAccepted' if 'vocables' in field and field['vocables'] == 'oneVocable' else classes
classes = classes+' websitePreview' if field['type'] == 'WebsitePreview' else classes
classes = classes+' ('+res_class+') '+disabled
classes = classes+ ' ' + field['cardinality'] if 'cardinality' in field else classes
autocomplete = field['cache_autocomplete'] if 'cache_autocomplete' in field and len(field['cache_autocomplete']) > 0 else ''
mandatory = field['mandatory'] if 'mandatory' in field and field['mandatory'] == 'True' else 'False'

Expand Down Expand Up @@ -185,7 +186,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
checked=False,
mandatory = mandatory), )

# subtemplate
# Subtemplate
if field['type'] == 'Subtemplate':
resource_class = [t["type"] for t in tpl_list if t["template"] == field['import_subtemplate']][0]
params = params + (form.Textbox(myid,
Expand Down
12 changes: 6 additions & 6 deletions mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def inputToRDF(recordData, userID, stage, knowledge_extraction, graphToClear=Non
# CREATE/MODIFY A NAMED GRAPH for each new record

recordID = recordData.recordID
print(recordID)
graph_name = recordID
wd = rdflib.Graph(identifier=URIRef(base+graph_name+'/'))

Expand All @@ -100,7 +99,7 @@ def inputToRDF(recordData, userID, stage, knowledge_extraction, graphToClear=Non
wd.add(( URIRef(base+graph_name+'/'), PROV.wasAttributedTo, URIRef(creatorIRI) ))
wd.add(( URIRef(creatorIRI), RDFS.label , Literal(creatorLabel ) ))

# retrieve hidden triples (to be saved) and re-introduce them in the named graph
# retrieve hidden triples (to be saved) and re-introduce them in the modified named graph
to_be_saved = queries.saveHiddenTriples(graphToClear, tpl_form)
if to_be_saved:
for binding in to_be_saved['results']['bindings']:
Expand Down Expand Up @@ -218,7 +217,7 @@ def inputToRDF(recordData, userID, stage, knowledge_extraction, graphToClear=Non

# imported subrecords
for imported_entity in imported_subrecords:
imported_entity_id, imported_entity_label = recordData[imported_entity].split(',')
imported_entity_id, imported_entity_label = recordData[field['id']+"-"+imported_entity].split(',')
imported_entity_label = urllib.parse.unquote(imported_entity_label)
entityURI = getRightURIbase(imported_entity_id)
wd.add(( URIRef(base+graph_name), URIRef(field['property']), URIRef(entityURI) ))
Expand Down Expand Up @@ -261,7 +260,7 @@ def check_subrecords(data, identifier):
for subrecord in subrecords:
if subrecord.startswith(identifier+"__"):
new_subrecords.append(subrecord)
elif subrecord.startswith(identifier+"-") and "target-" not in data[subrecord]:
elif "-" in subrecord and "target-" not in data[identifier+"-"+subrecord]:
imported_subrecords.append(subrecord)
else:
double_subrecords.append(subrecord)
Expand Down Expand Up @@ -305,7 +304,8 @@ def process_new_subrecord(data, subrecord_id, userID, stage, knowledge_extractio
new_record_data['recordID'] = ID
label = new_record_data[find_label(sub_tpl)]
store_data = storify(new_record_data)
inputToRDF(store_data,userID,stage,knowledge_extraction,tpl_form=sub_tpl)
grapht_to_clear = None if stage == 'not modified' else base+ID+"/"
inputToRDF(store_data,userID,stage,knowledge_extraction,graphToClear=grapht_to_clear,tpl_form=sub_tpl)
result = ID+","+label
data[subrecord_id] = result.strip()
return data
Expand Down Expand Up @@ -340,5 +340,5 @@ def find_label(tpl):
fields_id = [field['id'] for field in tpl_fields if field['disambiguate'] == "True"]
label_field_id = fields_id[0] if fields_id != [] else False

# Add a mechanism to handle potential Templates without a Primary Key (e.g. the primary key has been set to "hidden")
# TODO: add a mechanism to handle potential Templates without a Primary Key in case it's needed
return label_field_id
1 change: 1 addition & 0 deletions queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def getData(graph,res_template):
OPTIONAL {?subject schema:keywords ?keywords . ?keywords rdfs:label ?keywords_label . } }
}
'''

sparql = SPARQLWrapper(conf.myEndpoint)
sparql.setQuery(queryNGraph)
sparql.setReturnFormat(JSON)
Expand Down
67 changes: 67 additions & 0 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,7 @@ button#showTemplates {

.subform_buttons {
margin-top: 3em !important;
margin-bottom: 1.5em !important;
}

.subform_buttons input {
Expand All @@ -2036,6 +2037,72 @@ input[subtemplate]+.fa-plus-circle {
color: rgba(100,23,180,1); cursor: pointer;
}

/* Subrecords visualisation */

.subtemplateValue {
background-color: #ececec !important;
display: block;
margin-bottom: 0px !important;
}

.subtemplateValue > a {
background-color: white;
border: black 1px solid;
box-shadow: 3px 5px;
color: black !important;
display: inline-block;
font-weight: 400;
padding: 2px 50px 2px 15px !important;
text-decoration: none !important;
width: 100%;
}

.subtemplateValue:last-of-type {
margin-bottom: 1rem;
}

.subtemplateValue section:last-of-type {
margin-bottom: 0px !important;
padding-bottom: 1rem;
}

.subtemplateValue > span {
display: inline-block;
position: absolute;
right: 2em;
}

.subtemplateValue .subtemplateValue {
border: rgb(152, 128, 177) 1px solid !important;
}

.fa-chevron-down {
color: #343a406e;
padding-top: 8px;
}

.fa-chevron-down:hover {
color: rgba(100, 23, 180, 1);
cursor: pointer;
}

.hidden-subrecord {
display: none;
}

.subtemplateValue > div > section > p {
font-size: 1em !important;
}

.subtemplateValue > div .articleSubtitle {
font-size: 0.8em !important;
}
.subtemplateValueOpen > a,
.subtemplateValue > a:hover {
border-color: rgba(100, 23, 180, 1) !important;
color: rgba(100, 23, 180, 1) !important;
}

/* extra */
.fa-plus-circle, .fa-eye, .fa-trash{color: rgba(100,23,180,1); cursor: pointer;}
.link_btn, .btn {white-space: nowrap;}
Expand Down
Loading

0 comments on commit c923a54

Please sign in to comment.