From 17bd9beaf7f358a44e5bf36a5855fe6727d506dc Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Tue, 10 May 2022 18:17:06 +0100 Subject: [pagoda] Move project to Scala This commit includes a few changes: - The repository still uses Maven to manage dependency but it is now a Scala project. - The code has been ported from OWLAPI 3.4.10 to 5.1.20 - A proof of concept program using both RSAComb and PAGOdA has been added. --- test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java | 199 ----------------------- test/uk/ac/ox/cs/hermit/HermitTester.java | 55 ------- test/uk/ac/ox/cs/hermit/JAIR_HermiT.java | 129 --------------- 3 files changed, 383 deletions(-) delete mode 100644 test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java delete mode 100644 test/uk/ac/ox/cs/hermit/HermitTester.java delete mode 100644 test/uk/ac/ox/cs/hermit/JAIR_HermiT.java (limited to 'test/uk/ac/ox/cs/hermit') diff --git a/test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java b/test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java deleted file mode 100644 index 008fcb2..0000000 --- a/test/uk/ac/ox/cs/hermit/HermitQueryReasoner.java +++ /dev/null @@ -1,199 +0,0 @@ -package uk.ac.ox.cs.hermit; - -import org.semanticweb.HermiT.Reasoner; -import org.semanticweb.HermiT.model.Atom; -import org.semanticweb.HermiT.model.AtomicRole; -import org.semanticweb.owlapi.model.*; -import org.semanticweb.owlapi.reasoner.Node; -import uk.ac.ox.cs.pagoda.owl.OWLHelper; -import uk.ac.ox.cs.pagoda.owl.QueryRoller; -import uk.ac.ox.cs.pagoda.query.QueryManager; -import uk.ac.ox.cs.pagoda.query.QueryRecord; -import uk.ac.ox.cs.pagoda.util.Timer; - -import java.io.*; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.*; - -public class HermitQueryReasoner { - - public static void main(String... args) throws FileNotFoundException, OWLOntologyCreationException, OWLOntologyStorageException { - if (args.length == 0) { -// args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/lubm/lubm1_merged.owl", null, PagodaTester.lubm_query}; -// args = new String[] {"/users/yzhou/ontologies/uobm/uobm1_merged.owl", null, "/users/yzhou/ontologies/uobm/queries/standard.sparql"}; -// args = new String[] {"/users/yzhou/ontologies/fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", null, "/users/yzhou/ontologies/fly/queries/fly.sparql"}; -// args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/npd/npd-all-minus-datatype.owl", "/media/krr-nas-share/Yujiao/ontologies/npd/data/npd-data-dump-minus-datatype-new.ttl", "/users/yzhou/ontologies/npd/queries/atomic.sparql"}; -// args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/npd/npd-all.owl", "/media/krr-nas-share/Yujiao/ontologies/npd/data/npd-data-dump-processed.ttl", "/users/yzhou/ontologies/npd/queries/atomic.sparql"}; -// args = new String[] {PagodaTester.dbpedia_tbox, PagodaTester.dbpedia_abox, PagodaTester.dbpedia_query}; -// args = new String[] {"/users/yzhou/ontologies/answersCorrectness/unsatisfiable.owl", null, "/users/yzhou/ontologies/answersCorrectness/unsatisfiable_queries.sparql"}; - -// args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/cco-processed-noDPR-noDPD.ttl", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/graph sampling/sample_100.nt", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/chembl/queries/atomic_one_filtered.sparql", "../answersCorrectness-share/results/chembl/hermit_1p"}; - args = - new String[]{"/users/yzhou/temp/uniprot_debug/core-processed-noDis.owl", "/users/yzhou/temp/uniprot_debug/sample_1_removed.nt", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/queries/atomic_one.sparql", "../answersCorrectness-share/results/uniprot/hermit_1p"}; - } -// args = new String[] {"imported.owl", "", "/media/krr-nas-share/Yujiao/ontologies/bio2rdf/uniprot/queries/atomic_one.sparql", "../answersCorrectness-share/results/uniprot/hermit_1p"}; } - - - PrintStream ps = args.length < 4 ? null : new PrintStream(new File(args[3])); - for (int i = 0; i < args.length; ++i) { - if (args[i] == null || args[i].equalsIgnoreCase("null")) args[i] = ""; - System.out.println("Argument " + i + ": " + args[i]); - } - -// PrintStream ps = null; // new PrintStream(new File("../answersCorrectness-share/results/reactome/ ")); - if (ps != null) System.setOut(ps); - - Timer t = new Timer(); - OWLOntology onto = OWLHelper.loadOntology(args[0]); - OWLOntologyManager man = onto.getOWLOntologyManager(); - - OWLDatatype date = man.getOWLDataFactory().getOWLDatatype(IRI.create("http://www.w3.org/2001/XMLSchema#date")); - - if (onto.containsEntityInSignature(date)) { - for (OWLOntology o: onto.getImportsClosure()) - for (OWLAxiom axiom: o.getAxioms()) - if (axiom.getDatatypesInSignature().contains(date)) { - System.out.println("The axiom: " + axiom + " is being ingored. "); - man.removeAxiom(onto, axiom); - } - man.saveOntology(onto, new FileOutputStream(args[0] = "tbox_hermit.owl")); - man.removeOntology(onto); - onto = OWLHelper.loadOntology(man, args[0]); - System.out.println("TBox processed in " + t.duration()); - } - - try { - onto = OWLHelper.getImportedOntology(onto, args[1]); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println("Ontology loaded in " + t.duration()); - System.out.println("ABox axioms:" + onto.getABoxAxioms(true).size()); -// for (OWLOntology o: onto.getImportsClosure()) -// for (OWLAxiom axiom: o.getAxioms()) -// System.out.println(axiom); - - Reasoner hermit = new Reasoner(onto); - if (!hermit.isConsistent()) { - System.out.println("The ontology is inconsistent."); - return ; - } - System.out.println("Preprocessing DONE in " + t.duration()); - -// System.out.println(hermit.isConsistent()); - - QueryManager queryManager = new QueryManager(); - QueryRoller roller = new QueryRoller(onto.getOWLOntologyManager().getOWLDataFactory()); - int failedCounter = 0; - Timer total = new Timer(); - for (QueryRecord record: queryManager.collectQueryRecords(args[2])) { - if (Integer.parseInt(record.getQueryID()) < 10) continue; - if (total.duration() > 18000) { - System.out.println("Time out 5h."); - return ; - } - System.out.println("--------------------- Query " + record.getQueryID() + " -----------------------"); - System.out.println(record.getQueryText()); - ExecutorService exec = Executors.newSingleThreadExecutor(); - try { - Future succ = exec.submit(new QueryThread(record, onto, hermit, roller)); - try { - try { - if (record.getQueryID().equals("1")) - System.out.println(succ.get(60, TimeUnit.MINUTES)); - else - System.out.println(succ.get(20, TimeUnit.MINUTES)); - } catch (InterruptedException e) { -// e.printStackTrace(); - } catch (ExecutionException e) { -// e.printStackTrace(); - } catch (TimeoutException e) { -// e.printStackTrace(); - } - } finally { - if (succ.cancel(true)) { - System.out.println("Trying to cancel the current query thread " + (++failedCounter)); - } - } - } finally { - exec.shutdownNow(); - } - } - - if (ps != null) ps.close(); - System.exit(0); - } - -} - -class QueryThread implements Callable { - - QueryRecord record; - OWLOntology onto; - Reasoner hermit; - QueryRoller roller; - - public QueryThread(QueryRecord record2, OWLOntology onto2, Reasoner hermit2, QueryRoller roller2) { - record = record2; onto = onto2; hermit = hermit2; roller = roller2; - } - - @Override - public Boolean call() throws Exception { - Set answers = new HashSet(); - Timer t = new Timer(); - if (record.getDistinguishedVariables().length > 1) { - if (record.getDistinguishedVariables().length == 2 && record.getClause().getBodyLength() == 1) { - dealWithAtomicBinaryQuery(record.getClause().getBodyAtom(0), answers); - System.out.println("Query " + record.getQueryID() + " The number of answers: " + answers.size()); - System.out.println("Query " + record.getQueryID() + " Total time: " + t.duration()); - } - else { - System.out.println("Query " + record.getQueryID() + " The number of answers: Query cannot be processsed."); - System.out.println("Query " + record.getQueryID() + " Total time: Query cannot be processsed."); - } - return false; - } - - OWLClassExpression exp = null; - - try { - exp = roller.rollUp(record.getClause(), record.getAnswerVariables()[0]); - } catch (Exception e) { - System.out.println("Query " + record.getQueryID() + " The number of answers: Query cannot be processsed."); - System.out.println("Query " + record.getQueryID() + " Total time: Query cannot be processsed."); - return false; - } - System.out.println(exp); - for (Node node: hermit.getInstances(exp, false)) { - for (OWLIndividual ind: node.getEntities()) { - answers.add(ind.toStringID()); - } - } - System.out.println("Query " + record.getQueryID() + " The number of answers: " + answers.size()); - System.out.println("Query " + record.getQueryID() + " Total time: " + t.duration()); - return true; - } - - private void dealWithAtomicBinaryQuery(Atom bodyAtom, Set answers) { - StringBuilder sb = new StringBuilder(); - OWLDataFactory f = onto.getOWLOntologyManager().getOWLDataFactory(); - OWLObjectProperty p = f.getOWLObjectProperty(IRI.create(((AtomicRole) bodyAtom.getDLPredicate()).getIRI())); - for (Node sub: hermit.getInstances(f.getOWLObjectMinCardinality(1, p), false)) { - for (Node obj: hermit.getObjectPropertyValues(sub.getRepresentativeElement(), p)) { - for (OWLNamedIndividual subInd: sub.getEntities()) { - sb.setLength(0); - sb.append(subInd.toString()).append(" "); - int len = sb.length(); - for (OWLNamedIndividual objInd: obj.getEntities()) { - sb.setLength(len); - sb.append(objInd.toString()); - answers.add(sb.toString()); - } - } - } - } - } - -} - diff --git a/test/uk/ac/ox/cs/hermit/HermitTester.java b/test/uk/ac/ox/cs/hermit/HermitTester.java deleted file mode 100644 index dc70284..0000000 --- a/test/uk/ac/ox/cs/hermit/HermitTester.java +++ /dev/null @@ -1,55 +0,0 @@ -package uk.ac.ox.cs.hermit; - -import org.semanticweb.HermiT.Configuration; -import org.semanticweb.HermiT.Reasoner; -import org.semanticweb.HermiT.model.Atom; -import org.semanticweb.HermiT.model.DLClause; -import org.semanticweb.HermiT.model.DLOntology; -import org.semanticweb.HermiT.structural.OWLClausification; -import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLAxiom; -import org.semanticweb.owlapi.model.OWLClass; -import org.semanticweb.owlapi.model.OWLDataFactory; -import org.semanticweb.owlapi.model.OWLNamedIndividual; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.reasoner.Node; - -import uk.ac.ox.cs.pagoda.owl.OWLHelper; - -public class HermitTester { - - public static void main(String[] args) { - OWLOntology onto = OWLHelper.loadOntology("imported.owl"); - Reasoner hermit = new Reasoner(onto); - OWLDataFactory f = onto.getOWLOntologyManager().getOWLDataFactory(); - OWLClass concept = f.getOWLClass(IRI.create("http://semantics.crl.ibm.com/univ-bench-dl.owl#Query12")); - - for (OWLOntology o: onto.getImportsClosure()) { - System.out.println(o.containsEntityInSignature(concept)); - for (OWLAxiom axiom: o.getAxioms()) - if (axiom.getClassesInSignature().contains(concept)) - System.out.println(axiom); - } - - for (Node node : hermit.getInstances(concept, false)) - for (OWLNamedIndividual i: node.getEntities()) { - System.out.println(i.toStringID()); - } - -// clausifierTest(); - } - - @SuppressWarnings("unused") - private static void clausifierTest() { - OWLOntology onto = OWLHelper.loadOntology("/users/yzhou/ontologies/travel.owl"); - OWLClausification clausifier = new OWLClausification(new Configuration()); - DLOntology dlOntology = (DLOntology)clausifier.preprocessAndClausify(onto, null)[1]; - - for (DLClause clause: dlOntology.getDLClauses()) - System.out.println(clause); - for (Atom atom : dlOntology.getPositiveFacts()) - System.out.println(atom); - - } - -} diff --git a/test/uk/ac/ox/cs/hermit/JAIR_HermiT.java b/test/uk/ac/ox/cs/hermit/JAIR_HermiT.java deleted file mode 100644 index 72e7af8..0000000 --- a/test/uk/ac/ox/cs/hermit/JAIR_HermiT.java +++ /dev/null @@ -1,129 +0,0 @@ -package uk.ac.ox.cs.hermit; - -import org.junit.Test; -import uk.ac.ox.cs.pagoda.util.TestUtil; - -public class JAIR_HermiT { - - @Test - public void lubm1() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - String[] args = new String[] { - TestUtil.combinePaths(ontoDir, "lubm/univ-bench.owl"), - TestUtil.combinePaths(ontoDir, "lubm/data/lubm1_owl"), - TestUtil.combinePaths(ontoDir, "lubm/queries/answersCorrectness.sparql") -// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/hermit" - }; - HermitQueryReasoner.main(args); - } - - @Test - public void lubm1_rolledUp() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - String[] args = new String[] { - "/home/yzhou/backup/20141212/univ-bench-queries.owl", - TestUtil.combinePaths(ontoDir, "lubm/data/lubm1_owl"), - TestUtil.combinePaths(ontoDir, "lubm/queries/atomic_lubm.sparql") -// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/lubm1/hermit_rolledUp" - }; - HermitQueryReasoner.main(args); - } - - @Test - public void uobm1() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - String[] args = new String[] { - TestUtil.combinePaths(ontoDir, "uobm/univ-bench-dl.owl"), - TestUtil.combinePaths(ontoDir, "uobm/data/uobm1_owl_withDeclaration"), - TestUtil.combinePaths(ontoDir, "uobm/queries/standard.sparql") -// , "hermit_uobm1.out" -// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/hermit" - }; - HermitQueryReasoner.main(args); - } - - @Test - public void uobm1_rolledUp() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - String[] args = new String[] { - "/home/yzhou/backup/20141212/univ-bench-dl-queries.owl", - TestUtil.combinePaths(ontoDir, "uobm/data/uobm1_owl_withDeclaration"), - TestUtil.combinePaths(ontoDir, "uobm/queries/atomic_uobm.sparql") - , "hermit_uobm1_rolledUp.out" -// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uobm1/hermit_rolledUp" - }; - HermitQueryReasoner.main(args); - } - - @Test - public void fly_rolledUp() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - HermitQueryReasoner.main( - TestUtil.combinePaths(ontoDir, "fly/fly-all-in-one_rolledUp.owl"), -// TestUtil.combinePaths(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl", - null, - TestUtil.combinePaths(ontoDir, "fly/queries/fly_atomic.sparql") - , "hermit_fly.out" - ); - } - - @Test - public void npd() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - HermitQueryReasoner.main( - TestUtil.combinePaths(ontoDir, "npd/npd-all-minus-datatype.owl"), - TestUtil.combinePaths(ontoDir, "npd/data/npd-data-dump-minus-datatype-new.ttl"), - TestUtil.combinePaths(ontoDir, "npd/queries/atomic_ground.sparql") - , "hermit_npd.out" -// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/npd/hermit" - ); - } - - @Test - public void dbpedia() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - HermitQueryReasoner.main( - TestUtil.combinePaths(ontoDir, "dbpedia/integratedOntology-all-in-one-minus-datatype.owl"), - TestUtil.combinePaths(ontoDir, "dbpedia/data/dbpedia-minus-datatype-new.ttl"), - TestUtil.combinePaths(ontoDir, "dbpedia/queries/atomic_ground.sparql") - , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/dbpedia/hermit" - ); - } - - @Test - public void reactome() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - HermitQueryReasoner.main( - TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/biopax-level3-processed.owl"), - TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/graph sampling/reactome_sample_10.ttl"), - TestUtil.combinePaths(ontoDir, "bio2rdf/reactome/queries/atomic_ground.sparql") - , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/reactome/hermit_10p" - ); - } - - @Test - public void chembl() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - HermitQueryReasoner.main( - TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/cco-noDPR.ttl"), -// null, - TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/graph sampling/sample_1.nt"), - TestUtil.combinePaths(ontoDir, "bio2rdf/chembl/queries/atomic_ground.sparql") - , "hermit_chembl.out" -// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/chembl/hermit_1p" - ); - } - - @Test - public void uniprot() throws Exception { - String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); - HermitQueryReasoner.main( - TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/core-sat.owl"), - TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/graph sampling/sample_1.nt"), - TestUtil.combinePaths(ontoDir, "bio2rdf/uniprot/queries/atomic_ground.sparql") - , "hermit_uniprot.out" -// , "/home/yzhou/java-workspace/answersCorrectness-share/results_new/uniprot/hermit_1p" - ); - } - -} -- cgit v1.2.3