public static List<Resource> findRootsByType(Model model, Resource atype) { String s = String.join("\n", "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>", "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>", "SELECT DISTINCT ?root { { ?root rdf:type ?ATYPE } UNION { ?root rdf:type ?t . ?t rdfs:subClassOf ?ATYPE } }") ; Query q = QueryFactory.create(s) ; QuerySolutionMap qsm = new QuerySolutionMap() ; qsm.add("ATYPE", atype) ; try(QueryExecution qExec = QueryExecutionFactory.create(q, model, qsm)) { return ListUtils.toList( QueryExecUtils.getAll(qExec, "root").stream().map(r->(Resource)r)); } }