Fix infinite recursion on cyclic import structures. cherry-pick from 4

If owl:imports iri declarations do not match the imported ontology IRI
and there is a cycle in the imports closure, the parsing goes into an
infinite recursion. Cycle broken by detecting the cycles on the
owl:imports IRIs rather than waiting for the ontologies to appear in 
the manager index.