Skip to content

Commit

Permalink
Merge branch 'egonw-chemistry/fasterRelatedSearch'
Browse files Browse the repository at this point in the history
  • Loading branch information
fnielsen committed Apr 5, 2023
2 parents 24b6785 + 41b6cce commit b809ca0
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions scholia/app/templates/chemical_related.sparql
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
PREFIX target: <http://www.wikidata.org/entity/{{ q }}>

# title: related chemical structures
SELECT ?mol ?molLabel ?InChIKey ?CAS ?ChemSpider ?PubChem_CID WHERE {
target: wdt:P235 ?queryKey .
?mol wdt:P235 ?InChIKey .
SELECT ?mol ?molLabel ?InChIKey ?CAS ?ChemSpider ?PubChem_CID WITH {
SELECT ?queryKey ?srsearch ?filter WHERE {
target: wdt:P235 ?queryKey .
BIND (CONCAT(substr($queryKey,1,14), " haswbstatement:P235") AS ?srsearch)
BIND (CONCAT("^", substr($queryKey,1,14)) AS ?filter)
}
} AS %MOLS WITH {
SELECT ?mol ?InChIKey WHERE {
INCLUDE %MOLS
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "www.wikidata.org";
wikibase:api "Search";
mwapi:srsearch ?srsearch;
mwapi:srlimit "max".
?mol wikibase:apiOutputItem mwapi:title.
}
?mol wdt:P235 ?InChIKey .
FILTER (regex(str(?InChIKey), ?filter))
FILTER (?InChIKey != ?queryKey)
}
} AS %MOLS2 {
INCLUDE %MOLS2
OPTIONAL { ?mol wdt:P231 ?CAS }
OPTIONAL { ?mol wdt:P661 ?ChemSpider }
OPTIONAL { ?mol wdt:P662 ?PubChem_CID }
FILTER (regex(str(?InChIKey), concat("^", substr($queryKey,1,14), "-")))
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

0 comments on commit b809ca0

Please sign in to comment.