Skip to content

Commit

Permalink
Added some query efficiency and flexibility to the incoming and outgo…
Browse files Browse the repository at this point in the history
…ing view.
  • Loading branch information
jpmccu committed Nov 18, 2024
1 parent c542c19 commit 6243690
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 24 deletions.
2 changes: 1 addition & 1 deletion whyis/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__='2.3.17'
__version__='2.3.18'

if __name__ == '__main__':
print(__version__)
33 changes: 21 additions & 12 deletions whyis/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down Expand Up @@ -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
Expand All @@ -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'])
Expand Down Expand Up @@ -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')
Expand Down
14 changes: 12 additions & 2 deletions whyis/templates/incoming_class.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@
}
bind(1 as ?probability)
bind(?assertion as ?link)
minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type|<http://dbpedia.org/ontology/wikiPageExternalLink> ?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 <http://dbpedia.org/ontology/wikiPageExternalLink> ?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 }}
14 changes: 12 additions & 2 deletions whyis/templates/incoming_ontology.json
Original file line number Diff line number Diff line change
Expand Up @@ -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|<http://dbpedia.org/ontology/wikiPageExternalLink> ?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 <http://dbpedia.org/ontology/wikiPageExternalLink> ?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 }}
14 changes: 11 additions & 3 deletions whyis/templates/incoming_resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
}
}
bind(?assertion as ?link)
minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type|<http://dbpedia.org/ontology/wikiPageExternalLink> ?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 <http://dbpedia.org/ontology/wikiPageExternalLink> ?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))

Expand Down
13 changes: 11 additions & 2 deletions whyis/templates/outgoing_class.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
}
bind(1 as ?probability)
bind(?assertion as ?link)
minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type|<http://dbpedia.org/ontology/wikiPageExternalLink> ?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 <http://dbpedia.org/ontology/wikiPageExternalLink> ?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))
Expand Down
14 changes: 14 additions & 0 deletions whyis/templates/outgoing_ontology.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@
}
bind(1 as ?probability)
bind(?assertion as ?link)

filter(!isLiteral(?target))

minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type|<http://dbpedia.org/ontology/wikiPageExternalLink> ?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 <http://dbpedia.org/ontology/wikiPageExternalLink> ?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 }}
12 changes: 10 additions & 2 deletions whyis/templates/outgoing_resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
}
}
bind(?assertion as ?link)
minus { ?source owl:sameAs|rdfs:seeAlso|rdf:type|<http://dbpedia.org/ontology/wikiPageExternalLink>|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 <http://dbpedia.org/ontology/wikiPageExternalLink> ?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))
Expand Down

0 comments on commit 6243690

Please sign in to comment.