本文整理汇总了Java中org.semanticweb.owlapi.reasoner.OWLReasoner.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java OWLReasoner.dispose方法的具体用法?Java OWLReasoner.dispose怎么用?Java OWLReasoner.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.semanticweb.owlapi.reasoner.OWLReasoner
的用法示例。
在下文中一共展示了OWLReasoner.dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reasonLeavingOneOut
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的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();
}
示例2: testBasicSim
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void testBasicSim() throws Exception {
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOBO(getResource("sim/mp-subset-1.obo").getAbsolutePath());
g = new OWLGraphWrapper(sourceOntol);
parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);
setOutput("target/basic-owlsim-test.out");
owlpp = new OWLPrettyPrinter(g);
// assume buffering
OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
try {
this.createOwlSim();
owlsim.createElementAttributeMapFromOntology();
//sos.saveOntology("/tmp/z.owl");
reasoner.flush();
for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) {
showSim(i,j);
}
}
}
finally {
reasoner.dispose();
}
}
示例3: testGetEntropy
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void testGetEntropy() throws OWLOntologyCreationException, IOException, OBOFormatParserException, UnknownOWLClassException {
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOBO(getResourceIRIString("sim/mp-subset-1.obo"));
g = new OWLGraphWrapper(sourceOntol);
parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);
owlpp = new OWLPrettyPrinter(g);
// assume buffering
OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
try {
owlsim = new SimpleOwlSim(sourceOntol);
((SimpleOwlSim) owlsim).setReasoner(reasoner);
reasoner.flush();
Double e = owlsim.getEntropy();
LOG.info("ENTROPY OF ONTOLOGY = "+e);
for (String subset : g.getAllUsedSubsets()) {
LOG.info("SUBSET:"+subset);
e = owlsim.getEntropy(g.getOWLClassesInSubset(subset));
LOG.info(" ENTROPY OF "+subset+" = "+e);
}
}
finally {
reasoner.dispose();
}
}
示例4: testInfoProfile
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void testInfoProfile() throws OWLOntologyCreationException, IOException, UnknownOWLClassException, OBOFormatParserException {
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOBO(getResource("sim/mp-subset-1.obo").getAbsolutePath());
g = new OWLGraphWrapper(sourceOntol);
parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);
owlpp = new OWLPrettyPrinter(g);
final int truncLen = 200;
// assume buffering
OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
try {
createOwlSim();
//sos.setReasoner(reasoner);
LOG.info("Reasoner="+owlsim.getReasoner());
SimJSONEngine sj = new SimJSONEngine(g, owlsim);
//sos.saveOntology("/tmp/z.owl");
reasoner.flush();
owlsim.createElementAttributeMapFromOntology();
owlsim.computeSystemStats();
for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
String jsonStr = sj.getAttributeInformationProfile(owlsim.getAttributesForElement(i));
LOG.info("InformationInfo:"+jsonStr);
}
}
finally {
reasoner.dispose();
}
}
示例5: testSearch
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void testSearch() throws Exception {
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOBO(getResource("sim/mp-subset-1.obo").getAbsolutePath());
g = new OWLGraphWrapper(sourceOntol);
parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);
owlpp = new OWLPrettyPrinter(g);
final int truncLen = 200;
// assume buffering
OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
try {
createOwlSim();
//sos.setReasoner(reasoner);
LOG.info("Reasoner="+owlsim.getReasoner());
SimJSONEngine sj = new SimJSONEngine(g, owlsim);
//sos.saveOntology("/tmp/z.owl");
reasoner.flush();
owlsim.createElementAttributeMapFromOntology();
owlsim.computeSystemStats();
for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
Set<OWLClass> atts = owlsim.getAttributesForElement(i);
String jsonStr = sj.search(atts, "MGI", true, false);
LOG.info(jsonStr);
}
}
finally {
reasoner.dispose();
}
}
示例6: testAnnotationSufficiencyScore
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void testAnnotationSufficiencyScore() throws OWLOntologyCreationException, OBOFormatParserException, IOException, UnknownOWLClassException {
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOBO(getResource("sim/mp-subset-1.obo").getAbsolutePath());
g = new OWLGraphWrapper(sourceOntol);
parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);
setOutput("target/basic-owlsim-test.out");
// assume buffering
OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
try {
this.createOwlSim();
owlsim.createElementAttributeMapFromOntology();
reasoner.flush();
owlsim.computeSystemStats();
LOG.info("Overall statistical summary for Test:");
LOG.info(owlsim.getSystemStats().toString());
for (OWLNamedIndividual i : owlsim.getAllElements()) {
LOG.info(i.toStringID()+" scores:");
double score = owlsim.calculateOverallAnnotationSufficiencyForIndividual(i);
LOG.info(owlsim.computeIndividualStats(i).getSummary()+"annotation_sufficiency: "+score);
}
} finally {
reasoner.dispose();
}
}
示例7: testOrganismPair
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void testOrganismPair() throws Exception{
g = getOntologyWrapper("limb_gci.owl");
ElkReasonerFactory rf = new ElkReasonerFactory();
OWLReasoner r = rf.createReasoner(g.getSourceOntology());
try {
Set<OWLSubClassOfAxiom> axioms = GCIUtil.getSubClassOfSomeValuesFromAxioms(r);
int n = 0;
for (OWLSubClassOfAxiom axiom : axioms) {
String c = ((OWLClass) axiom.getSubClass()).getIRI().toString();
OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) axiom.getSuperClass();
String rel = ((OWLObjectProperty) svf.getProperty()).getIRI().toString();
String p = ((OWLClass) svf.getFiller()).getIRI().toString();
String axstr = c + " " + rel + " " + p;
System.out.println(axstr);
if ("http://x.org/phalanx-development http://x.org/part-of http://x.org/digit-development".equals(axstr)) {
n |= 1;
}
if ("http://x.org/digit-development http://x.org/part-of http://x.org/autopod-development".equals(axstr)) {
n |= 2;
}
if ("http://x.org/limb-development http://x.org/part-of http://x.org/organism-development".equals(axstr)) {
n |= 4;
}
if ("http://x.org/autopod-development http://x.org/part-of http://x.org/limb-development".equals(axstr)) {
n |= 8;
}
}
assertEquals(4, axioms.size());
assertEquals(15, n);
}
finally {
r.dispose();
}
}
示例8: coAnnotatedTest
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
/**
* Test fetching commonly co-annotated classes in a set of individuals
* vs the background (entire) corpus using the TF-IDF method.
* @throws Exception
* @throws MathException
*/
@Test
public void coAnnotatedTest() throws Exception, MathException {
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOWL(getResourceIRIString("sim/mp-subset-1.obo"));
g = new OWLGraphWrapper(sourceOntol);
parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);
owlpp = new OWLPrettyPrinter(g);
// assume buffering
OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
try {
this.createOwlSim();
owlsim.createElementAttributeMapFromOntology();
reasoner.flush();
owlsim.populateFullCoannotationMatrix();
Set<OWLNamedIndividual> inds = sourceOntol.getIndividualsInSignature();
for (OWLNamedIndividual i : inds) {
//get a random set of other individuals to do the subset
List<ClassCount> coaClasses = owlsim.getCoAnnotatedClassesForIndividual(i);
LOG.info("Found "+coaClasses.size()+" coannotated classes for "+g.getIdentifier(i));
for (ClassCount cc : coaClasses) {
LOG.info(owlpp.render(cc.c)+cc.score);
}
}
}
finally {
reasoner.dispose();
}
}
示例9: test
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
GafObjectsBuilder b = new GafObjectsBuilder();
final GafDocument gaf = b.buildDocument("src/test/resources/not_bioentity_closure/mini-test.gaf");
ParserWrapper pw = new ParserWrapper();
OWLOntology testOwl = pw.parse(new File("src/test/resources/not_bioentity_closure/mini-test.obo").getCanonicalPath());
final OWLGraphWrapper g = new OWLGraphWrapper(testOwl);
OWLOntology slimOWL = pw.parse(TaxonTools.TAXON_PURL);
ElkReasonerFactory rf = new ElkReasonerFactory();
MockGafSolrDocumentLoader l = new MockGafSolrDocumentLoader();
OWLReasoner r = null;
try {
r = rf.createReasoner(slimOWL);
l.setGafDocument(gaf);
l.setGraph(g);
l.setEcoTools(new EcoTools(pw));
l.setTaxonTools(new TaxonTools(r, true));
l.load();
}
finally {
if (r != null) {
r.dispose();
}
}
List<Map<String, Object>> docs = l.getDocumentCollection().getDocuments();
assertFalse(docs.size() == 0);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
for (Map<String, Object> doc : docs) {
String json = gson.toJson(doc);
System.out.println(json);
}
}
示例10: GOReciprocalAnnotationRule
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public GOReciprocalAnnotationRule(OWLGraphWrapper graph, TraversingEcoMapper eco) {
this.graph = graph;
evidences = eco.getAllValidEvidenceIds("IPI", true);
OWLClass proteinBindingCls = graph.getOWLClassByIdentifier(PROTEIN_BINDING_GO_ID);
if (proteinBindingCls == null) {
throw new RuntimeException("No class found for identifier: "+PROTEIN_BINDING_GO_ID);
}
ElkReasonerFactory factory = new ElkReasonerFactory();
OWLReasoner reasoner = null;
try {
reasoner = factory.createReasoner(graph.getSourceOntology());
proteinBindingClasses = new HashSet<OWLClass>();
proteinBindingClasses.add(proteinBindingCls);
Set<OWLClass> subClasses = reasoner.getSubClasses(proteinBindingCls, false).getFlattened();
for (OWLClass cls : subClasses) {
if (!cls.isBottomEntity() && !cls.isTopEntity()) {
proteinBindingClasses.add(cls);
}
}
}
finally {
if (reasoner != null) {
reasoner.dispose();
}
}
}
示例11: testScores
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void testScores() throws OWLOntologyCreationException, IOException, UnknownOWLClassException, OBOFormatParserException {
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOBO(getResource("sim/mp-subset-1.obo").getAbsolutePath());
g = new OWLGraphWrapper(sourceOntol);
parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);
owlpp = new OWLPrettyPrinter(g);
final int truncLen = 200;
// assume buffering
OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
try {
createOwlSim();
//sos.setReasoner(reasoner);
LOG.info("Reasoner="+owlsim.getReasoner());
SimJSONEngine sj = new SimJSONEngine(g, owlsim);
//sos.saveOntology("/tmp/z.owl");
reasoner.flush();
owlsim.createElementAttributeMapFromOntology();
//owlsim.computeSystemStats();
for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
String jsonStr = sj.getAnnotationSufficiencyScore(i);
LOG.info("ANNOTSUFFICIENCY:"+jsonStr);
}
}
finally {
reasoner.dispose();
}
}
示例12: testOrganismPair
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public void testOrganismPair() throws Exception{
g = getOntologyWrapper("q-in-e-v1.omn");
g.getConfig().isGraphReasonedAndRelaxed = false;
OWLReasoner r = getGraphReasoner(g);
try {
findDescendants(r, "part_of some limb", 3);
findDescendants(r, "inheres_in_part_of some limb", 4);
findDescendants(r, "limb", 3);
findDescendants(r, "abnormal_morphology");
findDescendants(r, "develops_from some limb_bud", 6);
findDescendants(r, "part_of some hindlimb", 1);
findDescendants(r, "autopod", 3);
findDescendants(r, "autopod and (part_of some hindlimb)", 1);
findDescendants(r, "(part_of some limb) and not foot", 2);
findDescendants(r, "not foot and (part_of some limb)", 2);
findDescendants(r, "not foot");
findDescendants(r, "inheres_in some hand", 1);
findDescendants(r, "inheres_in some limb", 2);
findDescendants(r, "inheres_in some (hindlimb or forelimb)", 2);
findDescendants(r, "inheres_in some (part_of some limb)", 2);
findDescendants(r, "inheres_in_part_of some limb", 4);
findDescendants(r, "hyperplastic and inheres_in_part_of some limb", 2);
findDescendants(r, "hyperplastic and inheres_in some (part_of some (anterior_to some hindlimb))", 1);
findDescendants(r, "(anterior_to some hindlimb)", 1);
findDescendants(r, "part_of some (anterior_to some hindlimb)", 1);
findDescendants(r, "hyperplastic and inheres_in some hand", 1);
findDescendants(r, "hyperplastic_hand", 1);
findDescendants(r, "hyperplastic", 3);
findIndividuals(r, "metazoan", 5);
findIndividuals(r, "human", 3);
findIndividuals(r, "has_phenotype some hyperplastic_hand", 3);
findIndividuals(r, "human and has_phenotype some hyperplastic_hand", 2); // underestimation without pre-reasoning
findIndividuals(r, "human and has_phenotype some abnormal_morphology", 3);
findIndividuals(r, "human and has_phenotype some hyperplastic", 3);
////findIndividuals(r, "has_phenotype some (not hyperplastic)", 2);
findIndividuals(r, "fly and has_phenotype some (inheres_in some compound_eye)", 1);
findIndividuals(r, "fly and has_phenotype some (inheres_in some (has_part some ommatidium))", 1);
}
finally {
r.dispose();
}
}
示例13: assertAllInferences
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public static void assertAllInferences(OWLGraphWrapper graph, String idsInputFile) {
final OWLOntology ontology = graph.getSourceOntology();
final OWLOntologyManager manager = ontology.getOWLOntologyManager();
final OWLDataFactory factory = manager.getOWLDataFactory();
Set<String> ids = loadIdsInputFile(idsInputFile);
final OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
final OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
try {
logger.info("Start check all");
// check all classes from the main ontology
AllInferenceReport report = new AllInferenceReport();
Set<OWLClass> classes = ontology.getClassesInSignature(Imports.EXCLUDED);
int count = 0;
int total = ids != null ? ids.size() : classes.size();
int step = 100;
for (final OWLClass owlClass : classes) {
if (ids != null) {
String id = graph.getIdentifier(owlClass);
if (ids.contains(id) == false) {
continue;
}
}
count += 1;
// get axioms for the current class
Set<OWLClassAxiom> axioms = ontology.getAxioms(owlClass, Imports.EXCLUDED);
handleAxioms(owlClass, axioms, ontology, manager, factory, reasoner, report);
// handleAxioms2(owlClass, axioms, ontology, manager, factory, reasoner, report);
if (count % step == 0) {
logger.info("Current count "+count+" of "+total);
}
}
PrintWriter writer = new PrintWriter(System.out);
report.printReport(writer);
writer.close();
}
finally {
reasoner.dispose();
}
}
示例14: testCompareIndividuals
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
@Test
public void testCompareIndividuals() throws Exception {
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOWL(getResourceIRIString("sim/mp-subset-1.obo"));
g = new OWLGraphWrapper(sourceOntol);
parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);
owlpp = new OWLPrettyPrinter(g);
final int truncLen = 200;
// assume buffering
OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
try {
createOwlSim();
//sos.setReasoner(reasoner);
LOG.info("Reasoner="+owlsim.getReasoner());
SimJSONEngine sj = new SimJSONEngine(g, owlsim);
//sos.saveOntology("/tmp/z.owl");
reasoner.flush();
for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
//System.out.println("COMPARING: "+i);
for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) {
String jsonStr = sj.compareAttributeSetPair(
owlsim.getAttributesForElement(i),
owlsim.getAttributesForElement(j)
);
if(jsonStr.length() < truncLen)
LOG.warn(jsonStr);
else
LOG.info("SAMPLE:"+jsonStr.substring(0, truncLen));
}
}
// test to ensure robust in face of unknown classes
df = g.getDataFactory();
OWLClass unkC = df.getOWLClass(IRI.create("http://x.org"));
Set<OWLClass> uset = Collections.singleton(unkC);
boolean isThrown = false;
try {
sj.compareAttributeSetPair(uset, uset);
} catch (UnknownOWLClassException e) {
// we expect this
isThrown = true;
}
assertTrue(isThrown);
sj.compareAttributeSetPair(uset, uset, true);
OWLClass thing = df.getOWLThing();
Set<OWLClass> things = Collections.singleton(unkC);
// we expect no results here
LOG.info("TxT:"+sj.compareAttributeSetPair(things, things, true));
}
finally {
reasoner.dispose();
}
}
示例15: main
import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public static void main(String[] args) throws OWLOntologyCreationException {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// Load your ontology.
OWLOntology ont = man.loadOntologyFromOntologyDocument(new File(
"c:/ontologies/ontology.owl"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Create your desired query class expression. In this example we
// will query ObjectIntersectionOf(A ObjectSomeValuesFrom(R B)).
PrefixManager pm = new DefaultPrefixManager("http://example.org/");
OWLClass A = dataFactory.getOWLClass(":A", pm);
OWLObjectProperty R = dataFactory.getOWLObjectProperty(":R", pm);
OWLClass B = dataFactory.getOWLClass(":B", pm);
OWLClassExpression query = dataFactory.getOWLObjectIntersectionOf(A,
dataFactory.getOWLObjectSomeValuesFrom(R, B));
// Create a fresh name for the query.
OWLClass newName = dataFactory.getOWLClass(IRI.create("temp001"));
// Make the query equivalent to the fresh class
OWLAxiom definition = dataFactory.getOWLEquivalentClassesAxiom(newName,
query);
man.addAxiom(ont, definition);
// Remember to either flush the reasoner after the ontology change
// or create the reasoner in non-buffering mode. Note that querying
// a reasoner after an ontology change triggers re-classification of
// the whole ontology which might be costly. Therefore, if you plan
// to query for multiple complex class expressions, it will be more
// efficient to add the corresponding definitions to the ontology at
// once before asking any queries to the reasoner.
reasoner.flush();
// You can now retrieve subclasses, superclasses, and instances of
// the query class by using its new name instead.
reasoner.getSubClasses(newName, true);
reasoner.getSuperClasses(newName, true);
reasoner.getInstances(newName, false);
// After you are done with the query, you should remove the definition
man.removeAxiom(ont, definition);
// You can now add new definitions for new queries in the same way
// After you are done with all queries, do not forget to free the
// resources occupied by the reasoner
reasoner.dispose();
}