@prefix ex: <https://kg.earthmetabolome.org/metrin/api/.well-known/examples/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix spex:<https://purl.expasy.org/sparql-examples/ontology#> .

ex:001 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Among the SIRIUS structural annotations from Tabernaemontana coffeoides (Apocynaceae) seeds extract, which ones are reported in the Tabernaemontana genus?"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX sosa: <http://www.w3.org/ns/sosa/>
PREFIX emi: <https://w3id.org/emi#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>

SELECT DISTINCT ?ik2d ?genus
WHERE
    {
    ?material sosa:hasSample ?extract ;
        sosa:isSampleOf ?organe .
    ?organe emi:inTaxon ?wd_sp .
    ?wd_sp rdfs:label "tabernaemontana coffeoides" .
    ?extract sosa:isFeatureOfInterestOf ?lcms .
    ?lcms sosa:hasResult ?feature_list .
    ?feature_list emi:hasLCMSFeature ?feature .
    ?feature emi:hasAnnotation ?sirius_annotation .
    ?sirius_annotation a emi:StructuralAnnotation ;
        prov:wasGeneratedBy ?activity ;
        emi:hasChemicalStructure ?ik2d .
    ?activity prov:wasAssociatedWith <https://bio.informatik.uni-jena.de/software/sirius> .
    ?ik2d emi:hasSMILES ?smiles ;
        emi:isInChIKey2DOf ?ik .
    ?ik emi:isInChIKeyOf ?wd_id .
	{
        SELECT DISTINCT ?wd_id ?genus WHERE {
            ?material sosa:hasSample ?extract ;
                sosa:isSampleOf ?organe .
            ?organe emi:inTaxon ?wd_sp .
            ?wd_sp rdfs:label "tabernaemontana coffeoides" .
           # OPTIONAL {
                SERVICE <https://query.wikidata.org/sparql> {
                    ?wd_sp wdt:P225 ?species_name .
                    ?genus wdt:P31 wd:Q16521 ;
                        wdt:P105 wd:Q34740 ;
                        ^wdt:P171* ?wd_sp .
                    ?childtaxa wdt:P171* ?genus .
                    ?wd_id wdt:P703 ?childtaxa
                }
           # }
        } LIMIT 100
    }
}""" ;
    schema:target <https://kg.earthmetabolome.org/metrin/api/> ;
    spex:federatesWith <https://query.wikidata.org/sparql> .
