def drop_all(): print "{}{}{}".format( "\n====================================================================================\n", "List of graphs dropped\n", "====================================================================================" ) drops = """ ################################################################# ### DELETE NAMED GRAPHS ### ################################################################# DELETE {{ GRAPH ?graph {{ ?s ?p ?o }} }} where {{ GRAPH ?graph {{ ?s ?p ?o }} }} """ print drops print "{}{}{}".format( "\n=====================================================================\n", "DROPPING ALL...\nPLEASE WAIT FOR FEEDBACK.\n", "=====================================================================" ) print endpoint(drops)
def drop_a_research_question(graph, display=False, activated=False): query = """DROP SILENT GRAPH <{}>""".format(graph) if activated is True: print "{}{}{}".format( "=======================================================" "=======================================================\n", "DROPPING A RESEARCH QUESTIONS...\nPLEASE WAIT FOR FEEDBACK.", "\n=======================================================" "=======================================================") drop_start = time.time() try: drops_response = endpoint(query) except Exception as error: print "\t>>> Query NOT executed'" print "\t>>>", error.message return error.message drop_end = time.time() if drops_response[St.result] is not None: if len(drops_response[St.result]) == 0: return 'The query was successfully executed but no feedback was returned' # print "drops_response", drops_response[St.result] drops_doc = xmltodict.parse(drops_response[St.result]) print "\t>>> Query executed : {:<14}".format( drops_doc['sparql']['boolean']) print "\t>>> Executed in : {:<14} minute(s)".format( str((drop_end - drop_start) / 60)) if display is True: print "\t>>> Query details : {}\n".format(query) print "" return 'The query was successfully executed' else: return 'The query was not executed'
def drop_all_research_questions(display=False, activated=False): query = """ DELETE {GRAPH ?g {?s ?p ?o.} } WHERE { graph ?g { ?rq rdf:type <http://risis.eu/class/ResearchQuestion> . ?s ?p ?o. } }""" if activated is True: print "{}{}{}".format( "=======================================================" "=======================================================\n", "DROPPING ALL RESEARCH QUESTIONS...\nPLEASE WAIT FOR FEEDBACK.", "\n=======================================================" "=======================================================") drop_start = time.time() drops_response = endpoint(query) drop_end = time.time() if drops_response[St.result] is not None: if len(drops_response[St.result]) == 0: return error drops_doc = xmltodict.parse(drops_response[St.result]) print "\t>>> Query executed : {:<14}".format( drops_doc['sparql']['boolean']) print "\t>>> Executed in : {:<14} minute(s)".format( str((drop_end - drop_start) / 60)) if display is True: print ">>> Query details : {}\n".format(query) print ""
def get_namedgraph_size(linkset_uri, isdistinct=False): distinct = "" if isdistinct is True: distinct = "DISTINCT " check_query = "\n{}\n{}\n{}\n{}\n{}\n{}\n{}".format( # "PREFIX linkset: <http://risis.eu/linkset/>", # "PREFIX lsMetadata: <http://risis.eu/linkset/metadata/>", # "PREFIX predicate: <http://risis.eu/linkset/predicate/>", # "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>", " ##### GETTING THE LINKSET SIZE", " select(count({}?source) as ?triples)".format(distinct), " WHERE ", " {", " GRAPH <{}>".format(linkset_uri), " { ?source ?predicate ?target }", " }") # print check_query result = endpoint(check_query) # print result if result[St.result] is not None: dropload_doc = xmltodict.parse(result[St.result]) return dropload_doc['sparql']['results']['result']['binding'][ 'literal']['#text'] else: return None
def delete_aligned_linkset(research_uri, alignment_uri, display=False, activated=False): query = """ DELETE {{ graph <{0}> {{ ?alignment ?alignmentProperty <{1}> . }} }} WHERE {{ graph <{0}> {{ ?alignment a <http://risis.eu/class/AlignmentMapping> . ?alignment ?alignmentProperty <{1}> . }} }} """.format(research_uri, alignment_uri) if display is True: print query if activated is True: print "{}{}{}".format( "=======================================================" "=======================================================\n", "DROPPING THE SELECTED ALIGNMENT:\n[{}]\nPLEASE WAIT FOR FEEDBACK..." .format(alignment_uri), "\n=======================================================" "=======================================================") drop_start = time.time() drops_response = endpoint(query) drop_end = time.time() if drops_response[St.result] is not None: if len(drops_response[St.result]) == 0: return error drops_doc = xmltodict.parse(drops_response[St.result]) print "\t>>> Query executed : {:<14}".format( drops_doc['sparql']['boolean']) print "\t>>> Executed in : {:<14} minute(s)".format( str((drop_end - drop_start) / 60)) if display is True: print ">>> Query details : {}\n".format(query) print ""
def delete_aligned_linksets(research_uri, display=False, activated=False): query = """ DELETE {{ GRAPH <{0}> {{ ?alignment <{2}used> ?linkset. ?alignment <{3}created> ?linkset. }} }} WHERE {{ graph <{0}> {{ ?alignment a <{1}AlignmentMapping> ; (<{2}used>|<{3}created>) ?linkset. }} }} """.format(research_uri, Ns.riclass, Ns.prov, Ns.alivocab) if display is True: print query if activated is True: print "{}{}{}".format( "=======================================================" "=======================================================\n", "DROPPING ALL CREATED OR USED LINKSET REGISTERED FOR :\n[{}]\nPLEASE WAIT FOR FEEDBACK..." .format(research_uri), "\n=======================================================" "=======================================================") drop_start = time.time() drops_response = endpoint(query) drop_end = time.time() if drops_response[St.result] is not None: if len(drops_response[St.result]) == 0: return error drops_doc = xmltodict.parse(drops_response[St.result]) print "\t>>> Query executed : {:<14}".format( drops_doc['sparql']['boolean']) print "\t>>> Executed in : {:<14} minute(s)".format( str((drop_end - drop_start) / 60)) if display is True: print ">>> Query details : {}\n".format(query) print ""
def drop_research_question_lenses(research_uri, display=False, activated=False): query = """ DELETE {{ GRAPH <{0}> {{ ?research_question ?p ?lens. ?lens a bdb:Lens. }} }} WHERE {{ graph <{0}> {{ ?research_question ?p ?lens. }} ?lens a bdb:Lens. }}""".format(research_uri, Ns.riclass) if activated is True: print "{}{}{}".format( "=======================================================" "=======================================================\n", "DROPPING ALL LENSES REGISTERED UNDER [{}]..\nPLEASE WAIT FOR FEEDBACK." .format(research_uri), "\n=======================================================" "=======================================================") drop_start = time.time() drops_response = endpoint(query) drop_end = time.time() if drops_response[St.result] is not None: if len(drops_response[St.result]) == 0: return error drops_doc = xmltodict.parse(drops_response[St.result]) print "\t>>> Query executed : {:<14}".format( drops_doc['sparql']['boolean']) print "\t>>> Executed in : {:<14} minute(s)".format( str((drop_end - drop_start) / 60)) if display is True: print ">>> Query details : {}\n".format(query) print ""
def drop_linkset(graph, display=False, activated=False): queries = """ ################################################################# ### DELETE LINKSET NAMED GRAPHS AND METADATA ### ################################################################# ### 1. DELETING GRAPHS's METADATA PREFIX void: <{0}> PREFIX bdb: <{1}> PREFIX link: <{2}> DELETE {{ ?linktype ?x ?y }} where {{ <{3}> void:linkPredicate ?linktype . ?linktype ?x ?y }} ; ### 2. DELETING ASSERTION METADATA DELETE {{ ?assertionMethod ?x ?y }} where {{ <{3}> bdb:assertionMethod ?assertionMethod . ?assertionMethod ?x ?y }} ; ### 3. DELETING JUSTIFICATION METADATA DELETE {{ ?linksetJustification ?x ?y }} where {{ <{3}> bdb:linksetJustification ?linksetJustification . ?linksetJustification ?x ?y }} ; ### 4. DELETING THE SINGLETON GRAPH DELETE {{ GRAPH ?singletonGraph {{ ?x ?y ?z }} }} where {{ <{3}> link:singletonGraph ?singletonGraph . GRAPH ?singletonGraph {{ ?x ?y ?z }} . }} ; ### 5. DELETING THE META DATA DELETE {{ <{3}> ?x ?y . }} where {{ <{3}> ?x ?y }} ; ################################################################# ### DELETE LINKSET NAMED GRAPHS ### ################################################################# DROP SILENT GRAPH <{3}> """.format(Ns.void, Ns.bdb, Ns.alivocab, graph) if activated is False and display is True: print queries # print endpoint(queries, database_name, host) if activated is True: print "{}{}{}".format( "=======================================================" "=======================================================\n", "DROPPING THE LINKSET GRAPH <{}>... \nPLEASE WAIT FOR FEEDBACK.". format(graph), "\n=======================================================" "=======================================================") drop_start = time.time() drops_response = endpoint(queries) drop_end = time.time() if drops_response[St.result] is not None: if len(drops_response[St.result]) == 0: return error drops_doc = xmltodict.parse(drops_response[St.result]) print "\t>>> Query executed : {:<14}".format( drops_doc['sparql']['boolean']) print "\t>>> Executed in : {:<14} minute(s)".format( str((drop_end - drop_start) / 60)) if display is True: print ">>> Query details : {}\n".format(queries) print ""
def drop_unions(display=False, activated=False): queries = """ PREFIX void: <{}> PREFIX bdb: <{}> PREFIX alivocab: <{}> PREFIX lensOp: <{}> ### DELETING THE METHOD RESOURCE DELETE {{ ?method ?x ?y }} WHERE {{ ?lens a bdb:Lens ; alivocab:operator lensOp:union ; bdb:assertionMethod ?method . ?method ?x ?y . }} ; ### DELETING THE METADATA DELETE {{ ?lens ?x ?y }} WHERE {{ ?lens a bdb:Lens ; alivocab:operator lensOp:union ; ?x ?y . }} ; ################################################################# ### DELETE LINKSET NAMED GRAPHS ### ################################################################# DELETE {{ GRAPH ?graph {{ ?s ?p ?o }} }} where {{ GRAPH ?graph {{ ?s ?p ?o }} Filter regex(str(?graph), 'union_', 'i') }} """.format(Ns.void, Ns.bdb, Ns.alivocab, Ns.lensOp) if activated is True: print "{}{}{}".format( "=======================================================" "=======================================================\n", "DROPPING UNION...\nPLEASE WAIT FOR FEEDBACK", "\n=======================================================" "=======================================================", ) drop_start = time.time() drops_response = endpoint(queries) drop_end = time.time() if drops_response[St.result] is not None: if len(drops_response[St.result]) == 0: return error drops_doc = xmltodict.parse(drops_response[St.result]) print "\t>>> Query executed : {:<14}".format( drops_doc['sparql']['boolean']) print "\t>>> Executed in : {:<14} minute(s)".format( str((drop_end - drop_start) / 60)) if display is True: print ">>> Query details : {}\n".format(queries) print ""
def drop_a_lens(lens, display=False, activated=False): queries = """ PREFIX void: <{0}> PREFIX bdb: <{1}> PREFIX link: <{2}> ### 1. DELETING ASSERTION METHOD DELETE {{ ?assertionMethod ?x ?y }} where {{ <{3}> a bdb:Lens ; bdb:assertionMethod ?assertionMethod . ?assertionMethod ?x ?y . }} ; ### 2. DELETING JUSTIFICATION DELETE {{ ?linksetJustification ?x ?y }} where {{ <{3}> a bdb:Lens ; bdb:linksetJustification ?linksetJustification ;. ?linksetJustification ?x ?y . }} ; ### 3. DELETING LINK-TYPE DELETE {{ ?linkPredicate ?x ?y }} where {{ <{3}> a bdb:Lens ; void:linkPredicate ?linkPredicate . ?linkPredicate ?x ?y . }} ; ### 4. DELETING THE SINGLETON GRAPH DELETE {{ GRAPH ?singletonGraph {{ ?x ?y ?z }} }} where {{ <{3}> a bdb:Lens ; link:singletonGraph ?singletonGraph . GRAPH ?singletonGraph {{ ?x ?y ?z }} . }} ; ### 5. DELETING THE METADATA DELETE {{ <{3}> ?x ?y }} where {{ <{3}> a bdb:Lens ; ?x ?y. }} ; ################################################################# ### DELETE LINKSET NAMED GRAPHS ### ################################################################# DROP SILENT GRAPH <{3}> """.format(Ns.void, Ns.bdb, Ns.alivocab, lens) if activated is True: print "{}{}{}".format( "=======================================================" "=======================================================\n", "DROPPING A LENS...\nPLEASE WAIT FOR FEEDBACK.", "\n=======================================================" "=======================================================") # print queries drop_start = time.time() drops_response = endpoint(queries) drop_end = time.time() print drops_response, "Done!!!" if drops_response[St.result] is not None: if len(drops_response[St.result]) == 0: return error drops_doc = xmltodict.parse(drops_response[St.result]) print "\t>>> Query executed : {:<14}".format( drops_doc['sparql']['boolean']) print "\t>>> Executed in : {:<14} minute(s)".format( str((drop_end - drop_start) / 60)) if display is True: print ">>> Query details : {}\n".format(queries) print ""