From dff2ed43da1b02e11b02e41a12f40695ee9bebfa Mon Sep 17 00:00:00 2001 From: Eric Yu Date: Mon, 18 Oct 2021 20:36:58 -0600 Subject: [PATCH] Add filter to subjects in sequence search --- flask/search.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/flask/search.py b/flask/search.py index ebe3436..a801f26 100644 --- a/flask/search.py +++ b/flask/search.py @@ -607,7 +607,7 @@ def search(sparql_query, uri2rank, clusters, default_graph_uri): if 'file_search' in flags: filename = str(flags['file_search']) results = sequencesearch.sequence_search(flags, filename) - sequence_criteria = create_sequence_criteria(criteria, results) + sequence_criteria = create_sequence_criteria(criteria, filter_sequence_search_subjects(_from, results)) criteria_response = query.query_parts(_from, sequence_criteria) bindings = create_criteria_bindings(criteria_response, uri2rank, True, filename[:-4] + '.uc') @@ -618,7 +618,7 @@ def search(sparql_query, uri2rank, clusters, default_graph_uri): # return new clusters here # pass into func -> queryparts create_sequence_criteria - sequence_criteria = create_sequence_criteria(criteria, results) + sequence_criteria = create_sequence_criteria(criteria, filter_sequence_search_subjects(_from, results)) criteria_response = query.query_parts(_from, sequence_criteria) bindings = create_criteria_bindings(criteria_response, uri2rank, True, temp_filename[:-4] + '.uc') @@ -729,3 +729,20 @@ def get_cigar_data(uri, ucTableName): return line[7] return 'N/A' + +def filter_sequence_search_subjects(_from, uris): + """ + Adds filters to SPARQL based on the allowed graphs and URI's from sequence search + + [description] + + Arguments: + _from {list} -- List of allowed graphs + uris {list} -- List of URI's from sequence search + """ + from_uris = [] + result = re.findall(r"\<([A-Za-z0-9:\/.]+)\>*", _from) + for r in result: + from_uris.append(r) + + return [uri for uri in uris if any(f for f in from_uris if f in uri)]