OWLAPI
and MiniME
in any source file you want to use Mini-ME in.
let ontologyUrl = Bundle.main.url(forResource: "ontology", withExtension: "owl")!
let manager = OWLManager.createOWLOntologyManager()
if let ontology = try? manager.loadOntologyFromDocument(at: ontologyUrl) {
let reasoner = MicroReasoner(ontology: ontology)
reasoner.kb.classify()
}
let ontologyUrl = Bundle.main.url(forResource: "ontology", withExtension: "owl")!
let manager = OWLManager.createOWLOntologyManager()
if let ontology = try? manager.loadOntologyFromDocument(at: ontologyUrl) {
let reasoner = MicroReasoner(ontology: ontology)
let consistent = reasoner.isConsistent()
print("The ontology is " + (consistent ? "consistent" : "not consistent"))
}
let ontologyUrl = Bundle.main.url(forResource: "ontology", withExtension: "owl")!
let manager = OWLManager.createOWLOntologyManager()
if let ontology = try? manager.loadOntologyFromDocument(at: ontologyUrl) {
let reasoner = MicroReasoner(ontology: ontology)
let satisfiable = reasoner.isSatisfiable(classWithIri: OWLIRI(string: "http://a.com/onto.owl#class"))
print("The class is " + (satisfiable ? "satisfiable" : "not satisfiable"))
}
let resourceOntologyUrl = Bundle.main.url(forResource: "resource", withExtension: "owl")!
let requestOntologyUrl = Bundle.main.url(forResource: "request", withExtension: "owl")!
let manager = OWLManager.createOWLOntologyManager()
guard let resourceOntology = try? manager.loadOntologyFromDocument(at: resourceOntologyUrl),
let requestOntology = try? manager.loadOntologyFromDocument(at: requestOntologyUrl) else {
return
}
let reasoner = MicroReasoner(ontology: resourceOntology)
reasoner.loadRequest(from: requestOntology)
for request in reasoner.requestIndividuals.keys {
for resource in reasoner.resourceIndividuals.keys {
let compatible = reasoner.compatibility(betweenResource: resource, andRequest: request)!
if compatible {
let abduction = reasoner.abduction(withResource: resource, forRequest: request)!
print("Abduction between resource \"\(resource)\" and request \"\(request)\":")
print("Hypotesis: \(abduction.hypotesis)")
print("Penalty: \(abduction.penalty)\n")
} else {
let contraction = reasoner.contraction(withResource: resource, forRequest: request)!
print("Contraction between resource \"\(resource)\" and request \"\(request)\":")
print("Keep: \(contraction.keep)")
print("Give up: \(contraction.giveUp)")
print("Penalty: \(contraction.penalty)\n")
}
}
}
let resourceOntologyUrl = Bundle.main.url(forResource: "resource", withExtension: "owl")!
let requestOntologyUrl = Bundle.main.url(forResource: "request", withExtension: "owl")!
let manager = OWLManager.createOWLOntologyManager()
guard let resourceOntology = try? manager.loadOntologyFromDocument(at: resourceOntologyUrl),
let requestOntology = try? manager.loadOntologyFromDocument(at: requestOntologyUrl) else {
return
}
let reasoner = MicroReasoner(ontology: resourceOntology)
reasoner.loadRequest(from: requestOntology)
for request in reasoner.requestIndividuals.keys {
if let composition = reasoner.composition(forRequest: request) {
print("Composition for request: \"\(request)\"")
print("Cover resources: \(composition.coverResources.map({ $0.iri.string }).joined(separator: ", "))")
print("Uncovered part: \(composition.uncoveredRequest)\n")
}
}
Correctness of the returned results and performance (in terms of turnaround time and peak memory) can be evaluated by launching Mini-ME Swift from the command line, via either a test framework or by directly invoking a command line wrapper, as explained in the upcoming sections.
Instructions on how to install, configure and use the test framework are available on its public repository. Datasets and reasoners used for performance evaluation should be unpacked in the root directory of the test framework.
The MiniME-cli tool, available in the reasoners archive, is internally used by the test framework in order to accurately compute turnaround times for some of the supported reasoning tasks. For standard tasks, it also provides the output of the inference service. It can be run manually as follows:
./MiniME-cli classification -i <input ontology> [-o <output file>]
: classifies the specified OWL ontology, printing the inferred taxonomy in the output file../MiniME-cli consistency -i <input ontology>
: checks the consistency of the specified OWL ontology../MiniME-cli abduction-contraction -i <resource OWL file> -r <request OWL file>
: evaluates non-standard inference services on the specified resource OWL file (containing ontology and a set of resource individuals) and request OWL file (containing the request individual expressed with respect to the same ontology).