diff --git a/app.py b/app.py index 4fb9f57..97ef310 100644 --- a/app.py +++ b/app.py @@ -567,7 +567,8 @@ def GET(self, name): return render.record(record_form=f, pageID=name, user=user, alert=block_user, limit=limit, is_git_auth=is_git_auth,invalid=False, - project=conf.myProject,template=None,query_templates=None,knowledge_extractor=False) + project=conf.myProject,template=None, + query_templates=None,knowledge_extractor=False) def POST(self, name): """ Submit a new record @@ -610,7 +611,8 @@ def POST(self, name): extractor = u.has_extractor(recordData.res_name) return render.record(record_form=f, pageID=name, user=user, alert=block_user, limit=limit, is_git_auth=is_git_auth,invalid=False, - project=conf.myProject,template=recordData.res_name,query_templates=query_templates,knowledge_extractor=extractor) + project=conf.myProject,template=recordData.res_name, + query_templates=query_templates,knowledge_extractor=extractor) else: raise web.seeother(prefixLocal+'record-'+name) @@ -625,10 +627,12 @@ def POST(self, name): if recordID: if invalid_input: f = forms.get_form(templateID) + query_templates = u.get_query_templates(recordData.res_name) extractor = u.has_extractor(templateID) return render.record(record_form=f, pageID=name, user=user, alert=block_user, limit=limit, is_git_auth=is_git_auth,invalid=True, - project=conf.myProject,template=templateID,skos_vocabs=skos_file,knowledge_extractor=extractor) + project=conf.myProject,template=templateID, + query_templates=query_templates,knowledge_extractor=extractor) else: u.update_knowledge_extraction(recordData,KNOWLEDGE_EXTRACTION) userID = user.replace('@','-at-').replace('.','-dot-') @@ -679,17 +683,14 @@ def GET(self, name): with open(res_template) as tpl_form: fields = json.load(tpl_form) ids_dropdown = u.get_dropdowns(fields) - if not os.path.isfile(SKOS_VOCAB): - skos_file = None - else: - with open(SKOS_VOCAB, 'r') as skos_list: - skos_file = json.load(skos_list) + + query_templates=u.get_query_templates(res_template) extractor = queries.retrieve_extractions(conf.base+name) if u.has_extractor(name, modify=True) else False return render.modify(graphdata=data, pageID=recordID, record_form=f, user=session['username'],ids_dropdown=ids_dropdown, is_git_auth=is_git_auth,invalid=False, - project=conf.myProject,template=res_template,skos_vocabs=skos_file,knowledge_extractor=extractor) + project=conf.myProject,template=res_template,query_templates=query_templates,knowledge_extractor=extractor) else: session['logged_in'] = 'False' raise web.seeother(prefixLocal+'/') @@ -730,17 +731,14 @@ def POST(self, name): fields = json.load(tpl_form) ids_dropdown = u.get_dropdowns(fields) - if not os.path.isfile(SKOS_VOCAB): - skos_file = None - else: - with open(SKOS_VOCAB, 'r') as skos_list: - skos_file = json.load(skos_list) + query_templates = u.get_query_templates(templateID) extractor = queries.retrieve_extractions(conf.base+name) if u.has_extractor(name, modify=True) else False return render.modify(graphdata=data, pageID=recordID, record_form=f, user=session['username'],ids_dropdown=ids_dropdown, is_git_auth=is_git_auth,invalid=True, - project=conf.myProject,template=res_template,skos_vocabs=skos_file,knowledge_extractor=extractor) + project=conf.myProject,template=res_template, + query_templates=query_templates,knowledge_extractor=extractor) else: print(recordData) recordID = recordData.recordID @@ -794,18 +792,15 @@ def GET(self, name): with open(res_template) as tpl_form: fields = json.load(tpl_form) ids_dropdown = u.get_dropdowns(fields) # TODO CHANGE - if not os.path.isfile(SKOS_VOCAB): - skos_file = None - else: - with open(SKOS_VOCAB, 'r') as skos_list: - skos_file = json.load(skos_list) + + query_templates = u.get_query_templates(res_template) extractor = queries.retrieve_extractions(conf.base+name) if u.has_extractor(name, modify=True) else False return render.review(graphdata=data, pageID=recordID, record_form=f, graph=graphToRebuild, user=session['username'], ids_dropdown=ids_dropdown,is_git_auth=is_git_auth, invalid=False,project=conf.myProject,template=res_template, - skos_vocabs=skos_file,knowledge_extractor=extractor) + query_templates=query_templates,knowledge_extractor=extractor) else: session['logged_in'] = 'False' raise web.seeother(prefixLocal+'/') @@ -840,17 +835,13 @@ def POST(self, name): with open(templateID) as tpl_form: fields = json.load(tpl_form) ids_dropdown = u.get_dropdowns(fields) # TODO CHANGE - if not os.path.isfile(SKOS_VOCAB): - skos_file = None - else: - with open(SKOS_VOCAB, 'r') as skos_list: - skos_file = json.load(skos_list) + query_templates = u.get_query_templates() extractor = queries.retrieve_extractions(conf.base+name) if u.has_extractor(name, modify=True) else False return render.review(graphdata=data, pageID=recordID, record_form=f, graph=graphToRebuild, user=session['username'], ids_dropdown=ids_dropdown,is_git_auth=is_git_auth, invalid=True,project=conf.myProject,template=templateID, - skos_vocabs=skos_file,knowledge_extractor=extractor) + query_templates=query_templates,knowledge_extractor=extractor) else: recordData = web.input() recordID = recordData.recordID @@ -879,17 +870,14 @@ def POST(self, name): with open(templateID) as tpl_form: fields = json.load(tpl_form) ids_dropdown = u.get_dropdowns(fields) - if not os.path.isfile(SKOS_VOCAB): - skos_file = None - else: - with open(SKOS_VOCAB, 'r') as skos_list: - skos_file = json.load(skos_list) + + query_templates = u.get_query_templates() extractor = queries.retrieve_extractions(conf.base+name) if u.has_extractor(name, modify=True) else False return render.review(graphdata=data, pageID=recordID, record_form=f, graph=graphToRebuild, user=session['username'], ids_dropdown=ids_dropdown,is_git_auth=is_git_auth, invalid=True,project=conf.myProject,template=templateID, - skos_vocabs=skos_file,knowledge_extractor=extractor) + query_templates=query_templates,knowledge_extractor=extractor) else: recordData = web.input() u.update_knowledge_extraction(recordData,KNOWLEDGE_EXTRACTION) diff --git a/forms.py b/forms.py index 275fca5..8d86672 100644 --- a/forms.py +++ b/forms.py @@ -115,7 +115,7 @@ def get_form(json_form, from_dict=False, subtemplate=False): lang=conf.mainLang), ) # Entities, SKOS thesauri, links - if field['type'] in ['Skos', 'WebsitePreview'] or (field['type'] == 'Textbox' and field['value'] in ['URL', 'URI']): + if field['type'] in ['Skos', 'WebsitePreview'] or (field['type'] == 'Textbox' and field['value'] in ['URL', 'URI', 'Place']): params = params + (form.Textbox(myid, description = description, id=myid, @@ -130,11 +130,11 @@ def get_form(json_form, from_dict=False, subtemplate=False): params = params + (form.Textbox(myid, description = description, id=myid, + placeholder=placeholder, pre = prepend, class_= classes, value=default, mandatory = mandatory) , ) - # Text box if field['type'] == 'Textarea': diff --git a/mapping.py b/mapping.py index f67b0f9..e2c324e 100644 --- a/mapping.py +++ b/mapping.py @@ -7,8 +7,8 @@ import web from web import form, storify import rdflib -from rdflib import URIRef , XSD, Namespace , Literal -from rdflib.namespace import OWL, DC , DCTERMS, RDF , RDFS +from rdflib import URIRef , XSD, Namespace , Literal, term +from rdflib.namespace import OWL, DC , DCTERMS, RDF , RDFS, SKOS from rdflib.plugins.sparql import prepareQuery from SPARQLWrapper import SPARQLWrapper, JSON from pymantic import sparql @@ -39,23 +39,27 @@ def getValuesFromFields(fieldPrefix, recordData, fields=None, field_type=None): """ request form fields by field prefix, check if multiple values are available, returns a set of tuples including ID (for the URI) and label of values """ - result_dict = {'type':'URI'} + result_dict = {'type':field_type} if field_type != None else {'type':'URI'} results = set() for key, value in recordData.items(): - if key.startswith(fieldPrefix+'_') and ',' in value: # multiple values from text box (wikidata) + URL - values = value.split(',', 1) - print(key,values) - results.add(( values[0].strip(), urllib.parse.unquote(values[1]) )) # (id, label) - elif key == fieldPrefix and field_type != 'Textarea': # uri from dropdown (single value from controlled vocabulary) + URL - if fields: - field = next(field for field in fields if field["id"] == fieldPrefix) - label = field['values'][value] if value and value != 'None' and 'values' in field else None - if label: - results.add(( value, label )) - elif field_type: - values = value.split(',') - for val in values: - results.add(( val.strip(), val.strip() )) + if field_type == 'Textarea': + # textarea: NLP keywords + if key.startswith(fieldPrefix+'_Q') and ',' in value and key.split('_')[1] == value.split(',')[0]: + values = value.split(',', 1) + results.add(( values[0].strip(), urllib.parse.unquote(values[1]) )) # (id, label) + else: + if key.startswith(fieldPrefix+'_') and ',' in value: # multiple values from text box (entities) and URL + values = value.split(',', 1) + results.add(( values[0].strip(), urllib.parse.unquote(values[1]) )) # (id, label) + elif key == fieldPrefix: # uri from dropdown (single value from controlled vocabulary) and URL + if fields: + field = next(field for field in fields if field["id"] == fieldPrefix) + label = field['values'][value] if value and value != 'None' and 'values' in field else None + if label: + results.add(( value, label )) + elif field_type == 'URL': + for url in value.split(','): + results.add(( url.strip(), url.strip() )) result_dict['results'] = results return result_dict @@ -69,7 +73,7 @@ def getLiteralValuesFromFields(fieldPrefix, recordData): lang = key.rsplit('_')[1] if lang == 'mainLang': result_dict['mainLang'] = value - else: + elif term._is_valid_langtag(lang): results.add((value,lang)) result_dict['results'] = results return result_dict @@ -150,8 +154,8 @@ def inputToRDF(recordData, userID, stage, knowledge_extraction, graphToClear=Non for field in fields: if field['type'] not in ['KnowledgeExtractor', 'Subtemplate']: # URI, Textarea (only text at this stage), Literals - value = getValuesFromFields(field['id'], recordData, fields) if 'value' in field and field['value'] in ['URI','Place'] \ - else getValuesFromFields(field['id'], recordData, field_type=field['type']) if 'value' in field and field['value'] == 'URL' \ + value = getValuesFromFields(field['id'], recordData, fields=fields) if 'value' in field and field['value'] in ['URI','Place'] \ + else getValuesFromFields(field['id'], recordData, field_type=field['value']) if 'value' in field and field['value'] == 'URL' \ else getLiteralValuesFromFields(field['id'], recordData) if 'value' in field and field['value'] == 'Literal' else recordData[field['id']] # TODO disambiguate as URI, value if field["disambiguate"] == 'True': # use the key 'disambiguate' as title of the graph @@ -181,19 +185,21 @@ def inputToRDF(recordData, userID, stage, knowledge_extraction, graphToClear=Non wd.add(( URIRef(base+graph_name), URIRef(field['property']), URIRef(value))) else: wd.add(( URIRef(base+graph_name), URIRef(field['property']), Literal(value) )) - elif 'value' in field and field['value'] == 'URL': - for entity in value: - if entity[1] != "": - to_add = entity[1] - if not to_add.startswith("http"): - to_add = "http://" + to_add - wd.add(( URIRef(base+graph_name), URIRef(field['property']), URIRef(to_add) )) + # multiple-values fields elif isinstance(value,dict): - if value['type'] == 'URI': #object properties + print("Checkpoint:", value, field['id']) + if value['type'] == 'URL': #url + for URL in value['results']: + if URL[1] != "": + valueURL = URL[1] if URL[1].startswith("http") else "http://" + URL[1] + wd.add(( URIRef(base+graph_name), URIRef(field['property']), URIRef(valueURL) )) + elif value['type'] == 'URI': #object properties + rdf_property = SKOS.prefLabel if field['type'] == 'Skos' else RDFS.label + print(field['type'], rdf_property) for entity in value['results']: entityURI = getRightURIbase(entity[0]) # Wikidata or new entity wd.add(( URIRef(base+graph_name), URIRef(field['property']), URIRef(entityURI) )) - wd.add(( URIRef( entityURI ), RDFS.label, Literal(entity[1].lstrip().rstrip(), datatype="http://www.w3.org/2001/XMLSchema#string") )) + wd.add(( URIRef( entityURI ), rdf_property, Literal(entity[1].lstrip().rstrip(), datatype="http://www.w3.org/2001/XMLSchema#string") )) elif value['type'] == 'Literal': #multi-language Literals for literal in value['results']: val, lang = literal @@ -201,9 +207,9 @@ def inputToRDF(recordData, userID, stage, knowledge_extraction, graphToClear=Non wd.add(( URIRef(base+graph_name), URIRef(field['property']), Literal(val, lang=lang))) # now get also the entities associated to textareas (record creation) if field['type'] == 'Textarea': - value = getValuesFromFields(field['id'], recordData, fields, 'Textarea') - for entity in value['results']: - entityURI = getRightURIbase(entity[0])+entity[0] + nlp_keywords = getValuesFromFields(field['id'], recordData, field_type='Textarea') + for entity in nlp_keywords['results']: + entityURI = getRightURIbase(entity[0]) wd.add(( URIRef(base+graph_name), SCHEMA.keywords, URIRef(entityURI) )) wd.add(( URIRef( entityURI ), RDFS.label, Literal(entity[1].lstrip().rstrip(), datatype="http://www.w3.org/2001/XMLSchema#string") )) # KNOWLEDGE EXTRACTION: import graphs @@ -296,7 +302,7 @@ def process_new_subrecord(data, userID, stage, knowledge_extraction, sub_tpl, su new_record_data[subtemplate_field['id']] = data[key] # Multiple values fields: Literals or URI - elif subtemplate_field['value'] == 'Literal' or subtemplate_field['value'] in ['URI','URL']: + elif subtemplate_field['value'] == 'Literal' or subtemplate_field['value'] in ['URI','URL','Place']: keys = [input_id for input_id in data.keys() if input_id.startswith(subtemplate_field['id']+"_") and input_id.endswith("_"+subrecord_id)] for key in keys: shortened_key = key.rsplit("_",1)[0] @@ -309,7 +315,7 @@ def process_new_subrecord(data, userID, stage, knowledge_extraction, sub_tpl, su label_input_field = subfield_id+"_"+main_lang+"_"+subrecord_id label = data[label_input_field] if label_input_field in data else "No label" - print("\nDATA:\n",new_record_data) + print("#### DATA:\n",new_record_data) store_data = storify(new_record_data) grapht_to_clear = None if stage == 'not modified' else base+subrecord_id+"/" inputToRDF(store_data,userID,stage,knowledge_extraction,graphToClear=grapht_to_clear,tpl_form=sub_tpl) diff --git a/queries.py b/queries.py index dacbf66..b8be870 100644 --- a/queries.py +++ b/queries.py @@ -202,20 +202,68 @@ def getClass(res_uri): def getData(graph,res_template): """ get a named graph and rebuild results for modifying the record""" + + def compare_sublists(l, lol): + for sublist in lol: + temp = [i for i in sublist if i in l] + if sorted(temp) == sorted(l): + return True + return False + + def disambiguate_pattern(properties,fields,k): + field_k = next(field for field in fields if field['id'] == k) + pattern = '' + # disambiguate Textbox > URI and Textbox > Place: + if field_k['type'] == 'Textbox': + if field_k['value'] == 'URI': + if any(field for field in properties if field['type'] == 'Textbox' and field['value'] == 'Place'): + pattern = 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. ?'+field['id']+' rdfs:label ?'+field['id']+'_label . FILTER(!REGEX(str(?'+field['id']+'),"sws.geonames.org/"))} .' + elif field_k['value'] == 'Place': + if any(field for field in properties if field['type'] == 'Textbox' and field['value'] == 'URI'): + pattern = 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. ?'+field['id']+' rdfs:label ?'+field['id']+'_label . FILTER(REGEX(str(?'+field['id']+'),"sws.geonames.org/"))} .' + if field_k['value'] == 'URL': + if field_k['type'] == 'Textbox': + if any(field for field in properties if field['type'] == 'Multimedia'): + pattern = 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. FILTER (isURI(?'+field['id']+')) FILTER NOT EXISTS {?'+field['id']+' rdfs:label ?'+field['id']+'_label } FILTER NOT EXISTS { ?'+field['id']+' skos:prefLabel ?'+field['id']+'_label } FILTER(!REGEX(str(?'+field['id']+'), "\\\\.(apng|avif|gif|ico|jpg|jpeg|jfif|pjpeg|pjp|png|svg|webp|mp3|wav|ogg|mp4|ogg|webm)$", "i"))} .' + elif field_k['type'] == 'Multimedia': + if any(field for field in properties if field['type'] == 'Textbox' and field['value'] == 'URL'): + pattern = 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. FILTER (isURI(?'+field['id']+')) FILTER NOT EXISTS {?'+field['id']+' rdfs:label ?'+field['id']+'_label } FILTER NOT EXISTS { ?'+field['id']+' skos:prefLabel ?'+field['id']+'_label } FILTER(REGEX(str(?'+field['id']+'), "\\\\.(apng|avif|gif|ico|jpg|jpeg|jfif|pjpeg|pjp|png|svg|webp|mp3|wav|ogg|mp4|ogg|webm)$", "i"))} .' + return pattern + with open(res_template) as config_form: fields = json.load(config_form) + properties_dict = {} + patterns = [] res_class = getClass(graph[:-1]) - patterns = [ 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'.} ' if field['value'] in ['Literal','URL'] - else 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. FILTER (datatype(?'+field['id']+') = xsd:'+field['value'][0].lower() + field['value'][1:]+') } ' if field['value'] in ['Date', 'gYear', 'gYearMonth'] - else 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. ?'+field['id']+' rdfs:label ?'+field['id']+'_label .} .' - for field in fields ] + # check duplicate properties + for field in fields: + if field['type'] != 'KnowledgeExtractor': + if field['property'] in properties_dict: + properties_dict[field['property']].append(field) + else: + properties_dict[field['property']] = [field] + + # add query pattern + for field in fields: + if field['type'] != 'KnowledgeExtractor': + pattern = "" + if len(properties_dict[field['property']]) > 1: + pattern = disambiguate_pattern(properties_dict[field['property']],fields,field['id']) + if pattern == "": + pattern = 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. FILTER (lang(?'+field['id']+')!="")} ' if field['value'] == 'Literal' \ + else 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. FILTER (isURI(?'+field['id']+')) FILTER NOT EXISTS {?'+field['id']+' rdfs:label ?'+field['id']+'_label } FILTER NOT EXISTS { ?'+field['id']+' skos:prefLabel ?'+field['id']+'_label } } ' if field['value'] == 'URL' \ + else 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. FILTER (datatype(?'+field['id']+') = xsd:'+field['value'][0].lower() + field['value'][1:]+') } ' if field['value'] in ['Date', 'gYear', 'gYearMonth'] \ + else 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. ?'+field['id']+' skos:prefLabel ?'+field['id']+'_label .} .' if 'type' in field and field['type'] == 'Skos' \ + else 'OPTIONAL {?subject <'+field['property']+'> ?'+field['id']+'. ?'+field['id']+' rdfs:label ?'+field['id']+'_label } .' + patterns.append(pattern) patterns_string = ''.join(patterns) queryNGraph = ''' PREFIX base: <'''+conf.base+'''> PREFIX schema: + PREFIX skos: SELECT DISTINCT * WHERE { <'''+graph+'''> rdfs:label ?graph_title ; ?stage @@ -231,22 +279,16 @@ def getData(graph,res_template): sparql.setReturnFormat(JSON) results = sparql.query().convert() - def compare_sublists(l, lol): - for sublist in lol: - temp = [i for i in sublist if i in l] - if sorted(temp) == sorted(l): - return True - return False - data = defaultdict(list) for result in results["results"]["bindings"]: result.pop('subject',None) - label = result.pop('graph_title',None) + graph_label = result.pop('graph_title',None) for k,v in result.items(): if '_label' not in k and v['type'] == 'literal': # string values value = v['value'] if 'xml:lang' in v: - value = (v['value'],v['xml:lang'],'mainLang') if v['value']==label['value'] and v['xml:lang']==label['xml:lang'] else (v['value'],v['xml:lang']) + value = (v['value'],v['xml:lang'],'mainLang') if v['value']==graph_label['value'] and v['xml:lang']==graph_label['xml:lang'] else (v['value'],v['xml:lang']) + if value not in data[k]: data[k].append(value) elif v['type'] == 'uri': # uri values @@ -380,10 +422,8 @@ def saveHiddenTriples(graph, tpl): } } ''' - print(queryNGraph) sparql = SPARQLWrapper(conf.myEndpoint) sparql.setQuery(queryNGraph) sparql.setReturnFormat(JSON) results = sparql.query().convert() - print(results) return results diff --git a/static/css/main.css b/static/css/main.css index ea4cb95..0d2925c 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -732,8 +732,9 @@ nav .wditem, nav .viafitem { .searchWikidata~.tag, .searchGeonames~.tag, +.searchSkos~.tag, textarea~.tags-nlp { - margin-left: 35px !important; + margin-left: 15px !important; } .tag::after { @@ -752,7 +753,7 @@ span[class^='tag Q']:hover { } .tags-nlp { - margin: 25px; + margin: 15px; } .tags-nlp::before { @@ -760,10 +761,11 @@ span[class^='tag Q']:hover { font-size: 0.7em; color: grey; display: block; + margin-left: 20px; } .tags-url { - margin-left: 35px; + margin-left: 15px; } .tags-url::before { @@ -771,6 +773,7 @@ span[class^='tag Q']:hover { font-size: 0.7em; color: grey; display: block; + margin-left: 20px; } @@ -1954,7 +1957,7 @@ button#showTemplates { } .multimediaTag .tag{ - margin-left:35px !important; + margin-left:15px !important; word-wrap:break-word; max-width: calc(100% - 35px); } diff --git a/static/js/main.js b/static/js/main.js index 8077470..277b882 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,8 +1,8 @@ if (graph.length) {var in_graph = "FROM <"+graph+">"} else {var in_graph = ""} -const wd_img = ' ' +const wd_img = ' ' const geo_img = ''; -const viaf_img = ''; +const viaf_img = ''; const wikidataEndpoint = "https://query.wikidata.org/sparql" $(document).ready(function() { @@ -101,10 +101,27 @@ $(document).ready(function() { areas.forEach(element => { element.after(tags); }); // Textbox > URL: suggestion - const textboxURL = document.querySelectorAll('#recordForm input.urlField, #modifyForm input.urlField'); - var suggestionTags = document.createElement('div'); - suggestionTags.setAttribute('class','tags-url'); - textboxURL.forEach(element => { element.after(suggestionTags); }); + const textboxURL = document.querySelectorAll('#recordForm input.urlField, #modifyForm input.urlField, #recordForm input.multimediaField, #modifyForm input.multimediaField'); + textboxURL.forEach(element => { + var suggestionTags = document.createElement('div'); + suggestionTags.setAttribute('class','tags-url'); + const parent = element.parentNode; + if (element.className.includes('multimediaField')) { + const previousURLS = Array.from(parent.querySelectorAll('.multimediaTag')); + previousURLS.forEach(tag => { + tag.remove(); + suggestionTags.appendChild(tag); + }); + } else { + console.log(element) + const previousURLS = Array.from(parent.querySelectorAll('span.tag, input.hiddenInput')); + previousURLS.forEach(tag => { + tag.remove(); + suggestionTags.appendChild(tag); + }); + }; + element.after(suggestionTags.cloneNode(true)); + }); // Suggest vocabularies links $("input[type='text'].searchSkos").each(function() { @@ -1123,7 +1140,7 @@ function searchGeonames(searchterm) { e.preventDefault(); var oldID = this.getAttribute('data-id').substr(this.getAttribute('data-id').lastIndexOf('/') + 1); var oldLabel = $(this).text(); - $('#'+searchterm).after(""+oldLabel+""); + $('#'+searchterm).after(""+oldLabel+""); $("#searchresult").hide(); $('#'+searchterm).val(''); }); @@ -1143,7 +1160,7 @@ function searchGeonames(searchterm) { $('a[data-id="'+ item.geonameId+'"]').each( function() { $(this).bind('click', function(e) { e.preventDefault(); - $('#'+searchterm).after(""+item.name+""); + $('#'+searchterm).after(""+item.name+""); $("#searchresult").hide(); $('#'+searchterm).val(''); //colorForm(); @@ -1817,8 +1834,37 @@ function addURL(searchterm, iframe=false) { $('#'+searchterm).after(""); } else { - $('#'+searchterm).after(""+$('#'+searchterm).val()+""); + $('#'+searchterm).next('.tags-url').prepend(""+$('#'+searchterm).val()+""); } + + // popover Wayback Machine + var tooltip_save = '\ + '; + + var tooltip_saved = '\ + '; + + $('#'+searchterm).parent().append(tooltip_save); + $('#'+searchterm).parent().append(tooltip_saved); + $(".savetheweb").popover({ + html: true, + title : "

Need to save a source for the future?

", + content: "

If you have a web page that is important to you, \ + we can save it using the \ + Wayback Machine

\ +

Shall we?

\ + \ + \ +

", + placement: "bottom", + }).popover('show'); + } else if ($('#'+searchterm).val().length > 0 && !regexURL.test($('#'+searchterm).val()) ) { alert('Insert a valid URL'); @@ -2033,7 +2079,7 @@ function searchSkos(searchterm) { $(this).bind('click', function (e) { e.preventDefault(); if (!skos_vocabs.includes("oneVocableAccepted") || $('#' + searchterm).nextAll("span").length == 0) { - $('#' + searchterm).after("" + label+" - "+vocabulary_noun + ""); + $('#' + searchterm).after("" + label+" - "+vocabulary_noun + ""); } else if (skos_vocabs.includes("oneVocableAccepted") && $('#' + searchterm).nextAll("span").length > 0) { alert("Only one term is accepted!"); @@ -2068,18 +2114,18 @@ function addMultimedia(searchterm) { if ($('#'+searchterm).val().length > 0 && regexURL.test($('#'+searchterm).val()) ) { // IMAGE if ($('#'+searchterm).hasClass("Image") && stringEndsWith($('#'+searchterm).val(), imageFormats)) { - $('#'+searchterm).after("
"); - $('.multimediaTag.'+newID).prepend(""+$('#'+searchterm).val()+""); + $('#'+searchterm).next('.tags-url').prepend("
"); + $('.multimediaTag.'+newID).prepend(""+$('#'+searchterm).val()+""); $('.multimediaTag.'+newID).prepend(""); } // AUDIO else if ($('#'+searchterm).hasClass("Audio") && stringEndsWith($('#'+searchterm).val(), audioFormats)) { - $('#'+searchterm).after("
"); - $('.multimediaTag.'+newID).prepend(""+$('#'+searchterm).val()+""); + $('#'+searchterm).next('.tags-url').prepend("
"); + $('.multimediaTag.'+newID).prepend(""+$('#'+searchterm).val()+""); $('.multimediaTag.'+newID).prepend(""); } // VIDEO else if ($('#'+searchterm).hasClass("Video") && stringEndsWith($('#'+searchterm).val(), videoFormats)) { - $('#'+searchterm).after("
"); - $('.multimediaTag.'+newID).prepend(""+$('#'+searchterm).val()+""); + $('#'+searchterm).next('.tags-url').prepend("
"); + $('.multimediaTag.'+newID).prepend(""+$('#'+searchterm).val()+""); $('.multimediaTag.'+newID).prepend(""); } else { @@ -2109,6 +2155,7 @@ function stringEndsWith(string, formatList) { // NLP function nlpText(searchterm) { var lang = searchterm.split('_')[1]; + var baseID = searchterm.split('_')[0]; $('textarea#'+searchterm).keypress( throttle(function(e) { if(e.which == 13) { //$('textarea#'+searchterm).parent().parent().append('
'); @@ -2137,7 +2184,7 @@ function nlpText(searchterm) { function(data) { console.log(data); $.each(data.search, function(i, item) { - $('textarea#'+searchterm).next('.tags-nlp').append(''+item.label+''); + $('textarea#'+searchterm).next('.tags-nlp').append(''+item.label+''); }); }); }; diff --git a/templates/modify.html b/templates/modify.html index e2e62fe..a8a7f94 100644 --- a/templates/modify.html +++ b/templates/modify.html @@ -1,9 +1,14 @@ -$def with (graphdata, pageID, record_form, user, ids_dropdown,is_git_auth,invalid, project,template, skos_vocabs, knowledge_extractor) +$def with (graphdata,pageID,record_form,user,ids_dropdown,is_git_auth,invalid,project,template,query_templates,knowledge_extractor) $var user = user $var is_git_auth = is_git_auth $var project = project +$if query_templates!=None: +
$else: - - $if " vocabularyField " in input.attrs["class"]: - $:input.render() - $ list_vocabs = "//".join(list(skos_vocabs.keys())) - $ selectedVocabs = str(skos_vocabs) - - $if len(graphdata[id]) > 0 and "multimedia" not in input.attrs["class"] and "websitePreview" not in input.attrs["class"]: + + $if type(graphdata[id][0]) is list: $:input.render() @@ -132,14 +127,6 @@

Modify record

- $elif "vocabularyField" in input.attrs["class"]: - $ list_vocabs = "//".join(list(skos_vocabs.keys())) - $ selectedVocabs = str(skos_vocabs) - $if knowledge_extractor != False: diff --git a/templates/record.html b/templates/record.html index d95d7c3..e6f88cc 100644 --- a/templates/record.html +++ b/templates/record.html @@ -4,10 +4,10 @@ $var project = project $if query_templates!=None: - + $if alert == False:
diff --git a/templates/review.html b/templates/review.html index b51b824..f3b4aaa 100644 --- a/templates/review.html +++ b/templates/review.html @@ -1,8 +1,13 @@ -$def with (graphdata, pageID, record_form, graph, user,ids_dropdown,is_git_auth,invalid,project,template,skos_vocabs,knowledge_extractor) +$def with (graphdata, pageID, record_form, graph, user,ids_dropdown,is_git_auth,invalid,project,template,query_templates,knowledge_extractor) $var user = user $var is_git_auth = is_git_auth $var project = project +$if query_templates!=None: +
$else: - - $if " vocabularyField " in input.attrs["class"]: - $:input.render() - $ list_vocabs = "//".join(list(skos_vocabs.keys())) - $ selectedVocabs = str(skos_vocabs) - - $if len(graphdata[id]) > 0 and "multimedia" not in input.attrs["class"] and "websitePreview" not in input.attrs["class"]: + + $if type(graphdata[id][0]) is list: $:input.render() @@ -97,7 +92,7 @@

Review record

$if input.type=="text": $else: - + $if len(k_v) == 3: $ lang_id = id+'_mainLang'