From 6243690351ca16f20af40652e814ccad5cdefdef Mon Sep 17 00:00:00 2001 From: Jamie McCusker Date: Mon, 18 Nov 2024 15:19:14 -0500 Subject: [PATCH] Added some query efficiency and flexibility to the incoming and outgoing view. --- whyis/_version.py | 2 +- whyis/filters.py | 33 ++++++++++++++++---------- whyis/templates/incoming_class.json | 14 +++++++++-- whyis/templates/incoming_ontology.json | 14 +++++++++-- whyis/templates/incoming_resource.json | 14 ++++++++--- whyis/templates/outgoing_class.json | 13 ++++++++-- whyis/templates/outgoing_ontology.json | 14 +++++++++++ whyis/templates/outgoing_resource.json | 12 ++++++++-- 8 files changed, 92 insertions(+), 24 deletions(-) diff --git a/whyis/_version.py b/whyis/_version.py index ede19653..929d08dc 100644 --- a/whyis/_version.py +++ b/whyis/_version.py @@ -1,4 +1,4 @@ -__version__='2.3.17' +__version__='2.3.18' if __name__ == '__main__': print(__version__) diff --git a/whyis/filters.py b/whyis/filters.py index 4fed1d83..784b93fe 100644 --- a/whyis/filters.py +++ b/whyis/filters.py @@ -225,22 +225,23 @@ def probquery(select): # ?assertion a np:Assertion. ?np np:hasAssertion ?assertion. - optional { - ?np np:hasProvenance ?provenance - graph ?provenance { - ?assertion prov:wasDerivedFrom|dc:references ?article. - #?article a sio:PeerReviewedArticle. - } + + # optional { +# ?np np:hasProvenance ?provenance +# graph ?provenance { +# ?assertion prov:wasDerivedFrom|dc:references ?article. +# #?article a sio:PeerReviewedArticle. +# } optional { - ?article sio:hasAttribute|sio:SIO_000008 [ a whyis:ConfidenceScore; sio:hasValue|sio:SIO_000300 ?probability]. + ?article sio:hasAttribute [ a whyis:ConfidenceScore; sio:hasValue ?probability]. } minus { ?article a np:Nanopublication.} } optional { graph ?prob_assertion { - { ?assertion sio:hasAttribute|sio:SIO_000008 [ a sio:ProbabilityMeasure; sio:hasValue|sio:SIO_000300 ?probability]. } + { ?assertion sio:hasAttribute [ a sio:ProbabilityMeasure; sio:hasValue ?probability]. } UNION - { ?assertion sio:hasAttribute|sio:SIO_000008 [ a sio:SIO_000638; sio:hasValue|sio:SIO_000300 ?probability]. } + { ?assertion sio:SIO_000008 [ a sio:SIO_000638; sio:SIO_000300 ?probability]. } } ?prob_np np:hasAssertion ?prob_assertion. } @@ -284,8 +285,10 @@ def merge(links): i['probability'] = combine_pvalues([tfidf/(1+tfidf)],method='stouffer')[1] else: i['probability'] = i['probability'].value - result['from'].append(i['np']) - result['articles'].extend(i['articles']) + if 'np' in i: + result['from'].append(i['np']) + if 'artciles' in i: + result['articles'].extend(i['articles']) result['probability'] = max([i['probability'] for i in links]) #print "end: " return result @@ -308,7 +311,8 @@ def merge(links): result = dict(links[0]) result['from'] = [] result['articles'] = [] - del result['np'] + if 'np' in result: + del result['np'] for i in links: result['from'].extend(i['from']) result['articles'].extend(i['articles']) @@ -338,6 +342,11 @@ def probit(q, **values): results = query_filter(q, values=values) results = mergeLink(results) results = sorted(mergeLinkTypes(results), key=lambda x: x['probability'], reverse=True) + results = add_types_and_labels(results) + return results + + @app.template_filter('add_types_and_labels') + def add_types_and_labels(results): for r in results: if 'link_type' in r: labelize(r, 'link_type', 'link_label') diff --git a/whyis/templates/incoming_class.json b/whyis/templates/incoming_class.json index 23449f88..c9570a18 100644 --- a/whyis/templates/incoming_class.json +++ b/whyis/templates/incoming_class.json @@ -6,10 +6,20 @@ } bind(1 as ?probability) bind(?assertion as ?link) - minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type| ?target.} - minus { ?source sio:hasPart|sio:SIO_000028|sio:hasAttribute|sio:SIO_000008 ?target } + + filter(!isLiteral(?target)) + minus { ?source owl:sameAs ?target.} + minus { ?source rdfs:seeAlso ?target.} + minus { ?source rdf:type ?target.} + minus { ?source ?target.} + minus { ?source foaf:depiction ?target. + minus { ?source sio:hasPart ?target.} + minus { ?source sio:SIO_000028 ?target.} + minus { ?source sio:hasAttribute ?target.} + minus { ?source sio:SIO_000008 ?target. } minus { ?target a sio:Term.} minus { ?target a sio:SIO_000275.} filter (!sameTerm(?source, ?target) && isIRI(?target)) + FILTER (!regex(str(?source), "^bnode:")) ''' | probit(target=this.identifier) | tojson }} diff --git a/whyis/templates/incoming_ontology.json b/whyis/templates/incoming_ontology.json index f7421cec..efc9068b 100644 --- a/whyis/templates/incoming_ontology.json +++ b/whyis/templates/incoming_ontology.json @@ -7,10 +7,20 @@ bind(1 as ?probability) values ?link_type {owl:imports} bind(?assertion as ?link) - minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type| ?target.} - minus { ?source sio:hasPart|sio:SIO_000028|sio:hasAttribute|sio:SIO_000008 ?target } + + filter(!isLiteral(?target)) + minus { ?source owl:sameAs ?target.} + minus { ?source rdfs:seeAlso ?target.} + minus { ?source rdf:type ?target.} + minus { ?source ?target.} + minus { ?source foaf:depiction ?target. + minus { ?source sio:hasPart ?target.} + minus { ?source sio:SIO_000028 ?target.} + minus { ?source sio:hasAttribute ?target.} + minus { ?source sio:SIO_000008 ?target. } minus { ?target a sio:Term.} minus { ?target a sio:SIO_000275.} filter (!sameTerm(?source, ?target) && isIRI(?target)) + FILTER (!regex(str(?source), "^bnode:")) ''' | probit(target=this.identifier) | tojson }} diff --git a/whyis/templates/incoming_resource.json b/whyis/templates/incoming_resource.json index 9fe6e1f2..3d574c24 100644 --- a/whyis/templates/incoming_resource.json +++ b/whyis/templates/incoming_resource.json @@ -4,9 +4,17 @@ } } bind(?assertion as ?link) - minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type| ?target.} - minus { ?source sio:hasPart|sio:SIO_000028|sio:hasAttribute|sio:SIO_000008 ?target } - minus { ?source a sio:Term } + filter(!isLiteral(?target)) + minus { ?source owl:sameAs ?target.} + minus { ?source rdfs:seeAlso ?target.} + minus { ?source rdf:type ?target.} + minus { ?source ?target.} + minus { ?source foaf:depiction ?target. + minus { ?source sio:hasPart ?target.} + minus { ?source sio:SIO_000028 ?target.} + minus { ?source sio:hasAttribute ?target.} + minus { ?source sio:SIO_000008 ?target. } + minus { ?target a sio:Term.} minus { ?target a sio:SIO_000275.} filter (!sameTerm(?source, ?target) && isIRI(?target)) diff --git a/whyis/templates/outgoing_class.json b/whyis/templates/outgoing_class.json index 06bec5a2..0e0eab75 100644 --- a/whyis/templates/outgoing_class.json +++ b/whyis/templates/outgoing_class.json @@ -6,8 +6,17 @@ } bind(1 as ?probability) bind(?assertion as ?link) - minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type| ?target.} - minus { ?source sio:hasPart|sio:SIO_000028|sio:hasAttribute|sio:SIO_000008 ?target } + + filter(!isLiteral(?target)) + minus { ?source owl:sameAs ?target.} + minus { ?source rdfs:seeAlso ?target.} + minus { ?source rdf:type ?target.} + minus { ?source ?target.} + minus { ?source foaf:depiction ?target. + minus { ?source sio:hasPart ?target.} + minus { ?source sio:SIO_000028 ?target.} + minus { ?source sio:hasAttribute ?target.} + minus { ?source sio:SIO_000008 ?target. } minus { ?target a sio:Term.} minus { ?target a sio:SIO_000275.} filter (!sameTerm(?source, ?target) && isIRI(?target)) diff --git a/whyis/templates/outgoing_ontology.json b/whyis/templates/outgoing_ontology.json index 9b5c4a25..93931c81 100644 --- a/whyis/templates/outgoing_ontology.json +++ b/whyis/templates/outgoing_ontology.json @@ -19,10 +19,24 @@ } bind(1 as ?probability) bind(?assertion as ?link) + + filter(!isLiteral(?target)) + minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type| ?target.} minus { ?source sio:hasPart|sio:SIO_000028|sio:hasAttribute|sio:SIO_000008 ?target } minus { ?target a sio:Term.} minus { ?target a sio:SIO_000275.} + minus { ?source owl:sameAs ?target.} + minus { ?source rdfs:seeAlso ?target.} + minus { ?source rdf:type ?target.} + minus { ?source ?target.} + minus { ?source foaf:depiction ?target. + minus { ?source sio:hasPart ?target.} + minus { ?source sio:SIO_000028 ?target.} + minus { ?source sio:hasAttribute ?target.} + minus { ?source sio:SIO_000008 ?target. } + minus { ?target a sio:Term.} + minus { ?target a sio:SIO_000275.} filter (!sameTerm(?source, ?target) && isIRI(?target)) FILTER (!regex(str(?source), "^bnode:")) ''' | probit(source=this.identifier) | tojson }} diff --git a/whyis/templates/outgoing_resource.json b/whyis/templates/outgoing_resource.json index bce2a88b..a5f810b4 100644 --- a/whyis/templates/outgoing_resource.json +++ b/whyis/templates/outgoing_resource.json @@ -4,8 +4,16 @@ } } bind(?assertion as ?link) - minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type||foaf:depiction ?target.} - minus { ?source sio:hasPart|sio:SIO_000028|sio:hasAttribute|sio:SIO_000008 ?target } + filter(!isLiteral(?target)) + minus { ?source owl:sameAs ?target.} + minus { ?source rdfs:seeAlso ?target.} + minus { ?source rdf:type ?target.} + minus { ?source ?target.} + minus { ?source foaf:depiction ?target. + minus { ?source sio:hasPart ?target.} + minus { ?source sio:SIO_000028 ?target.} + minus { ?source sio:hasAttribute ?target.} + minus { ?source sio:SIO_000008 ?target. } minus { ?target a sio:Term.} minus { ?target a sio:SIO_000275.} filter (!sameTerm(?source, ?target) && isIRI(?target))