PREFIX owl: PREFIX rdf: PREFIX skos: SELECT DISTINCT ?s ?label WHERE { SERVICE { SELECT DISTINCT ?s ?label ?plabel ?alabel ?hlabel (GROUP_CONCAT(DISTINCT STR(?type)) as ?types) WHERE { GRAPH { ?s rdf:type { ?s rdf:type ?type . ?s ?prop ?match . FILTER ( strstarts(lcase(str(?match)), "test") && !(?match != ?label && strstarts(lcase(str(?label)), "test")) ) OPTIONAL { ?s skos:prefLabel ?label . FILTER (langMatches(lang(?label), "en")) } OPTIONAL { # in case previous OPTIONAL block gives no labels ?s ?prop ?match . ?s skos:prefLabel ?label . FILTER (langMatches(lang(?label), lang(?match))) } } FILTER NOT EXISTS { ?s owl:deprecated true } } BIND(IF(?prop = skos:prefLabel && ?match != ?label, ?match, "") as ?plabel) BIND(IF(?prop = skos:altLabel, ?match, "") as ?alabel) BIND(IF(?prop = skos:hiddenLabel, ?match, "") as ?hlabel) VALUES (?prop) { (skos:prefLabel) (skos:altLabel) (skos:hiddenLabel) } } GROUP BY ?match ?s ?label ?plabel ?alabel ?hlabel ?prop ORDER BY lcase(str(?match)) lang(?match) LIMIT 10 } }