It can be solved using sparql. The same problem is answered in Why my query doesn't work using RDFlib which is same problem.
The code could be like this:
PREFIX ns: <http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT DISTINCT ?varClass ?varSubClass ?varSubClassComment ?varProperty ?varPropComment
FROM <http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf>
WHERE {
VALUES ?propertyType { owl:ObjectProperty owl:DatatypeProperty }
?varClass rdf:type owl:Class .
?varProperty rdf:type ?propertyType ;
rdfs:domain ?varClass .
OPTIONAL{ ?varProperty rdfs:comment ?varPropComment }
OPTIONAL{ ?varSubClass rdfs:subClassOf ?varClass ;
rdfs:comment ?varSubClassComment }
}
Anyway, since I've posted this answer, I studied some RDFlib codes and sparql. The latter might be applicable for the most cases.