@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:007 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Show chemical structures in Melochia umbellata extracts with structural annotations where the cosmic score is greater than 0.5 and the zodiac score is less than 0.8. For ISDB annotations, consider taxon scores greater than or equal to 6"@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 wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX emi: <https://w3id.org/emi#>
PREFIX sosa: <http://www.w3.org/ns/sosa/>

SELECT DISTINCT ?ik ?wd_id ?taxon ?taxon_name
WHERE { 
    {SELECT  ?ik ?wd_id
        WHERE {
            ?sample a emi:ExtractSample ;
                sosa:isSampleOf* ?organe ;
                sosa:isFeatureOfInterestOf ?lcms .
            ?organe emi:inTaxon ?taxon .
            ?taxon rdfs:label "melochia umbellata" .
            ?lcms a emi:LCMSAnalysisPos ;
                sosa:hasResult ?feature_list .
            ?feature_list emi:hasLCMSFeature ?feature .
            {
                ?feature emi:hasAnnotation ?annotation .
                ?annotation a emi:StructuralAnnotation ;
                    prov:wasGeneratedBy ?activity .
                ?activity prov:wasAssociatedWith <https://bio.informatik.uni-jena.de/software/sirius> .
                ?annotation emi:hasCosmicScore ?cosmic ;
                    emi:hasZodiacScore ?zodiac .
                FILTER((?cosmic > 0.5) && (?zodiac > 0.8))
            } UNION {
                ?feature emi:hasAnnotation ?annotation .
                ?annotation emi:hasTaxoScore ?taxo .
                FILTER(?taxo >= 6)
            }
            ?annotation emi:hasChemicalStructure ?ik2d .
            ?ik2d emi:hasSMILES ?smiles ;
                emi:isInChIKey2DOf ?ik .
            ?ik emi:isInChIKeyOf ?wd_id .
        } LIMIT 50
    }
  SERVICE <https://query.wikidata.org/sparql> {
        ?wd_id wdt:P31 wd:Q113145171 ;
            wdt:P703 ?taxon .
        ?taxon wdt:P225 ?taxon_name .
    }
}""" ;
    schema:target <https://kg.earthmetabolome.org/metrin/api/> ;
    spex:federatesWith <https://query.wikidata.org/sparql> .

