Skip to content

Commit

Permalink
#14 Inverse relationships in View Page & Term Page
Browse files Browse the repository at this point in the history
UI update still in progress. View pages have been enriched with a novel section to display incoming properties related to the entity. The Term Page "Appears in" section is now organized according to Classes. Term Pages becomes available also for imported entities.
  • Loading branch information
Sebastiano-G committed Jul 1, 2024
1 parent 1012852 commit 7321f5b
Show file tree
Hide file tree
Showing 13 changed files with 5,375 additions and 477 deletions.
65 changes: 58 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def POST(self, page):

# create a new template
elif actions.action.startswith('createTemplate'):
print('create template')
print('create template:', actions)
is_git_auth = github_sync.is_git_auth()
res_type = sorted([ urllib.parse.unquote(actions[class_input].strip()) for class_input in actions if class_input.startswith("uri_class")])
res_type = conf.main_entity if res_type == [] else res_type
Expand Down Expand Up @@ -995,7 +995,7 @@ def GET(self, name):
base = conf.base
record = base+name
res_class = queries.getClass(conf.base+name)
data, stage, title, properties, data_labels, extractions_data = None, None, None, None, {}, {}
data, stage, title, properties, data_labels, extractions_data, new_dict_classes, properties_sorted = None, None, None, None, {}, {}, {}, {}

try:
res_template = u.get_template_from_class(res_class)
Expand All @@ -1019,11 +1019,46 @@ def GET(self, name):
except Exception as e:
pass

try:
incoming_links = queries.get_records_from_object(base+name)
class_sorted = {}
for result in incoming_links['results']['bindings']:
result_class = result['class']['value']
result_property_uri = result['property']['value']
result_property = result_property_uri + "," + u.get_LOV_namespace(result_property_uri)
result_subject = result['subject']['value'] + ',' + result['label']['value']
if result_class not in class_sorted:
class_sorted[result_class] = { result_property : [result_subject] }
else:
if result_property in class_sorted[result_class]:
class_sorted[result_class][result_property].append(result_subject)
else:
class_sorted[result_class][result_property] = [result_subject]

with open(TEMPLATE_LIST) as tpl_list:
templates = json.load(tpl_list)
for k in list(class_sorted.keys()):
template = next((t["name"], t["template"]) for t in templates if t["type"] == sorted(k.split("; ")))
template_name, template_file = template
with open(template_file) as tpl_file:
template_fields = json.load(tpl_file)
property_label = list(class_sorted[k].keys())[0]
property_name = next(f["label"] for f in template_fields if f["property"] == property_label.split(',',1)[0])
if property_label in properties_sorted:
properties_sorted[property_label].extend(class_sorted[k][property_label])
else:
properties_sorted[property_label] = class_sorted[k][property_label]
new_dict_classes[template_name] = {'class':k, 'results': { property_label+','+property_name : class_sorted[k][property_label]} }
except Exception as e:
pass




return render.view(user=session['username'], graphdata=data_labels,
graphID=name, title=title, stage=stage, base=base,properties=properties,
is_git_auth=is_git_auth,project=conf.myProject,knowledge_extractor=extractions_data)
is_git_auth=is_git_auth,project=conf.myProject,knowledge_extractor=extractions_data,
inverses_by_class=new_dict_classes, inverses_by_properties = properties_sorted)

def POST(self,name):
""" Record web page
Expand All @@ -1050,15 +1085,31 @@ def GET(self, name):
the ID of the term, generally the last part of the URL
"""
web.header("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store")
data = queries.describeTerm(name)
uri = mapping.getRightURIbase(name)
data = queries.describeTerm(uri)
is_git_auth = github_sync.is_git_auth()

count = len([ result["subject"]["value"] \
results_by_class = {}
appears_in = [ result["subject"]["value"] \
for result in data["results"]["bindings"] \
if (name in result["object"]["value"] and result["object"]["type"] == 'uri') ])
if (name in result["object"]["value"] and result["object"]["type"] == 'uri') ]


with open(TEMPLATE_LIST) as tpl_list:
res_templates = json.load(tpl_list)
for res_uri in appears_in:
res_class = sorted(queries.getClass(res_uri))
res_type = next(t["name"] for t in res_templates if t["type"] == res_class)
if res_type in results_by_class:
results_by_class[res_type]['results'].append(res_uri)
else:
results_by_class[res_type] = {'class':res_class, 'results':[res_uri]}

count = len(appears_in)

return render.term(user=session['username'], data=data, count=count,
is_git_auth=is_git_auth,project=conf.myProject,base=conf.base,name=name)
is_git_auth=is_git_auth,project=conf.myProject,base=conf.base,
uri=uri,name=name,results=results_by_class)

def POST(self,name):
""" controlled vocabulary term web page
Expand Down
14 changes: 14 additions & 0 deletions forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def get_form(json_form, from_dict=False, subtemplate=False):
classes = classes+' websitePreview' if field['type'] == 'WebsitePreview' else classes
classes = classes+' disabled' if 'disabled' in field and field['disabled'] == "True" else classes
classes = classes+ ' ' + field['cardinality'] if 'cardinality' in field else classes
classes = classes+ ' ' + field['dataReuse'] if 'dataReuse' in field else classes
autocomplete = field['cache_autocomplete'] if 'cache_autocomplete' in field and len(field['cache_autocomplete']) > 0 else ''
rdf_property = field['property'] if 'property' in field else ''
mandatory = field['mandatory'] if 'mandatory' in field and field['mandatory'] == 'True' else 'False'

# text box
Expand All @@ -100,6 +102,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
class_= classes,
value=default,
lang=conf.mainLang,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class) , )
else:
Expand All @@ -112,6 +115,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
class_= classes,
value=default,
lang=conf.mainLang,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )

Expand All @@ -124,6 +128,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
pre = prepend,
class_= classes,
value=default,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )

Expand All @@ -136,6 +141,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
pre = prepend,
class_= classes,
value=default,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class) , )

Expand All @@ -149,6 +155,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
class_= classes,
value=default,
lang=conf.mainLang,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )

Expand All @@ -159,6 +166,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
id=myid,
pre = prepend,
class_= classes,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )
elif field['calendar'] == 'Day':
Expand All @@ -167,6 +175,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
id=myid,
pre = prepend,
class_= classes,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )
elif field['calendar'] == 'Year':
Expand All @@ -176,6 +185,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
pre = prepend,
class_= classes,
value=default,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )

Expand All @@ -187,6 +197,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
id=myid,
pre = prepend,
class_= classes,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )

Expand All @@ -200,6 +211,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
pre = prepend_title,
class_= classes+' checkbox_group',
checked=False,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )

Expand All @@ -212,6 +224,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
pre = '',
class_= classes+' checkbox_group following_checkbox',
checked=False,
data_property = rdf_property,
data_mandatory = mandatory,
data_class=res_class), )

Expand All @@ -227,6 +240,7 @@ def get_form(json_form, from_dict=False, subtemplate=False):
value=default,
data_mandatory = mandatory,
data_class=res_class,
data_property = rdf_property,
data_subtemplate = resource_class,
data_subtemplateID = field['import_subtemplate']), ) + get_form(field['import_subtemplate'], subtemplate=True)

Expand Down
Loading

0 comments on commit 7321f5b

Please sign in to comment.