Skip to content

Commit

Permalink
Merge 43333c1 into 92c3422
Browse files Browse the repository at this point in the history
  • Loading branch information
mboudet committed Jun 6, 2023
2 parents 92c3422 + 43333c1 commit 7d8c303
Show file tree
Hide file tree
Showing 13 changed files with 4,085 additions and 2,891 deletions.
62 changes: 55 additions & 7 deletions askomics/libaskomics/SparqlQuery.py
Expand Up @@ -1116,7 +1116,7 @@ def build_query_from_json(self, preview=False, for_editor=False):
pblock_ids = link["source"]["specialPreviousIds"]

# Position
if link["uri"] in ('included_in', 'overlap_with'):
if link["uri"] in ('included_in', 'overlap_with', 'distance_from'):

# If source of target is a special node, replace the id with the id of the concerned node
source_id = link["source"]["id"]
Expand Down Expand Up @@ -1192,6 +1192,16 @@ def build_query_from_json(self, preview=False, for_editor=False):
end2=end_2,
equalsign=equal_sign
), block_id, sblock_id, pblock_ids)
else:
for filter in link.get('faldoFilters', []):
modifier_string = ""
if filter['filterValue']:
modifier_string = " {} {}".format(filter['filterModifier'], filter['filterValue'])

start = start_1 if filter['filterStart'] == "start" else end_1
end = start_2 if filter['filterEnd'] == "start" else end_2
filter_string = "FILTER ( {} {} {} {} ) .".format(start, filter['filterSign'], end, modifier_string)
self.store_filter(filter_string, block_id, sblock_id, pblock_ids)

# Classic relation
else:
Expand Down Expand Up @@ -1311,7 +1321,11 @@ def build_query_from_json(self, preview=False, for_editor=False):
attributes[attribute["linkedWith"]]["entity_id"],
attributes[attribute["linkedWith"]]["label"]
))
var_to_replace.append((obj, var_2))
if not attribute.get('linkedNegative', False):
var_to_replace.append((obj, var_2))
else:
filter_string = "FILTER ( {} {} {} ) .".format(obj, "!=", var_2)
self.store_filter(filter_string, block_id, sblock_id, pblock_ids)

# Text
if attribute["type"] == "text":
Expand Down Expand Up @@ -1352,7 +1366,17 @@ def build_query_from_json(self, preview=False, for_editor=False):
attributes[attribute["linkedWith"]]["entity_id"],
attributes[attribute["linkedWith"]]["label"]
))
var_to_replace.append((obj, var_2))
any([filter['filterSign'] == "=" and not filter['filterValue'] for filter in attribute.get('linkedFilters', [])])

if not (attribute.get('linkedNegative', False) or attribute.get('linkedFilterValue')):
var_to_replace.append((obj, var_2))
else:
filter = "!" if attribute.get('linkedNegative', False) else ""
regex_clause = var_2
if attribute.get('linkedFilterValue'):
regex_clause = r"REGEX({}, REPLACE('{}', '\\\$1', {}), 'i')".format(obj, attribute.get('linkedFilterValue', "$1"), var_2)
filter_string = "FILTER ( {} {} ) .".format(filter, regex_clause)
self.store_filter(filter_string, block_id, sblock_id, pblock_ids)

# Numeric
if attribute["type"] == "decimal":
Expand Down Expand Up @@ -1385,7 +1409,15 @@ def build_query_from_json(self, preview=False, for_editor=False):
attributes[attribute["linkedWith"]]["entity_id"],
attributes[attribute["linkedWith"]]["label"]
))
var_to_replace.append((obj, var_2))
if any([filter['filterSign'] == "=" and not filter['filterValue'] for filter in attribute.get('linkedFilters', [])]):
var_to_replace.append((obj, var_2))
else:
for filter in attribute.get('linkedFilters', []):
modifier_string = ""
if filter['filterValue']:
modifier_string = " {} {}".format(filter['filterModifier'], filter['filterValue'])
filter_string = "FILTER ( {} {} {} {} ) .".format(obj, filter['filterSign'], var_2, modifier_string)
self.store_filter(filter_string, block_id, sblock_id, pblock_ids)

if attribute["type"] == "date":
if attribute["visible"] or Utils.check_key_in_list_of_dict(attribute["filters"], "filterValue") or attribute["id"] in linked_attributes:
Expand Down Expand Up @@ -1416,8 +1448,19 @@ def build_query_from_json(self, preview=False, for_editor=False):
attributes[attribute["linkedWith"]]["entity_id"],
attributes[attribute["linkedWith"]]["label"]
))
var_to_replace.append((obj, var_2))

if any([filter['filterSign'] == "=" and not filter['filterValue'] for filter in attribute.get('linkedFilters', [])]):
var_to_replace.append((obj, var_2))
else:
for filter in attribute.get('linkedFilters', []):
modifier_string = ""
if filter['filterValue']:
# Issue with virtuoso: engine-specific syntax for now (convert days to seconds)
if self.settings.get('triplestore', 'triplestore') == "virtuoso":
modifier_string = " {} {}".format(filter['filterModifier'], 24 * 3600 * int(filter['filterValue']))
else:
modifier_string = ' {} "P{}D"xsd:duration'.format(filter['filterModifier'], filter['filterValue'])
filter_string = "FILTER ( {} {} {} {} ) .".format(obj, filter['filterSign'], var_2, modifier_string)
self.store_filter(filter_string, block_id, sblock_id, pblock_ids)
# Category
if attribute["type"] == "category":
if attribute["visible"] or attribute["filterSelectedValues"] != [] or attribute["id"] in strands or attribute["id"] in linked_attributes:
Expand Down Expand Up @@ -1505,7 +1548,12 @@ def build_query_from_json(self, preview=False, for_editor=False):
attributes[attribute["linkedWith"]]["entity_id"],
attributes[attribute["linkedWith"]]["label"]
))
var_to_replace.append((category_value_uri, var_2))

if not attribute.get('linkedNegative', False):
var_to_replace.append((category_value_uri, var_2))
else:
filter_string = "FILTER ( {} {} {} ) .".format(category_value_uri, "!=", var_2)
self.store_filter(filter_string, block_id, sblock_id, pblock_ids)

from_string = "" if self.settings.getboolean("askomics", "single_tenant", fallback=False) else self.get_froms_from_graphs(self.graphs)
federated_from_string = self.get_federated_froms_from_graphs(self.graphs)
Expand Down
4 changes: 3 additions & 1 deletion askomics/react/src/navbar.jsx
Expand Up @@ -44,6 +44,7 @@ export default class AskoNavbar extends Component {

links = (
<>
{overviewLink}
{contactLink}
<NavItem><Link className="nav-link" to="/about"><i className="fas fa-info"></i> About</Link></NavItem>
<NavItem><Link className="nav-link" to="/login"><i className="fas fa-sign-in-alt"></i> Login</Link></NavItem>
Expand Down Expand Up @@ -75,6 +76,7 @@ export default class AskoNavbar extends Component {
<>
<NavItem><Link className="nav-link" to="/results"><i className="fas fa-tasks"></i> Results</Link></NavItem>
{integrationLinks}
{overviewLink}
{contactLink}
<NavItem><Link className="nav-link" to="/about"><i className="fas fa-info"></i> About</Link></NavItem>
<NavItem>
Expand All @@ -100,6 +102,7 @@ export default class AskoNavbar extends Component {
links = (
<>
<NavItem><Link className="nav-link" to="/results"><i className="fas fa-tasks"></i> Results</Link></NavItem>
{overviewLink}
{contactLink}
<NavItem><Link className="nav-link" to="/about"><i className="fas fa-info"></i> About</Link></NavItem>
<NavItem><Link className="nav-link" to="/login"><i className="fas fa-sign-in-alt"></i> Login</Link></NavItem>
Expand All @@ -116,7 +119,6 @@ export default class AskoNavbar extends Component {
<Collapse navbar>
<Nav className="ml-auto" navbar>
{askLink}
{overviewLink}
{links}
</Nav>
</Collapse>
Expand Down

0 comments on commit 7d8c303

Please sign in to comment.