java – sparql – replaces the triple with the union of the triples

Below is a simple sparql query from lubm.

PREFIX rdf: 
PREFIX ub: 
SELECT? X? Y1? Y2? Y3
WHERE
{? X rdf: type ub: Professor.}

And there is a Map <Chain, List> that contains some inferred subclass data from SCHEMA as

{
"":

The
""
""
""
....
]}

I want to replace this triple ? X rdf: ub type: teacher. in that sparql query with union of its subclasses like:

{{{{? For }
UNION
{? For }
}
UNION
{? For }
}
UNION
{? For }
}

but I have no idea how I can do this specific.

Could you please provide me with some code to do this in jena (java) …?

Thank you with gratitude 🙂