diff OPPL/src/GalaxyOWLAPI.java @ 13:7e6604a5ee55

New query tool added
author Mikel Egaña Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Thu, 29 Mar 2012 14:49:22 +0200
parents 6ca67b155e32
children 622cde484f4c
line wrap: on
line diff
--- a/OPPL/src/GalaxyOWLAPI.java	Thu Mar 22 14:37:46 2012 +0100
+++ b/OPPL/src/GalaxyOWLAPI.java	Thu Mar 29 14:49:22 2012 +0200
@@ -10,10 +10,16 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Scanner;
+import java.util.Set;
 
+import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxEditorParser;
 import org.coode.owlapi.obo.parser.OBOOntologyFormat;
+import org.coode.parsers.BidirectionalShortFormProviderAdapter;
 import org.semanticweb.HermiT.Reasoner;
 import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.expression.OWLEntityChecker;
+import org.semanticweb.owlapi.expression.ParserException;
+import org.semanticweb.owlapi.expression.ShortFormEntityChecker;
 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
 import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
 import org.semanticweb.owlapi.model.AddAxiom;
@@ -22,16 +28,20 @@
 import org.semanticweb.owlapi.model.OWLAnnotationProperty;
 import org.semanticweb.owlapi.model.OWLAxiom;
 import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassExpression;
 import org.semanticweb.owlapi.model.OWLDataFactory;
 import org.semanticweb.owlapi.model.OWLLiteral;
+import org.semanticweb.owlapi.model.OWLNamedIndividual;
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyChange;
 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
 import org.semanticweb.owlapi.model.OWLOntologyStorageException;
 import org.semanticweb.owlapi.reasoner.InferenceType;
+import org.semanticweb.owlapi.reasoner.NodeSet;
 import org.semanticweb.owlapi.reasoner.OWLReasoner;
 import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
+import org.semanticweb.owlapi.util.BidirectionalShortFormProvider;
 import org.semanticweb.owlapi.util.InferredAxiomGenerator;
 import org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator;
 import org.semanticweb.owlapi.util.InferredDisjointClassesAxiomGenerator;
@@ -41,8 +51,10 @@
 import org.semanticweb.owlapi.util.InferredSubObjectPropertyAxiomGenerator;
 import org.semanticweb.owlapi.util.OWLEntityRenamer;
 import org.semanticweb.owlapi.util.OWLOntologyMerger;
+import org.semanticweb.owlapi.util.SimpleShortFormProvider;
 import org.semanticweb.owlapi.vocab.OWL2Datatype;
 import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
+import org.semanticweb.owlapi.reasoner.Node;
 
 import uk.ac.manchester.cs.factplusplus.owlapiv3.FaCTPlusPlusReasonerFactory;
 
@@ -103,7 +115,47 @@
 		IRI mergedOntologyIRI = IRI.create("http://oeg-upm.net/oppl_galaxy/merged.owl");
 		ontology = merger.createMergedOntology(manager, mergedOntologyIRI);
 	}
-
+	
+	public OWLClassExpression parseMOSClassExpression (String expr) throws ParserException{
+		Set<OWLOntology> importsClosure = ontology.getImportsClosure();
+		BidirectionalShortFormProvider bidiShortFormProvider = new BidirectionalShortFormProviderAdapter(manager, importsClosure, new SimpleShortFormProvider());
+        OWLEntityChecker entityChecker = new ShortFormEntityChecker(bidiShortFormProvider);
+		ManchesterOWLSyntaxEditorParser MOSparser = new ManchesterOWLSyntaxEditorParser(manager.getOWLDataFactory(), expr);
+		MOSparser.setOWLEntityChecker(entityChecker);
+		return MOSparser.parseClassExpression();
+	}
+	
+	public Set<OWLNamedIndividual> getIndividuals (OWLClassExpression expr){
+		return (reasoner.getInstances(expr, false)).getFlattened();
+	}
+	public Set<OWLClass> getEquivalentClasses (OWLClassExpression expr){
+		Node<OWLClass> equivalentClasses = reasoner.getEquivalentClasses(expr);
+	    Set<OWLClass> result;
+	    if (expr.isAnonymous()) {
+	        result = equivalentClasses.getEntities();
+	    }
+	    else {
+	        result = equivalentClasses.getEntitiesMinus(expr.asOWLClass());
+	    }
+	    return result;
+	}
+	
+	public Set<OWLClass> getDirectSuperClasses (OWLClassExpression expr){		
+		 return (reasoner.getSuperClasses(expr, true)).getFlattened();
+	}
+	
+	public Set<OWLClass> getAncestors (OWLClassExpression expr){		
+		 return (reasoner.getSuperClasses(expr, false)).getFlattened();
+	}
+	
+	public Set<OWLClass> getDirectSubClasses (OWLClassExpression expr){		
+		 return (reasoner.getSubClasses(expr, true)).getFlattened();
+	}
+	
+	public Set<OWLClass> getDescendants (OWLClassExpression expr){		
+		 return (reasoner.getSubClasses(expr, false)).getFlattened();
+	}
+	
 	//	CLASS_ASSERTIONS Denotes the computation of the direct types of individuals for each individual in the signature of the imports closure of the root ontology.	
 	
 	public void addCLASS_ASSERTIONS(){