changeset 15:622cde484f4c draft

Add new tool to perform OPPL queries
author Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Thu, 12 Jul 2012 17:12:00 +0200
parents 68c4ae500a13
children 6c25e717c896
files OPPL/FaCT++-OSX-v1.5.2/32bit/libFaCTPlusPlusJNI.jnilib OPPL/FaCT++-OSX-v1.5.2/64bit/libFaCTPlusPlusJNI.jnilib OPPL/FaCT++-linux-v1.5.2/32bit/FaCT++ OPPL/FaCT++-linux-v1.5.2/32bit/libFaCTPlusPlusJNI.so OPPL/FaCT++-linux-v1.5.2/64bit/FaCT++ OPPL/FaCT++-linux-v1.5.2/64bit/libFaCTPlusPlusJNI.so OPPL/FaCT++-linux-v1.5.2/Models.lisp/create-new-test OPPL/README OPPL/oppl_query.jar OPPL/oppl_query.xml OPPL/oppl_query_lib/FaCTpp-OWLAPI-3.2-v1.5.2.jar OPPL/oppl_query_lib/HermiT.jar OPPL/oppl_query_lib/antlr-runtime-3.2.jar OPPL/oppl_query_lib/aterm-java-1.6.jar OPPL/oppl_query_lib/jgrapht-jdk1.5.jar OPPL/oppl_query_lib/org.coode.oppl-API.jar OPPL/oppl_query_lib/owlapi-bin.jar OPPL/oppl_query_lib/parsers.jar OPPL/oppl_query_lib/pellet-core.jar OPPL/oppl_query_lib/pellet-datatypes.jar OPPL/oppl_query_lib/pellet-el.jar OPPL/oppl_query_lib/pellet-owlapiv3.jar OPPL/oppl_query_lib/pellet-query.jar OPPL/oppl_query_lib/pellet-rules.jar OPPL/src/GalaxyOWLAPI.java OPPL/src/OPPLQueryGalaxy.java OPPL/test-data/ontology/single/test.owl OPPL/test-data/oppl_script/test.oppl OPPL/test-data/oppl_script/test_oppl_query.oppl OPPL/test-data/oppl_script/test_oppl_query_object_ind.oppl OPPL/test-data/oppl_script/test_oppl_query_object_prop.oppl
diffstat 24 files changed, 300 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/OPPL/README	Sat Mar 31 12:54:09 2012 +0200
+++ b/OPPL/README	Thu Jul 12 17:12:00 2012 +0200
@@ -12,9 +12,11 @@
 oppl_galaxy_tool.jar
 inference.jar
 query.jar
+oppl_query.jar
 oppl_galaxy_lib/
 inference_lib/
 query_lib/
+oppl_query_lib/
 FaCT++-linux-v1.5.2/ 
 FaCT++-OSX-v1.5.2/
  
@@ -29,6 +31,7 @@
     <tool file="OPPL/oppl.xml"/>
     <tool file="OPPL/inference.xml"/>
     <tool file="OPPL/query.xml"/>
+    <tool file="OPPL/oppl_query.xml"/>   
   </section>
 
 6.- Start Galaxy.
@@ -38,7 +41,7 @@
 FORESEEN FEATURES
 =================
 
-General (OPPL, Inference, Query):
+General (OPPL, Inference, Query, OPPL query):
 
 - Support for processing ontologies that import other ontologies loaded
 in galaxy.
@@ -61,6 +64,8 @@
 - Support for DataPropertyAssertion, DataPropertyHierarchy,
 DifferentIndividuals, ...
 
+OPPL query:
+
 
 
 KNOWN BUGS AND ISSUES
Binary file OPPL/oppl_query.jar has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OPPL/oppl_query.xml	Thu Jul 12 17:12:00 2012 +0200
@@ -0,0 +1,68 @@
+<tool id="oppl_query" name="Perform an OPPL query against an ontology" version="1.0.1">
+	<description>It performs a query, expressed in OPPL Syntax, against an OWL ontology</description>
+	
+	<!-- Galaxy is not happy with OPPL throwing info into stderr, and I have redirected stderr to /dev/null, which is a bad solution since OPPL galaxy does not inform properly when it fails -->
+	<!-- More info on the stderr issue: http://wiki.g2.bx.psu.edu/Future/Job%20Failure%20When%20stderr -->
+	<!-- Testing with wrapper.sh but no success so far -->
+
+	<!-- DEFAULT SETTINGS -->
+	
+	<!-- For big ontologies I use -Xmx7000M -Xms250M -DentityExpansionLimit=1000000000 If that's too much for your machine simply delete or modify at will, but since Galaxy is usually used in a server setting it makes sense to use a big chunk of memory -->
+
+	<command>
+		java -Xmx7000M -Xms250M -DentityExpansionLimit=1000000000 -jar ${__tool_data_path__}/shared/jars/oppl_query.jar $ontology $reasoner $answer_format "$query" > $output 2>/dev/null
+	</command>
+	
+	<!-- FACT++ -->
+	
+	<!-- If you are planning to use FaCT++ you have to uncomment bellow (And comment the default settings above) and replace the -Djava.library.path with the appropiate JNI library path for your platform:FaCT++-linux-v1.5.2/64bit, FaCT++-linux-v1.5.2/32bit, FaCT++-OSX-v1.5.2/64bit, ...... -->
+	<!-- Using this setting doesn't upset the rest of the reasoners so you may as well leave it on if you plan to switch between FaCT++, Pellet and HermiT -->
+	
+	<!--<command>
+		java -Djava.library.path=${__tool_data_path__}/shared/jars/FaCT++-linux-v1.5.2/64bit -Xmx7000M -Xms250M -DentityExpansionLimit=1000000000 -jar ${__tool_data_path__}/shared/jars/oppl_query.jar $ontology $reasoner $answer_format "$query" > $output 2>/dev/null
+	</commadn>-->
+	
+
+	<inputs>
+		<param name="ontology" type="data" label="Input ontology file"/>
+		<param name="query" type="text" size="100" value="" label="OPPL Query" />
+		<param name="reasoner" type="select" label="Choose reasoner">
+			<option value="Pellet" selected="true">Pellet</option>
+			<option value="HermiT">HermiT</option>
+			<option value="FaCTPlusPlus">FaCT++</option>
+		</param>
+		<param name="answer_format" type="select" label="Choose how to render the retrieved entities">
+			<option value="URI" selected="true">URI</option>
+			<option value="URIfragment">URI fragment</option>
+			<option value="URIfragment2OBO">OBO type URI fragment (e.g. GO_0000022 to GO:0000022)</option>
+		</param>
+	</inputs>
+	<outputs>
+		<data type="data" format="text" name="output" />
+	</outputs>
+	<tests>
+		<test>
+			<param name="input" value="test.owl"/>
+			<param name="query" value="?p:OBJECTPROPERTY SELECT Transitive ?p "/>
+			<param name="reasoner" value="Pellet"/>
+			<param name="answer_format" value="URIfragment"/>
+			<output name="out_file" file="query_result"/>	
+		</test>
+	</tests>
+	<help>
+
+**About OPPL-Query-Galaxy**
+
+  OPPL-Query-Galaxy can be used to execute an OPPL query against an OWL ontology (?whole:CLASS, ?part:CLASS SELECT ?part SubClassOf part_of some ?whole WHERE ?part != Nothing). The result is a two column table with the entities that have been bound by the variables. 
+  
+**Formats**
+
+  OPPL-Query-Galaxy uses the OWL API, and therefore it can load any ontology format that such API is able to load: OBO flat file, OWL (RDF/XML, OWL/XML, Functional, Manchester), turtle, and KRSS. The output is a list of terms.
+
+**Contact**
+
+  Please send any request or comment to mikel.egana.aranguren@gmail.com.
+
+	</help>
+
+</tool>
Binary file OPPL/oppl_query_lib/FaCTpp-OWLAPI-3.2-v1.5.2.jar has changed
Binary file OPPL/oppl_query_lib/HermiT.jar has changed
Binary file OPPL/oppl_query_lib/antlr-runtime-3.2.jar has changed
Binary file OPPL/oppl_query_lib/aterm-java-1.6.jar has changed
Binary file OPPL/oppl_query_lib/jgrapht-jdk1.5.jar has changed
Binary file OPPL/oppl_query_lib/org.coode.oppl-API.jar has changed
Binary file OPPL/oppl_query_lib/owlapi-bin.jar has changed
Binary file OPPL/oppl_query_lib/parsers.jar has changed
Binary file OPPL/oppl_query_lib/pellet-core.jar has changed
Binary file OPPL/oppl_query_lib/pellet-datatypes.jar has changed
Binary file OPPL/oppl_query_lib/pellet-el.jar has changed
Binary file OPPL/oppl_query_lib/pellet-owlapiv3.jar has changed
Binary file OPPL/oppl_query_lib/pellet-query.jar has changed
Binary file OPPL/oppl_query_lib/pellet-rules.jar has changed
--- a/OPPL/src/GalaxyOWLAPI.java	Sat Mar 31 12:54:09 2012 +0200
+++ b/OPPL/src/GalaxyOWLAPI.java	Thu Jul 12 17:12:00 2012 +0200
@@ -38,7 +38,6 @@
 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;
@@ -63,7 +62,7 @@
 /**
  * A wrapper of the OWL API 
  * 
- * @author Mikel Egaña Aranguren
+ * @author Mikel Ega��a Aranguren
  */
 public class GalaxyOWLAPI {
 	private OWLOntologyManager manager;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OPPL/src/OPPLQueryGalaxy.java	Thu Jul 12 17:12:00 2012 +0200
@@ -0,0 +1,171 @@
+/**
+ * 
+ */
+package es.upm.cbgp.opplquery.oppl.galaxy;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Iterator;
+import java.util.Scanner;
+import java.util.Set;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.semanticweb.owlapi.expression.ParserException;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLObject;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+
+import es.upm.fi.dia.oeg.oppl.galaxy.GalaxyOWLAPI;
+
+import org.coode.oppl.ChangeExtractor;
+import org.coode.oppl.ConstraintSystem;
+import org.coode.oppl.OPPLParser;
+import org.coode.oppl.OPPLScript;
+import org.coode.oppl.ParserFactory;
+import org.coode.parsers.ErrorListener;
+import org.coode.parsers.LoggerErrorListener;
+import org.coode.oppl.bindingtree.Assignment;
+import org.coode.oppl.bindingtree.BindingNode;
+import org.coode.oppl.exceptions.QuickFailRuntimeExceptionHandler;
+import org.coode.oppl.exceptions.RuntimeExceptionHandler;
+
+public class OPPLQueryGalaxy {
+
+	/**
+	 * @param args
+	 * @throws OWLOntologyCreationException 
+	 * @throws ParserException 
+	 * @throws FileNotFoundException 
+	 */
+	public static void main(String[] args) throws OWLOntologyCreationException, ParserException, FileNotFoundException {
+		// Get the arguments from command-line
+		String OWLFilePath = args [0]; // /home/mikel/UPM/OPPL_galaxy/OPPL/OPPL/test-data/ontology/single/test.owl
+		String reasoner_type = args [1]; // Pellet|FaCTPlusPlus|HermiT
+		String Answer_render = args [2]; // URI|URIfragment|URIfragment2OBO
+		String OPPL_script_sourcee = args [3];
+		
+//		String OPPL_script_file = args [3]; 
+//		File OPPL_script_file = new File("/home/mikel/UPM/OPPL_galaxy/OPPL/OPPL/test-data/oppl_script/test_oppl_query.oppl");
+//		File OPPL_script_file = new File("/home/mikel/UPM/OPPL_galaxy/OPPL/OPPL/test-data/oppl_script/test_oppl_query_object_prop.oppl");
+//		File OPPL_script_file = new File("/home/mikel/UPM/OPPL_galaxy/OPPL/OPPL/test-data/oppl_script/test_oppl_query_object_ind.oppl");
+		
+//		String OPPL_script_source = "";
+//		Scanner input = new Scanner(OPPL_script_file);
+//		while(input.hasNext()) {
+//		    String nextToken = input.next();
+//		    OPPL_script_source = OPPL_script_source + " " + nextToken;
+//		}
+//		input.close();
+		
+		// Create the manager
+		GalaxyOWLAPI galaxyowlapi = new GalaxyOWLAPI();
+				
+		// Load the main ontology and hope for the imported URIs to be resolvable		
+		galaxyowlapi.loadMainOntology(OWLFilePath);
+				
+		// Set the reasoner
+		
+		// Pellet
+		if(reasoner_type.equals("Pellet")){
+			galaxyowlapi.setReasonerPellet();
+		}
+		// FaCTPlusPlus
+		else if (reasoner_type.equals("FaCTPlusPlus")){
+			galaxyowlapi.setReasonerFaCT();
+		}
+		// HermiT
+		else{
+			galaxyowlapi.setReasonerHermit();
+		}
+		
+		OPPL_script_source = completeOPPLScript(OPPL_script_source);
+//		System.out.println(OPPL_script_source);
+		
+		ParserFactory parserFactory = new ParserFactory(galaxyowlapi.getOWLManager(), galaxyowlapi.getMainOntology(), galaxyowlapi.getReasoner()); 
+		Logger logger = Logger.getLogger(OPPLQueryGalaxy.class.getName());
+		ErrorListener errorListener = (ErrorListener) new LoggerErrorListener(logger);
+		OPPLParser opplparser = parserFactory.build(errorListener);
+		OPPLScript OPPLscript = opplparser.parse(OPPL_script_source);
+		RuntimeExceptionHandler exceptionhandler = new QuickFailRuntimeExceptionHandler(); 		
+		ChangeExtractor extractor = new ChangeExtractor(exceptionhandler, true);
+		extractor.visit(OPPLscript);
+		ConstraintSystem cs = OPPLscript.getConstraintSystem();
+		Set<BindingNode> nodes =  cs.getLeaves();
+				
+		Iterator NodesIterator = nodes.iterator();
+		while(NodesIterator.hasNext()){
+			Set Assignments = ((BindingNode)NodesIterator.next()).getAssignments();
+			Iterator AssignmentIterator = Assignments.iterator();
+			while(AssignmentIterator.hasNext()){
+				Assignment assignment = (Assignment)AssignmentIterator.next();
+				System.out.print(assignment.getAssignedVariable().toString());
+				System.out.print("\t");	
+				String OWLObjectString = ((OWLObject)assignment.getAssignment()).toString();
+				IRI entityIRI = IRI.create(OWLObjectString.substring(1,OWLObjectString.length()-1));
+				print_result_entity(entityIRI, Answer_render);
+				System.out.print("\n");
+			}		
+		}
+	}
+	
+	//URI|URIfragment|URIfragment2OBO
+	private static void print_result_entity (IRI iri, String Answer_render){
+		if(Answer_render.equals("URI")){
+			System.out.print(iri);
+		}
+		
+		// Weird bug: in eclipse it can print out the IRIs of every entity, but in Galaxy it can't!
+		// done manually
+		else if(Answer_render.equals("URIfragment")){	
+			if(iri.toString().contains("#")){
+				System.out.print(iri.getFragment());
+			}
+			else{
+				String [] iri_tokens = iri.toString().split("/");
+				System.out.print(iri_tokens[iri_tokens.length-1]);
+			}
+		}
+		else{
+			if(iri.toString().contains("#")){
+				System.out.print((iri.getFragment()).replace("_", ":"));
+			}
+			else{
+				String [] iri_tokens = iri.toString().split("/");
+				System.out.print((iri_tokens[iri_tokens.length-1]).replace("_", ":"));
+			}
+		}
+	}
+	
+	// Very crappy stuff: complete the query to make a whole OPPL script that can be parsed
+	private static String completeOPPLScript (String OPPLQuery){
+		
+		// Get the first variable and add at least an axiom to make a whole script		
+		Pattern p = Pattern.compile("(\\?\\w+):(CLASS|INDIVIDUAL|OBJECTPROPERTY|DATAPROPERTY|ANNOTATIONPROPERTY|CONSTANT)");
+		Matcher m = p.matcher(OPPLQuery);
+		m.find();
+		if (m.group(2).equals("CLASS")){
+			OPPLQuery = OPPLQuery + " BEGIN ADD " + m.group(1) + " SubClassOf !A END;";
+		}
+		else if (m.group(2).equals("INDIVIDUAL")){
+			OPPLQuery = OPPLQuery + " BEGIN ADD " + m.group(1) + " !p !b END;";
+		}
+		else if (m.group(2).equals("OBJECTPROPERTY")){
+			OPPLQuery = OPPLQuery + " BEGIN ADD Transitive ?p END;";
+		}
+//		else if (m.group(2).equals("DATAPROPERTY")){
+//			OPPLQuery = OPPLQuery + " BEGIN ADD ?whole SubClassOf !A END;";
+//		}
+//		else if (m.group(2).equals("ANNOTATIONPROPERTY")){
+//			OPPLQuery = OPPLQuery + " BEGIN ADD ?whole SubClassOf !A END;";
+//		}
+//		else if (m.group(2).equals("CONSTANT")){
+//			OPPLQuery = OPPLQuery + " BEGIN ADD ?whole SubClassOf !A END;";
+//		}
+		else{
+			OPPLQuery = "Malformed OPPL query";
+		}
+		return OPPLQuery;
+	}
+}
--- a/OPPL/test-data/ontology/single/test.owl	Sat Mar 31 12:54:09 2012 +0200
+++ b/OPPL/test-data/ontology/single/test.owl	Thu Jul 12 17:12:00 2012 +0200
@@ -32,6 +32,14 @@
     
 
 
+    <!-- http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#transitive_prop -->
+
+    <owl:ObjectProperty rdf:about="http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#transitive_prop">
+        <rdf:type rdf:resource="&owl;TransitiveProperty"/>
+    </owl:ObjectProperty>
+    
+
+
     <!-- http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl/part_of -->
 
     <owl:ObjectProperty rdf:about="&Ontology1314715036188;part_of"/>
@@ -55,6 +63,12 @@
     
 
 
+    <!-- http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#Ind_test_OPPL_query -->
+
+    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#Ind_test_OPPL_query"/>
+    
+
+
     <!-- http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl/OPPL_test -->
 
     <owl:Class rdf:about="&Ontology1314715036188;OPPL_test"/>
@@ -122,9 +136,37 @@
     <owl:Class rdf:about="&Ontology1314715036188;whole">
         <rdfs:subClassOf rdf:resource="&Ontology1314715036188;OPPL_test"/>
     </owl:Class>
+    
+
+
+    <!-- 
+    ///////////////////////////////////////////////////////////////////////////////////////
+    //
+    // Individuals
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+     -->
+
+    
+
+
+    <!-- http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#A -->
+
+    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#A">
+        <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#Ind_test_OPPL_query"/>
+        <Ontology1314715036188:prop rdf:resource="http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#B"/>
+    </owl:NamedIndividual>
+    
+
+
+    <!-- http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#B -->
+
+    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#B">
+        <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2011/7/Ontology1314715036188.owl#Ind_test_OPPL_query"/>
+    </owl:NamedIndividual>
 </rdf:RDF>
 
 
 
-<!-- Generated by the OWL API (version 3.2.2.1782) http://owlapi.sourceforge.net -->
+<!-- Generated by the OWL API (version 3.3.1957) http://owlapi.sourceforge.net -->
 
--- a/OPPL/test-data/oppl_script/test.oppl	Sat Mar 31 12:54:09 2012 +0200
+++ b/OPPL/test-data/oppl_script/test.oppl	Thu Jul 12 17:12:00 2012 +0200
@@ -4,5 +4,4 @@
 ?part SubClassOf part_of some ?whole WHERE ?part != Nothing
 BEGIN
 ADD ?part SubClassOf part_of only ?whole
-END;
-
+END;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OPPL/test-data/oppl_script/test_oppl_query.oppl	Thu Jul 12 17:12:00 2012 +0200
@@ -0,0 +1,4 @@
+?whole:CLASS,
+?part:CLASS
+SELECT
+?part SubClassOf part_of some ?whole WHERE ?part != Nothing
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OPPL/test-data/oppl_script/test_oppl_query_object_ind.oppl	Thu Jul 12 17:12:00 2012 +0200
@@ -0,0 +1,4 @@
+?a:INDIVIDUAL,
+?part:CLASS,
+?c:INDIVIDUAL
+SELECT ?a prop ?c
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OPPL/test-data/oppl_script/test_oppl_query_object_prop.oppl	Thu Jul 12 17:12:00 2012 +0200
@@ -0,0 +1,2 @@
+?p:OBJECTPROPERTY
+SELECT Transitive ?p 
\ No newline at end of file