Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-calculate subsumptions between SomeValues expressions #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
semantic.cache
LOG*
147 changes: 147 additions & 0 deletions bin/emr
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/bin/sh
DIRNAME=`dirname $0`
#PATH_TO_ME=`which $0`;
# Give a space-separated list of classpath items RELATIVE TO THE CURRENT SCRIPT
# These will be resolved into absolute pathnames
# Wildcards are allowed
CLASSPATH_RELATIVE=emr.jar

## Check for Cygwin, use grep for a case-insensitive search
IS_CYGWIN="FALSE"
if uname | grep -iq cygwin; then
IS_CYGWIN="TRUE"
fi

# If literal classpath values are needed, uncomment the line below
# This can be useful if the classpath contains URLs
# CLASSPATH_LITERAL=""

# To set a specific default Java path, set the JAVAPATH variable below.
# This value can be overridden with the -Jvm= option.
# If JAVAPATH is not set, the script will use whatever version of Java is on the
# path. If there is no copy of Java on the path, the JAVA_HOME environment
# variable will be used. If that fails, we just use "java" in the hopes that the
# failure message will make a little more sense.
# JAVAPATH="java"

if [ $IS_CYGWIN = "TRUE" ]
then
PATH_SEP=";"
else
PATH_SEP=":"
fi

JAVAARGS=" "
CMDARGS=" "

# Remove the name of this script from the end of the path
PATH_TO_ME=`which $0`;
PATH_TO_ME=`echo $PATH_TO_ME | sed -e "s/\(.*\)\/.*/\1/g"`

if [ $IS_CYGWIN = "TRUE" ]
then
LAUNCHER_DIR="`cygpath --mixed $PATH_TO_ME`"
else
LAUNCHER_DIR="$PATH_TO_ME"
fi


# Just the name of the script.
SCRIPTNAME=`echo $PATH_TO_ME | sed -e "s/.*\/\(.*\)/\1/g"`

## Add vmoptions to JAVAARGS if the proper file is available.
if [ -e "$PATH_TO_ME/$SCRIPTNAME.vmoptions" ]
then
VMOPTIONS=`cat $PATH_TO_ME/$SCRIPTNAME.vmoptions`
for OPTION in "$VMOPTIONS"
do
JAVAARGS="$JAVAARGS '${OPTION}'"
done
else
if [ $EMR_MEMORY ]
then
JAVAARGS="$JAVAARGS -Xmx$EMR_MEMORY"
else
JAVAARGS="$JAVAARGS -Xmx12G"
fi
fi

## Walk through all the command line arguments and add them to
## the CMDARGS depending.

for ARG in "$@"
do
CMDARGS="${CMDARGS} '${ARG}'"
shift 1;
done

## Add to CLASSPATH using CLASSPATH_RELATIVE.
CLASSPATH=""
for ARG in "$CLASSPATH_RELATIVE"
do
DEREFERENCED_CLASSPATH=`ls -1 -L $PATH_TO_ME/$ARG | grep -v ontologyrelease`
for CP_ENTRY in $DEREFERENCED_CLASSPATH
do
if [ $IS_CYGWIN = "TRUE" ]
then
CP_ENTRY="`cygpath --mixed \"$CP_ENTRY\"`"
fi
if [ -z "$CLASSPATH" ]
then
CLASSPATH="$CP_ENTRY"
else
CLASSPATH="$CLASSPATH$PATH_SEP$CP_ENTRY"
fi
done
done

## Add to CLASSPATH using CLASSPATH_LITERAL.
if [ -n "$CLASSPATH_LITERAL" ]
then
for CP_ENTRY in $CLASSPATH_LITERAL
do
if [ -z "$CLASSPATH" ]
then
CLASSPATH="$CP_ENTRY"
else
CLASSPATH="$CLASSPATH$PATH_SEP$CP_ENTRY"
fi
done
fi

## Figure out which java to use.
if [ -z "$JAVAPATH" ]
then
JAVAPATH=`which java`
if [ -z "$JAVAPATH" ]
then
if [ -n "$JAVA_HOME" && -e "$JAVA_HOME" ]
then
JAVAPATH=$JAVA_HOME/bin/java
else
JAVAPATH="java"
fi
fi
fi

## Assemble and run the final command.
CMD="\"$JAVAPATH\" -Xms2048M -DentityExpansionLimit=4086000 -Djava.awt.headless=true -classpath \"$CLASSPATH\" -DlauncherDir=\"$LAUNCHER_DIR\" $JAVAARGS org.geneontology.reasoner.EmrRunner $CMDARGS"

## DEBUG
## Let's see a little of the environment if we declare DEBUG=1.
if [ $DEBUG ]
then
for MYVAR in DEBUG PATH_TO_ME SCRIPTNAME DIRNAME JAVAARGS CMDARGS CLASSPATH_RELATIVE CMD
do
LETVAR=`echo "$"$MYVAR`
TMPVAR=`eval echo $LETVAR`
echo "${MYVAR}: \"${TMPVAR}\""
done
fi

## Run the final command.
if [ $DEBUG ]
then
echo "$CMD"
fi
sh -c "$CMD"
41 changes: 34 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.geneontology</groupId>
<artifactId>expression-materializing-reasoner</artifactId>
<version>0.1.3</version>
<version>0.2.0</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>An OWL reasoner extension for quering over existential restrictions</description>
Expand Down Expand Up @@ -38,7 +38,7 @@
<tag>HEAD</tag>
</scm>

<properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<owlapi.version>4.2.5</owlapi.version>
</properties>
Expand All @@ -51,6 +51,35 @@

<build>
<plugins>
<!-- Build a jar file in bin with all dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>emr</finalName>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<outputDirectory>${project.basedir}/bin</outputDirectory>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<mainClass>org.geneontology.reasoner.EmrRunner</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down Expand Up @@ -150,7 +179,6 @@
<groupId>org.semanticweb.elk</groupId>
<artifactId>elk-owlapi</artifactId>
<version>0.4.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
Expand All @@ -159,10 +187,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.10</version>
<scope>test</scope>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>
</dependencies>

Expand Down
154 changes: 154 additions & 0 deletions src/main/java/org/geneontology/reasoner/EmrRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package org.geneontology.reasoner;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.semanticweb.elk.owlapi.ElkReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.formats.FunctionalSyntaxDocumentFormat;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;

/**
* Command line wrapper
*
* @author cjm
*
*/
public class EmrRunner {

private static Logger LOG = Logger.getLogger(EmrRunner.class);

@Parameter(names = { "-v", "--verbose" }, description = "Level of verbosity")
private Integer verbose = 1;

@Parameter(names = { "-o", "--out"}, description = "output OWL file")
private String outpath;

@Parameter(names = { "-p", "--properties"}, description = "OWL file containing declarations of properties to be used")
private String propOntPath;

@Parameter(names = { "-m", "--method"}, description = "one of: closure, svf")
private String method = "closure";

@Parameter(names = { "-t", "--tabfile"}, description = "output tabfile")
private String outtabfile;

@Parameter(description = "Files")
private List<String> files = new ArrayList<>();

OWLOntologyManager manager;


public static void main(String ... args) throws OWLOntologyCreationException, IOException, OWLOntologyStorageException {
EmrRunner main = new EmrRunner();
new JCommander(main, args);
main.run();
}

public void run() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException {

Logger.getRootLogger().setLevel(Level.INFO);
Logger.getLogger("org.semanticweb.elk").setLevel(Level.OFF);

OWLOntology ontology = this.loadOWL(files.get(0));

OWLOntology propOnt = null;
Set<OWLObjectProperty> props = null;
if (propOntPath != null) {
propOnt = loadOWL(propOntPath);
props = propOnt.getObjectPropertiesInSignature();
LOG.info("PROPS: "+props);
}

ElkReasonerFactory ef = new ElkReasonerFactory();
OWLExtendedReasonerFactory elkEmrFactory;
elkEmrFactory = new ExpressionMaterializingReasonerFactory(ef);
LOG.info("creating extended reasoner");
OWLExtendedReasoner xreasoner = elkEmrFactory.createReasoner(ontology);
LOG.info("Done creating reasoner");

LOG.info("materializing props");
if (props != null) {
for (OWLObjectProperty p : props) {
((ExpressionMaterializingReasoner)xreasoner).materializeExpressions(p);
}
}
else {
LOG.info("materializing ALL props");
((ExpressionMaterializingReasoner)xreasoner).materializeExpressions();
}
LOG.info("DONE materializing props");


OWLOntologyManager mgr = ontology.getOWLOntologyManager();
OWLDataFactory df = mgr.getOWLDataFactory();
OWLOntology newOntology = mgr.createOntology();
newOntology = mgr.createOntology();
if (method.equals("svf")) {
LOG.info("Getting all subsumptions");
Set<OWLSubClassOfAxiom> axioms = ExtenderReasonerUtils.getInferredSubClassOfGCIAxioms(xreasoner, props);
mgr.addAxioms(newOntology, axioms);
if (outtabfile != null) {
ExtenderReasonerUtils.writeInferredSubClassOfGCIAxioms(axioms, outtabfile);
}
}
else {
// assume method is closure
Set<OWLSubClassOfAxiom> axioms = ExtenderReasonerUtils.getInferredSubClassOfAxiomsForNamedClasses(xreasoner, false);
mgr.addAxioms(newOntology, axioms);
}
File outfile = new File(outpath);
LOG.info("Saving to "+outfile);
System.out.println("Saving to "+outfile);
FunctionalSyntaxDocumentFormat fmt = new FunctionalSyntaxDocumentFormat();
mgr.saveOntology(newOntology, fmt, IRI.create(outfile));

}

private OWLOntologyManager getOWLOntologyManager() {
if (manager == null)
manager = OWLManager.createOWLOntologyManager();
return manager;
}
/**
* @param iri
* @return OWL Ontology
* @throws OWLOntologyCreationException
*/
public OWLOntology loadOWL(IRI iri) throws OWLOntologyCreationException {
return getOWLOntologyManager().loadOntology(iri);
}

public OWLOntology loadOWL(String path) throws OWLOntologyCreationException {
File file = new File(path);
return loadOWL(file);
}




/**
* @param file
* @return OWL Ontology
* @throws OWLOntologyCreationException
*/
public OWLOntology loadOWL(File file) throws OWLOntologyCreationException {
IRI iri = IRI.create(file);
return getOWLOntologyManager().loadOntologyFromOntologyDocument(iri);
}
}
Loading