private static OWLOntology convert(RDFModel model, OWLOntologyManager manager)
throws OWLOntologyCreationException, SAXException {
OWLOntology ontology = manager.createOntology( TMP_URI );
OWLRDFConsumer consumer = new OWLRDFConsumer( manager, ontology,
new AnonymousNodeChecker() {
public boolean isAnonymousNode(URI uri) {
return isAnonymousNode( uri.toString() );
}
public boolean isAnonymousNode(String uri) {
return uri.startsWith( ANON_URI );
}
} );
consumer.startModel( "" );
for( Statement stmt : model.getStatements() ) {
String subj = toString( stmt.getSubject() );
String pred = toString( stmt.getPredicate() );
RDFNode vObj = stmt.getObject();
String obj = toString( vObj );
if( vObj instanceof Literal ) {
Literal literal = (Literal) vObj;
String datatypeURI = literal.getDatatypeURI();
String lang = literal.getLanguage();
if( lang != null && lang.length() == 0 )
lang = null;
consumer.statementWithLiteralValue( subj, pred, obj, lang, datatypeURI );
}
else {
consumer.statementWithResourceValue( subj, pred, obj );
}
}
consumer.endModel();
return ontology;
}