sparql-examples

A set of SPARQL examples

View the Project on GitHub Adafede/sparql-examples

wd_chemicals_statistics

rq turtle/ttl

Chemicals statistics.

Use at


PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX mwapi: <https://www.mediawiki.org/ontology#API/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT
(xsd:integer(?count_) AS ?count)
(CONCAT("Total chemicals with ", ?description_) AS ?description)
WHERE {
    BIND("haswbstatement:P31=Q113145171|P31=Q59199015" AS ?constraint)
    VALUES (?description_ ?property_query_term) {
        ("or without stereochemistry" "")
        ("fully defined stereochemistry" "P31=Q113145171")
        ("undefined stereochemistry" "P31=Q59199015")
        ("CAS registry number" "P231")
        ("canonical SMILES" "P233")
        ("InChI" "P234")
        ("InChIKey" "P235")
        ("chemical formula" "P274")
    # ("ChEMBL ID" "P592") # limit IDs
    # ("ChemSpider ID" "P661") # limit IDs
        ("PubChem ID" "P662")
    # ("KEGG ID" "P665") # limit IDs
        ("ChEBI ID" "P683")
        ("found in taxon" "P703")
        ("isomeric SMILES" "P2017")
    # ("ZINC ID" "P2084") # limit IDs
        ("crystal structure" "haswbstatement:P3636|P11375")
        ("safety classification and labelling" "P4952")
        ("mass spectrum" "haswbstatement:P4964|P6689")
    # ("SMARTS notation" "P8533") # not for now
        ("NMR spectrum" "P9405")
    # hacky way to get quantity properties.
        ("pKa" "linksto:Property:P1117")
        ("mass" "linksto:Property:P2067")
        ("solubility" "linksto:Property:P2177")
        ("melting point" "linksto:Property:P2101")
        ("boiling point" "linksto:Property:P2102")
        ("electric dipole moment" "linksto:Property:P2201")
        ("ionization energy" "linksto:Property:P2260")
    # ("minimum explosive concentration" "linksto:Property:P2204") # safety
    # ("time-weighted average exposure limit" "linksto:Property:P2404") # safety
    # ("ceiling exposure limit" "linksto:Property:P2405") # safety
    # ("maximum peak exposure limit" "linksto:Property:P2406") # safety
    # ("short-term exposure limit" "linksto:Property:P2407") # safety
    # ("solubility product constant" "linksto:Property:P11813") # less than 5 statements
    }
    BIND(CONCAT(?property_query_term, " ", ?constraint) AS ?search_query)
    SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:endpoint "www.wikidata.org" ;
        wikibase:api "Search" ;
        wikibase:limit "once" ;
        mwapi:srsearch ?search_query;
        mwapi:srlimit "1".
        ?count_ wikibase:apiOutput "//searchinfo[1]/@totalhits".
    }
}
ORDER BY DESC(?count)

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v2("?constraint")
  v7("?count")
  v6("?count_"):::projected 
  v7("?description")
  v3("?description_"):::projected 
  v4("?property_query_term")
  v5("?search_query")
  c4(["www.wikidata.org"]):::literal 
  c13(["//searchinfo#91;1#93;/@totalhits"]):::literal 
  c11(["1"]):::literal 
  c2([http://www.bigdata.com/rdf#serviceParam]):::iri 
  c8(["once"]):::literal 
  c6(["Search"]):::literal 
  bind0[/"'haswbstatement:P31=Q113145171|P31=Q59199015'"/]
  bind0 --as--o v2
  bind1[/VALUES ?description_ ?property_query_term/]
  bind1-->v3
  bind1-->v4
  bind10(["or without stereochemistry"])
  bind10 --> bind1
  bind11([""])
  bind11 --> bind1
  bind12(["fully defined stereochemistry"])
  bind12 --> bind1
  bind13(["P31=Q113145171"])
  bind13 --> bind1
  bind14(["undefined stereochemistry"])
  bind14 --> bind1
  bind15(["P31=Q59199015"])
  bind15 --> bind1
  bind16(["CAS registry number"])
  bind16 --> bind1
  bind17(["P231"])
  bind17 --> bind1
  bind18(["canonical SMILES"])
  bind18 --> bind1
  bind19(["P233"])
  bind19 --> bind1
  bind110(["InChI"])
  bind110 --> bind1
  bind111(["P234"])
  bind111 --> bind1
  bind112(["InChIKey"])
  bind112 --> bind1
  bind113(["P235"])
  bind113 --> bind1
  bind114(["chemical formula"])
  bind114 --> bind1
  bind115(["P274"])
  bind115 --> bind1
  bind116(["PubChem ID"])
  bind116 --> bind1
  bind117(["P662"])
  bind117 --> bind1
  bind118(["ChEBI ID"])
  bind118 --> bind1
  bind119(["P683"])
  bind119 --> bind1
  bind120(["found in taxon"])
  bind120 --> bind1
  bind121(["P703"])
  bind121 --> bind1
  bind122(["isomeric SMILES"])
  bind122 --> bind1
  bind123(["P2017"])
  bind123 --> bind1
  bind124(["crystal structure"])
  bind124 --> bind1
  bind125(["haswbstatement:P3636|P11375"])
  bind125 --> bind1
  bind126(["safety classification and labelling"])
  bind126 --> bind1
  bind127(["P4952"])
  bind127 --> bind1
  bind128(["mass spectrum"])
  bind128 --> bind1
  bind129(["haswbstatement:P4964|P6689"])
  bind129 --> bind1
  bind130(["NMR spectrum"])
  bind130 --> bind1
  bind131(["P9405"])
  bind131 --> bind1
  bind132(["pKa"])
  bind132 --> bind1
  bind133(["linksto:Property:P1117"])
  bind133 --> bind1
  bind134(["mass"])
  bind134 --> bind1
  bind135(["linksto:Property:P2067"])
  bind135 --> bind1
  bind136(["solubility"])
  bind136 --> bind1
  bind137(["linksto:Property:P2177"])
  bind137 --> bind1
  bind138(["melting point"])
  bind138 --> bind1
  bind139(["linksto:Property:P2101"])
  bind139 --> bind1
  bind140(["boiling point"])
  bind140 --> bind1
  bind141(["linksto:Property:P2102"])
  bind141 --> bind1
  bind142(["electric dipole moment"])
  bind142 --> bind1
  bind143(["linksto:Property:P2201"])
  bind143 --> bind1
  bind144(["ionization energy"])
  bind144 --> bind1
  bind145(["linksto:Property:P2260"])
  bind145 --> bind1
  bind2[/"concat(?property_query_term,' ',?constraint)"/]
  v4 --o bind2
  v2 --o bind2
  bind2 --as--o v5
  subgraph s1["http://wikiba.se/ontology#mwapi"]
    style s1 stroke-width:4px;
    c2 --"wikibase:endpoint"-->  c4
    c2 --"wikibase:api"-->  c6
    c2 --"wikibase:limit"-->  c8
    c2 --https://www.mediawiki.org/ontology#API/srsearch-->  v5
    c2 --https://www.mediawiki.org/ontology#API/srlimit-->  c11
    v6 --"wikibase:apiOutput"-->  c13
  end
  bind3[/"http://www.w3.org/2001/XMLSchema#integer(?count_)"/]
  v6 --o bind3
  bind3 --as--o v7
  bind4[/"concat('Total chemicals with ',?description_)"/]
  v3 --o bind4
  bind4 --as--o v7