parseOntologyHeader(boolean toEOF) {
String tok = consumeToken();
if (!ONTOLOGY.matches(tok)) {
throw new ExceptionBuilder().withKeyword(ONTOLOGY).build();
}
IRI ontologyIRI = null;
IRI versionIRI = null;
if (peekToken().startsWith("<")) {
ontologyIRI = parseIRI();
if (peekToken().startsWith("<")) {
versionIRI = parseIRI();
}
}
Set<OWLAnnotation> annotations = new HashSet<>();
Set<OWLImportsDeclaration> imports = new HashSet<>();
while (true) {
String section = peekToken();
if (IMPORT.matches(section)) {
consumeToken();
tok = peekToken();
Optional<IRI> importedIRI = Optional.absent();
if (tok.startsWith("<")) {
importedIRI = Optional.of(parseIRI());
} else if (isOntologyName(tok)) {
consumeToken();
OWLOntology ont = getOntology(tok);
if (ont != null) {
importedIRI = ont.getOntologyID().getOntologyIRI();
}
} else {
consumeToken();
throw new ExceptionBuilder().withOnto()
.withKeyword("<$ONTOLOGYYURI$>").build();
}
if (!importedIRI.isPresent()) {
throw new ExceptionBuilder().withOnto()
.withKeyword("Imported IRI is null").build();
}
IRI importedOntologyIRI = importedIRI.get();
assert importedOntologyIRI != null;
imports.add(dataFactory
.getOWLImportsDeclaration(importedOntologyIRI));
} else if (ANNOTATIONS.matches(section)) {
consumeToken();