
it.unibz.inf.ontop.cli.OntopBootstrap Maven / Gradle / Ivy
package it.unibz.inf.ontop.cli;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;
import com.github.rvesse.airline.annotations.OptionType;
import it.unibz.inf.ontop.io.ModelIOManager;
import it.unibz.inf.ontop.model.OBDAModel;
import it.unibz.inf.ontop.owlapi.bootstrapping.DirectMappingBootstrapper;
import org.semanticweb.owlapi.io.FileDocumentTarget;
import org.semanticweb.owlapi.model.OWLOntology;
import java.io.File;
import java.util.Objects;
@Command(name = "bootstrap",
description = "Bootstrap ontology and mapping from the database")
public class OntopBootstrap extends OntopMappingOntologyRelatedCommand {
@Option(type = OptionType.COMMAND, name = {"-b", "--base-iri"}, title = "base IRI",
description = "base uri of the generated mapping")
protected String baseIRI;
@Override
public void run() {
try {
if (baseIRI.contains("#")) {
System.err.println("Base IRI cannot contain the character '#'!");
throw new IllegalArgumentException("Base IRI cannot contain the character '#'!");
}
Objects.requireNonNull(owlFile, "ontology file must not be null");
File ontologyFile = new File(owlFile);
File obdaFile = new File(mappingFile);
DirectMappingBootstrapper dm = new DirectMappingBootstrapper(
baseIRI, jdbcURL, jdbcUserName, jdbcPassword, jdbcDriverClass);
OBDAModel model = dm.getModel();
OWLOntology onto = dm.getOntology();
ModelIOManager mng = new ModelIOManager(model);
mng.save(obdaFile);
onto.getOWLOntologyManager().saveOntology(onto, new FileDocumentTarget(ontologyFile));
} catch (Exception e) {
System.err.println("Error occurred during bootstrapping: "
+ e.getMessage());
System.err.println("Debugging information for developers: ");
e.printStackTrace();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy