本文整理匯總了Java中org.semanticweb.owlapi.model.OWLOntologyManager.addAxioms方法的典型用法代碼示例。如果您正苦於以下問題:Java OWLOntologyManager.addAxioms方法的具體用法?Java OWLOntologyManager.addAxioms怎麽用?Java OWLOntologyManager.addAxioms使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.semanticweb.owlapi.model.OWLOntologyManager
的用法示例。
在下文中一共展示了OWLOntologyManager.addAxioms方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addBioEntity
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private void addBioEntity(OWLClass pr, OWLOntology lego, Bioentity bioentity) {
Set<OWLDeclarationAxiom> declarationAxioms = lego.getDeclarationAxioms(pr);
if (declarationAxioms == null || declarationAxioms.isEmpty()) {
// add class declaration and add label
OWLOntologyManager m = lego.getOWLOntologyManager();
OWLDataFactory f = m.getOWLDataFactory();
Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
axioms.add(f.getOWLDeclarationAxiom(pr));
String label = bioentity.getSymbol()+" - "+bioentity.getFullName();
axioms.add(f.getOWLAnnotationAssertionAxiom(f.getRDFSLabel(), pr.getIRI(), f.getOWLLiteral(label)));
m.addAxioms(lego, axioms);
}
}
示例2: minimizedTranslate
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Translate the given {@link GafDocument} into an OWL representation of the LEGO model.
* Additionally minimize the lego model and imports into one ontology module.
*
* @param gaf
* @return minimized lego ontology
*/
public OWLOntology minimizedTranslate(GafDocument gaf) {
OWLOntology all = translate(gaf);
final OWLOntologyManager m = all.getOWLOntologyManager();
SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, all, ModuleType.BOT);
Set<OWLEntity> sig = new HashSet<OWLEntity>(all.getIndividualsInSignature());
Set<OWLAxiom> moduleAxioms = sme.extract(sig);
try {
OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
m.addAxioms(module, moduleAxioms);
return module;
} catch (OWLException e) {
throw new RuntimeException("Could not create minimized lego model.", e);
}
}
示例3: isEdgeEntailed
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public boolean isEdgeEntailed(OWLEdge e, OWLOntology currentOntology, OWLReasoner reasoner) {
OWLOntologyManager m = getManager();
Set<OWLSubClassOfAxiom> scas = currentOntology.getSubClassAxiomsForSubClass(e.c);
Set<OWLSubClassOfAxiom> rmAxioms = new HashSet<OWLSubClassOfAxiom>();
for (OWLSubClassOfAxiom sca : scas) {
if (sca.getSuperClass().equals(e.p)) {
LOG.info("REMOVING: "+sca);
rmAxioms.add(sca);
}
}
boolean isEdgeAsserted = rmAxioms.size() > 0;
if (isEdgeAsserted) {
m.removeAxioms(currentOntology, rmAxioms);
reasoner.flush();
}
boolean isEntailed;
isEntailed = reasoner.getSuperClasses(e.c, false).containsEntity(e.p);
if (isEdgeAsserted) {
m.addAxioms(currentOntology, rmAxioms);
reasoner.flush();
}
return isEntailed;
}
示例4: mergeImportClosure
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public void mergeImportClosure(boolean isRemovedImportsDeclarations) throws OWLOntologyCreationException {
OWLOntologyManager manager = getManager();
Set<OWLOntology> imports = sourceOntology.getImportsClosure();
for (OWLOntology o : imports) {
if (o.equals(sourceOntology))
continue;
String comment = "Includes "+summarizeOntology(o);
LOG.info(comment);
addCommentToOntology(sourceOntology, comment);
manager.addAxioms(sourceOntology, o.getAxioms());
}
Set<OWLImportsDeclaration> oids = sourceOntology.getImportsDeclarations();
for (OWLImportsDeclaration oid : oids) {
RemoveImport ri = new RemoveImport(sourceOntology, oid);
getManager().applyChange(ri);
}
}
示例5: mergeSpecificImport
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Merge a specific ontology from the import closure into the main ontology.
* Removes the import statement.
*
* @param ontologyIRI id of the ontology to merge
* @throws OWLOntologyCreationException
*/
public void mergeSpecificImport(IRI ontologyIRI) throws OWLOntologyCreationException {
OWLOntologyManager manager = getManager();
Set<OWLOntology> imports = sourceOntology.getImportsClosure();
for (OWLOntology o : imports) {
if (o.equals(sourceOntology))
continue;
Optional<IRI> currentIRI = o.getOntologyID().getOntologyIRI();
if (currentIRI.isPresent() && currentIRI.get().equals(ontologyIRI)) {
String comment = "Includes "+summarizeOntology(o);
LOG.info(comment);
addCommentToOntology(sourceOntology, comment);
manager.addAxioms(sourceOntology, o.getAxioms());
}
}
Set<OWLImportsDeclaration> oids = sourceOntology.getImportsDeclarations();
for (OWLImportsDeclaration oid : oids) {
if (ontologyIRI.equals(oid.getIRI())) {
RemoveImport ri = new RemoveImport(sourceOntology, oid);
getManager().applyChange(ri);
}
}
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: createOntology
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
static OWLOntology createOntology(Set<? extends OWLAxiom> background, Set<? extends OWLAxiom> unifier)
throws OWLOntologyCreationException {
OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = ontologyManager.createOntology();
ontologyManager.addAxioms(ontology, background);
ontologyManager.addAxioms(ontology, unifier);
return ontology;
}
示例9: saveToOntologyFile
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Saves a set of axioms to an OWL ontology file.
*
* @param axioms
* a set of OWLAxioms
* @param file
* the output destination
*/
public static void saveToOntologyFile(Set<OWLAxiom> axioms, File file) {
try {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology();
manager.addAxioms(ontology, axioms);
saveToOntologyFile(ontology, file);
} catch (OWLOntologyCreationException e) {
throw new RuntimeException(e);
}
}
示例10: translate
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Translate the given annotations ({@link GeneAnnotation}) into an OWL representation of the LEGO model.
*
* @param annotations
* @param lego
* @throws OWLException
* @throws UnknownIdentifierException
*/
public void translate(Collection<GeneAnnotation> annotations, final OWLOntology lego) throws OWLException, UnknownIdentifierException {
final OWLOntologyManager m = graph.getManager();
Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
for(GeneAnnotation annotation : annotations) {
translate(annotation, axioms);
}
m.addAxioms(lego, axioms);
}
示例11: reasonLeavingOneOut
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public void reasonLeavingOneOut(OWLOntology leaveOutOntology) throws OWLOntologyCreationException {
OWLOntologyManager m = getManager();
OWLOntology ont2 = m.createOntology();
LOG.info("LEAVE ONE OUT: "+leaveOutOntology);
for (OWLOntology io : ontology.getImportsClosure()) {
if (io.equals(leaveOutOntology)) {
LOG.info("SKIPPING:"+io);
continue;
}
m.addAxioms(ont2, io.getAxioms());
}
OWLReasoner reasoner = rf.createReasoner(ont2);
for (OWLEdge e : edges) {
if (!e.isJustified) {
// there is no point checking unjustified edges;
// these are edges that when removed cannot be re-inferred using the entire ontology set.
// as reasoning is monotonic, removing imports cannot bring it back.
continue;
}
//LOG.info("Testing "+e);
if (!isEdgeEntailed(e, ont2, reasoner)) {
IRI req = leaveOutOntology.getOntologyID().getOntologyIRI().orNull();
LOG.info(e + " requires "+req);
e.requires.add(req);
}
}
reasoner.dispose();
}
示例12: markAsInferredAxiom
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Mark the given axioms as inferred.<br>
* <b>Side effect</b>: Removes the axiom in the given ontology and creates a
* new axiom with the changed annotations. Returns the new changed axiom.
*
* @param axioms
* @param ontology
* @return changed axiom
*/
public static Set<OWLAxiom> markAsInferredAxiom(Set<OWLAxiom> axioms, OWLOntology ontology) {
final OWLOntologyManager manager = ontology.getOWLOntologyManager();
final OWLDataFactory factory = manager.getOWLDataFactory();
// update axioms
Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
for (OWLAxiom axiom : axioms) {
newAxioms.add(updateInferredAxiom(axiom, factory, true));
}
// change ontology
manager.removeAxioms(ontology, axioms);
manager.addAxioms(ontology, newAxioms);
return newAxioms;
}
示例13: getOboGraphJSONString
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Generate a OboGraphs JSON ontology blob for the local axioms for an object.
*
* This will include
*
* - all logical axioms about the object
* - all annotations for all entities in the signature
*
* In other words, direct parents plus labels and other metadata on all entities
*
* @param obj
* @return JSON string
* @throws JsonProcessingException
* @throws OWLOntologyCreationException
*/
public String getOboGraphJSONString(OWLObject obj) throws JsonProcessingException, OWLOntologyCreationException {
FromOwl fromOwl = new FromOwl();
OWLOntologyManager m = sourceOntology.getOWLOntologyManager();
if (obj instanceof OWLNamedObject) {
OWLNamedObject nobj = (OWLNamedObject)obj;
OWLOntology ont = m.createOntology(nobj.getIRI());
Set<OWLAxiom> axioms = new HashSet<>();
if (nobj instanceof OWLClass) {
axioms.addAll(sourceOntology.getAxioms((OWLClass)nobj, Imports.INCLUDED));
}
else if (nobj instanceof OWLObjectProperty) {
axioms.addAll(sourceOntology.getAxioms((OWLObjectProperty)nobj, Imports.INCLUDED));
}
m.addAxioms(ont, axioms);
axioms = new HashSet<>();
for (OWLEntity e : ont.getSignature()) {
axioms.addAll(sourceOntology.getAnnotationAssertionAxioms(e.getIRI()));
}
axioms.addAll(sourceOntology.getAnnotationAssertionAxioms(nobj.getIRI()));
m.addAxioms(ont, axioms);
GraphDocument gd = fromOwl.generateGraphDocument(ont);
return OgJsonGenerator.render(gd);
}
else {
return "{}";
}
}
示例14: assertAboxInferences
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
@CLIMethod("--assert-abox-inferences")
public void assertAboxInferences(Opts opts) throws Exception {
opts.info("", "Finds all inferred OPEs and ClassAssertions and asserts them. Does not handle DPEs. Resulting ontology can be used for sparql queries");
boolean isNew = false;
while (opts.hasOpts()) {
if (opts.nextEq("-n|--new")) {
isNew = true;
}
else
break;
}
Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
OWLOntology ont = g.getSourceOntology();
// TODO : move this to a utility class
OWLOntologyManager mgr = ont.getOWLOntologyManager();
OWLDataFactory df = mgr.getOWLDataFactory();
LOG.info("Initial axioms:"+ont.getAxioms(true).size());
for (OWLNamedIndividual ind : ont.getIndividualsInSignature(Imports.INCLUDED)) {
//LOG.info("Checking: "+ind);
for (OWLObjectProperty p : ont.getObjectPropertiesInSignature(Imports.INCLUDED)) {
NodeSet<OWLNamedIndividual> vs = reasoner.getObjectPropertyValues(ind, p);
for (OWLNamedIndividual v : vs.getFlattened()) {
//LOG.info("NEW: "+ind+" -> "+p+" -> "+v);
newAxioms.add(df.getOWLObjectPropertyAssertionAxiom(p, ind, v));
}
}
for (OWLClass c : reasoner.getTypes(ind, false).getFlattened()) {
newAxioms.add(df.getOWLClassAssertionAxiom(c, ind));
//LOG.info("NEW: "+ind+" :: "+c);
}
}
OWLPrettyPrinter owlpp = new OWLPrettyPrinter(g);
for (OWLAxiom a : newAxioms) {
LOG.info("NEW: "+owlpp.render(a));
}
LOG.info("# OF NEW AXIOMS: "+newAxioms.size());
if (isNew) {
g.setSourceOntology(mgr.createOntology());
}
mgr.addAxioms(g.getSourceOntology(), newAxioms);
}
示例15: 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;
}