WDscholia / scholia

Wikidata-based scholarly profiles
https://scholia.toolforge.org
Other
215 stars 78 forks source link

Statistics for chemical index aspect #2378

Closed Adafede closed 8 months ago

Adafede commented 8 months ago

Fixes #2377

Description

This PR modifies the query for the statistics displayed on the chemical index page. It uses Cirrus Search for efficiency reason and limits the results to chemicals by their P31 property. This way, some other items not corresponding to chemicals using similar properties will not be listed (minerals, proteins, etc.). Further, it allows to display statistics that were not displayed before for the exact same reason.

Caveats

Please list anything which has been left out of this PR or which should be considered before this PR is accepted Check any of the following which apply:

If you make changes to the Python code

Testing

Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. Please also list any relevant details for your test configuration.

None

Checklist

fnielsen commented 8 months ago

There is currently a conflict. Could you rebase to current master?

fnielsen commented 8 months ago

A perhaps more readable version:

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")
    ("PubChem ID" "P662")
    ("ChEBI ID" "P683")
    ("found in taxon" "P703")
    ("isomeric SMILES" "P2017")
    ("crystal structure" "haswbstatement:P3636|P11375")
    ("mass spectrum" "haswbstatement:P4964|P6689")
    ("NMR spectrum" "haswbstatement:P5219|P9405")
    # hacky way to get quantity properties.
    ("pKa" "linksto:Property:P1117")
    ("mass" "linksto:Property:P2067")
    ("melting point" "linksto:Property:P2101")
    ("boiling point" "linksto:Property:P2102")
  }
  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)
Adafede commented 8 months ago

Sorry, made a bit of a mess. Should be good now