本文整理匯總了Java中org.semanticweb.owlapi.model.OWLOntologyManager.saveOntology方法的典型用法代碼示例。如果您正苦於以下問題:Java OWLOntologyManager.saveOntology方法的具體用法?Java OWLOntologyManager.saveOntology怎麽用?Java OWLOntologyManager.saveOntology使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.semanticweb.owlapi.model.OWLOntologyManager
的用法示例。
在下文中一共展示了OWLOntologyManager.saveOntology方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createModule
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private void createModule(String ontologyId, String moduleName, Set<OWLEntity> signature)
throws OWLOntologyCreationException, IOException, OWLOntologyStorageException
{
// create a new manager, avoid unnecessary change events
final OWLOntologyManager m = OWLManager.createOWLOntologyManager();
// extract module
SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, mooncat.getOntology(), ModuleType.BOT);
Set<OWLAxiom> moduleAxioms = sme.extract(signature);
OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
m.addAxioms(module, moduleAxioms);
// save module
OutputStream moduleOutputStream = null;
try {
moduleOutputStream = getOutputSteam(getModuleFileName(ontologyId, moduleName));
m.saveOntology(module, moduleOutputStream);
}
finally {
IOUtils.closeQuietly(moduleOutputStream);
}
}
示例2: createModule
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private static void createModule(String moduleName, Set<OWLEntity> signature, OWLOntology ont)
throws OWLOntologyCreationException, IOException, OWLOntologyStorageException
{
// create a new manager avoid unnecessary change events
final OWLOntologyManager m = OWLManager.createOWLOntologyManager();
// extract module
SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, ont, ModuleType.BOT);
Set<OWLAxiom> moduleAxioms = sme.extract(signature);
OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
m.addAxioms(module, moduleAxioms);
// save module
OutputStream moduleOutputStream = null;
try {
moduleOutputStream = new FileOutputStream(getModuleFile(moduleName));
m.saveOntology(module, moduleOutputStream);
}
finally {
IOUtils.closeQuietly(moduleOutputStream);
}
}
示例3: exportModel
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Export the ABox, will try to set the ontologyID to the given modelId (to
* ensure import assumptions are met)
*
* @param model
* @param ontologyFormat
* @return modelContent
* @throws OWLOntologyStorageException
*/
public String exportModel(ModelContainer model, OWLDocumentFormat ontologyFormat) throws OWLOntologyStorageException {
final OWLOntology aBox = model.getAboxOntology();
final OWLOntologyManager manager = aBox.getOWLOntologyManager();
// make sure the exported ontology has an ontologyId and that it maps to the modelId
final IRI expectedABoxIRI = model.getModelId();
Optional<IRI> currentABoxIRI = aBox.getOntologyID().getOntologyIRI();
if (currentABoxIRI.isPresent() == false) {
manager.applyChange(new SetOntologyID(aBox, expectedABoxIRI));
}
else {
if (expectedABoxIRI.equals(currentABoxIRI) == false) {
OWLOntologyID ontologyID = new OWLOntologyID(Optional.of(expectedABoxIRI), Optional.of(expectedABoxIRI));
manager.applyChange(new SetOntologyID(aBox, ontologyID));
}
}
// write the model into a buffer
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
if (ontologyFormat != null) {
manager.saveOntology(aBox, ontologyFormat, outputStream);
}
else {
manager.saveOntology(aBox, outputStream);
}
// extract the string from the buffer
String modelString = outputStream.toString();
return modelString;
}
示例4: saveExtractedModule
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public void saveExtractedModule(OWLOntologyManager manager, OWLOntology module, String physicalModuleURI) {
//OWLOntologyManager ontologyModuleManager = OWLManager.createOWLOntologyManager();
try {
manager.saveOntology(module, new RDFXMLOntologyFormat(), IRI.create(physicalModuleURI));
}
catch (Exception e) {
System.err.println("Error saving module\n" + e.getLocalizedMessage());
e.printStackTrace();
}
}
示例5: setUpBeforeClass
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
@BeforeClass
public static void setUpBeforeClass() throws Exception {
final URI ontologyUri = URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/ConnectorFactoryTest");
final File targetFile = Files.createTempFile("connectortest", ".owl").toFile();
targetFile.deleteOnExit();
final OWLOntologyManager om = OWLManager.createOWLOntologyManager();
final OWLOntology o = om.createOntology(IRI.create(ontologyUri));
om.saveOntology(o, IRI.create(targetFile));
final URI physicalUri = targetFile.toURI();
storageProperties = OntologyStorageProperties.ontologyUri(ontologyUri).physicalUri(physicalUri).driver(
OwlapiDataSource.class.getCanonicalName()).build();
}
示例6: main
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public static void main(String[] args) throws OWLOntologyStorageException,
OWLOntologyCreationException {
OWLOntologyManager inputOntologyManager = OWLManager.createOWLOntologyManager();
OWLOntologyManager outputOntologyManager = OWLManager.createOWLOntologyManager();
// Load your ontology.
OWLOntology ont = inputOntologyManager.loadOntologyFromOntologyDocument(new File("path-to-ontology"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Classify the ontology.
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
// To generate an inferred ontology we use implementations of
// inferred axiom generators
List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
gens.add(new InferredSubClassAxiomGenerator());
gens.add(new InferredEquivalentClassAxiomGenerator());
// Put the inferred axioms into a fresh empty ontology.
OWLOntology infOnt = outputOntologyManager.createOntology();
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner,
gens);
iog.fillOntology(outputOntologyManager.getOWLDataFactory(), infOnt);
// Save the inferred ontology.
outputOntologyManager.saveOntology(infOnt,
new FunctionalSyntaxDocumentFormat(),
IRI.create((new File("path-to-output").toURI())));
// Terminate the worker threads used by the reasoner.
reasoner.dispose();
}
示例7: gaf2OwlSimple
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Created to mimic the translation to OWL for GAF checks
*
* @param opts
* @throws Exception
*/
@CLIMethod("--gaf2owl-simple")
public void gaf2OwlSimple(Opts opts) throws Exception {
opts.info("-o FILE", "translates previously loaded GAF document into OWL, requires a loaded ontology to lookup ids");
String out = null;
while (opts.hasOpts()) {
if (opts.nextEq("-o")) {
out = opts.nextOpt();
}
else
break;
}
if (g == null) {
LOG.error("An ontology is required.");
exit(-1);
}
else if (gafdoc == null) {
LOG.error("A GAF document is required.");
exit(-1);
}
else if (out == null) {
LOG.error("An output file is required.");
exit(-1);
}
LOG.info("Creating OWL represenation of annotations.");
GAFOWLBridge bridge = new GAFOWLBridge(g);
bridge.setGenerateIndividuals(false);
bridge.setBasicAboxMapping(false);
bridge.setBioentityMapping(BioentityMapping.CLASS_EXPRESSION);
bridge.setSkipNotAnnotations(true);
OWLOntology translated = bridge.translate(gafdoc);
File outputFile = new File(out);
OWLOntologyManager manager = translated.getOWLOntologyManager();
OWLDocumentFormat ontologyFormat= new FunctionalSyntaxDocumentFormat();
manager.saveOntology(translated, ontologyFormat, IRI.create(outputFile));
}
示例8: write
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private void write(OWLOntologyManager manager, OWLOntology ont, OWLDocumentFormat format, OutputStream out) throws OWLOntologyStorageException {
try {
manager.saveOntology(ont, format, out);
} finally {
try {
out.close();
} catch (IOException e) {
logWarn("Could not close stream.", e);
}
}
}
示例9: saveOntologyCopy
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private void saveOntologyCopy(File file) throws OWLOntologyStorageException {
IRI newOntologyIRI = IRI.create(file.toURI());
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
manager.saveOntology(ontology, new RDFXMLOntologyFormat(), newOntologyIRI);
}
示例10: saveOntology
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public static synchronized void saveOntology(OWLOntologyManager moduleManager, OWLOntology ontology, String IRIstr) throws Exception{
moduleManager.saveOntology(
ontology, new RDFXMLOntologyFormat(), IRI.create(IRIstr));
}
示例11: preCheckOntology
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
protected int preCheckOntology(String inConsistentMsg, String unsatisfiableMsg, String unsatisfiableModule) throws OWLException, IOException {
// pre-check: only try to load ontology iff:
// * ontology is consistent
// * no unsatisfiable classes
OWLReasoner currentReasoner = reasoner;
boolean disposeReasoner = false;
try {
if (currentReasoner == null) {
disposeReasoner = true;
currentReasoner = new ElkReasonerFactory().createReasoner(g.getSourceOntology());
}
boolean consistent = currentReasoner.isConsistent();
if (consistent == false) {
LOG.error(inConsistentMsg);
return -1;
}
Set<OWLClass> unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom();
if (unsatisfiable.isEmpty() == false) {
LOG.error(unsatisfiableMsg);
OWLPrettyPrinter prettyPrinter = getPrettyPrinter();
for (OWLClass owlClass : unsatisfiable) {
LOG.error("Unsatisfiable: "+prettyPrinter.render(owlClass));
}
LOG.info("Creating module for unsatisfiable classes in file: "+unsatisfiableModule);
ModuleType mtype = ModuleType.BOT;
OWLOntologyManager m = g.getManager();
SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, g.getSourceOntology(), mtype );
Set<OWLEntity> seeds = new HashSet<OWLEntity>(unsatisfiable);
Set<OWLAxiom> axioms = sme.extract(seeds);
OWLOntology module = m.createOntology();
m.addAxioms(module, axioms);
File moduleFile = new File(unsatisfiableModule).getCanonicalFile();
m.saveOntology(module, IRI.create(moduleFile));
return -1;
}
}
finally {
if (disposeReasoner && currentReasoner != null) {
currentReasoner.dispose();
}
}
return 0;
}
示例12: testRemove
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
@Test
public void testRemove() throws Exception {
ParserWrapper pw = new ParserWrapper();
OWLGraphWrapper g = pw.parseToOWLGraph(getResourceIRIString("mooncat/remove-directives-test1.obo"));
System.out.println(g.getSourceOntology().getAxioms(AxiomType.EQUIVALENT_CLASSES));
OWLOntology secondary = pw.parse(getResourceIRIString("mooncat/remove-directives-test2.obo"));
System.out.println(secondary.getAxioms(AxiomType.EQUIVALENT_CLASSES));
g.addSupportOntology(secondary);
Mooncat mooncat = new Mooncat(g);
//mooncat.mergeOntologies();
g.mergeOntology(secondary);
OWLOntology merged = g.getSourceOntology();
System.out.println(merged.getAxioms(AxiomType.EQUIVALENT_CLASSES));
Owl2Obo owl2Obo = new Owl2Obo();
OBODoc mergedObo = owl2Obo.convert(merged);
if (USE_SYSTEM_OUT) {
System.out.println("------------------------");
OWLOntologyManager manager = merged.getOWLOntologyManager();
OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget();
manager.saveOntology(merged, new RDFXMLDocumentFormat(), documentTarget);
System.out.println("------------------------");
String oboString = renderOBOtoString(mergedObo);
System.out.println(oboString);
System.out.println("------------------------");
}
Frame headerFrame = mergedObo.getHeaderFrame();
String owlAxiomString = headerFrame.getTagValue(OboFormatTag.TAG_OWL_AXIOMS, String.class);
assertNotNull(owlAxiomString);
Frame frame = mergedObo.getTermFrame("X:1");
Collection<Clause> clauses = frame.getClauses(OboFormatTag.TAG_INTERSECTION_OF);
assertEquals(2, clauses.size());
}