diff options
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/summary/SummaryTester.java')
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/summary/SummaryTester.java | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/summary/SummaryTester.java b/test/uk/ac/ox/cs/pagoda/summary/SummaryTester.java deleted file mode 100644 index 18b6090..0000000 --- a/test/uk/ac/ox/cs/pagoda/summary/SummaryTester.java +++ /dev/null | |||
| @@ -1,139 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.summary; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | import java.io.FileNotFoundException; | ||
| 5 | import java.io.FileOutputStream; | ||
| 6 | import java.io.IOException; | ||
| 7 | import java.util.Scanner; | ||
| 8 | |||
| 9 | import org.semanticweb.HermiT.Reasoner; | ||
| 10 | import org.semanticweb.owlapi.model.AxiomType; | ||
| 11 | import org.semanticweb.owlapi.model.IRI; | ||
| 12 | import org.semanticweb.owlapi.model.OWLClassExpression; | ||
| 13 | import org.semanticweb.owlapi.model.OWLDataFactory; | ||
| 14 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 15 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| 16 | import org.semanticweb.owlapi.model.OWLOntologyStorageException; | ||
| 17 | |||
| 18 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | ||
| 19 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 20 | import uk.ac.ox.cs.pagoda.owl.QueryRoller; | ||
| 21 | import uk.ac.ox.cs.pagoda.query.QueryManager; | ||
| 22 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 23 | import uk.ac.ox.cs.pagoda.summary.Summary; | ||
| 24 | |||
| 25 | public class SummaryTester { | ||
| 26 | |||
| 27 | static String FILE_BREAK = System.getProperty("file.separator"); | ||
| 28 | static String LINE_BREAK = System.getProperty("line.separator"); | ||
| 29 | |||
| 30 | public static void main(String[] args) throws Exception { | ||
| 31 | // String arg = "ontologies/claros/all-in-one-manually.owl"; | ||
| 32 | // String arg = "ontologies/claros/Claros.owl ontologies/claros/data"; | ||
| 33 | String arg = "../uobmGenerator/univ-bench-dl.owl " + | ||
| 34 | "../uobmGenerator/uobm1 " + //"a " + | ||
| 35 | "ontologies/uobm/queries/uobm_standard_less.sparql"; | ||
| 36 | |||
| 37 | testSummarisedUpperBound(arg.split("\\ ")); | ||
| 38 | } | ||
| 39 | |||
| 40 | /** | ||
| 41 | * args[0] ontology file location | ||
| 42 | * args[1] data directory | ||
| 43 | * args[2] sparql query file location | ||
| 44 | * | ||
| 45 | * @param args | ||
| 46 | * @throws OWLOntologyCreationException | ||
| 47 | * @throws FileNotFoundException | ||
| 48 | * @throws OWLOntologyStorageException | ||
| 49 | */ | ||
| 50 | public static void testSummarisedUpperBound(String[] args) throws OWLOntologyCreationException, FileNotFoundException, OWLOntologyStorageException { | ||
| 51 | OWLOntology onto = OWLHelper.loadOntology(args[0]); | ||
| 52 | try { | ||
| 53 | onto = OWLHelper.getImportedOntology(onto, args[1]); | ||
| 54 | } catch (IOException e) { | ||
| 55 | e.printStackTrace(); | ||
| 56 | } | ||
| 57 | |||
| 58 | Summary sum = testSummary(onto); | ||
| 59 | System.out.println("Summarisation Done."); | ||
| 60 | |||
| 61 | System.out.println(args[2]); | ||
| 62 | Scanner scanner = new Scanner(new File(args[2])); | ||
| 63 | OWLOntology summary = sum.getSummary(); | ||
| 64 | OWLDataFactory factory = summary.getOWLOntologyManager().getOWLDataFactory(); | ||
| 65 | QueryRoller r = new QueryRoller(factory); | ||
| 66 | OWLClassExpression summarisedQueryExp; | ||
| 67 | Reasoner reasoner = new Reasoner(summary); | ||
| 68 | QueryManager queryManager = new QueryManager(); | ||
| 69 | int upperBoundCounter, queryID = 0; | ||
| 70 | StringBuilder queryText = new StringBuilder(); | ||
| 71 | String[] vars; | ||
| 72 | |||
| 73 | for (String line; ; ) { | ||
| 74 | queryText.setLength(0); | ||
| 75 | while (scanner.hasNextLine() && (line = scanner.nextLine()) != null && !line.startsWith("^[query")); | ||
| 76 | if (!scanner.hasNextLine()) break; | ||
| 77 | |||
| 78 | while (scanner.hasNextLine() && (line = scanner.nextLine()) != null && !line.isEmpty()) | ||
| 79 | queryText.append(line).append(LINE_BREAK); | ||
| 80 | if (!scanner.hasNextLine()) break; | ||
| 81 | |||
| 82 | System.out.println("------------ starting computing for Query " + ++queryID + "------------"); | ||
| 83 | |||
| 84 | System.out.println(queryText); | ||
| 85 | |||
| 86 | QueryRecord record = queryManager.create(queryText.toString(), queryID); | ||
| 87 | vars = record.getAnswerVariables(); | ||
| 88 | if (vars.length > 1) { | ||
| 89 | System.out.println("The query cannot be processed by HermiT ... More than one answer variable"); | ||
| 90 | continue; | ||
| 91 | } | ||
| 92 | |||
| 93 | summarisedQueryExp = r.rollUp(DLClauseHelper.getQuery(sum.getSummary(record), null), vars[0]); | ||
| 94 | |||
| 95 | upperBoundCounter = 0; | ||
| 96 | for (String representative: sum.getRepresentatives()) | ||
| 97 | if (reasoner.isEntailed(factory.getOWLClassAssertionAxiom(summarisedQueryExp, factory.getOWLNamedIndividual(IRI.create(representative))))) { | ||
| 98 | upperBoundCounter += sum.getGroup(representative).size(); | ||
| 99 | } | ||
| 100 | |||
| 101 | System.out.println("There are " + upperBoundCounter + " individual(s) in the upper bound computed by summary."); | ||
| 102 | } | ||
| 103 | scanner.close(); | ||
| 104 | } | ||
| 105 | |||
| 106 | public static Summary testSummary(OWLOntology ontology) throws OWLOntologyCreationException, FileNotFoundException { | ||
| 107 | Summary sum = new Summary(ontology); | ||
| 108 | |||
| 109 | System.out.println("original ontology data: "); | ||
| 110 | outputStatistics(ontology); | ||
| 111 | |||
| 112 | OWLOntology summary = sum.getSummary(); | ||
| 113 | |||
| 114 | System.out.println("summarised ontology data: "); | ||
| 115 | outputStatistics(summary); | ||
| 116 | |||
| 117 | try { | ||
| 118 | FileOutputStream out = new FileOutputStream("summary.owl"); | ||
| 119 | summary.getOWLOntologyManager().saveOntology(summary, out); | ||
| 120 | out.close(); | ||
| 121 | } catch (OWLOntologyStorageException e) { | ||
| 122 | e.printStackTrace(); | ||
| 123 | } catch (IOException e) { | ||
| 124 | // TODO Auto-generated catch block | ||
| 125 | e.printStackTrace(); | ||
| 126 | } | ||
| 127 | |||
| 128 | return sum; | ||
| 129 | } | ||
| 130 | |||
| 131 | private static void outputStatistics(OWLOntology onto) { | ||
| 132 | System.out.println("TBox: " + onto.getTBoxAxioms(true).size() + | ||
| 133 | "\tRBox: " + onto.getRBoxAxioms(true).size() + | ||
| 134 | "\tABox: " + onto.getABoxAxioms(true).size()); | ||
| 135 | System.out.println("Class Assertions: " + onto.getAxiomCount(AxiomType.CLASS_ASSERTION, true) + | ||
| 136 | "\tObject Property Assertions: " + onto.getAxiomCount(AxiomType.OBJECT_PROPERTY_ASSERTION, true)); | ||
| 137 | } | ||
| 138 | |||
| 139 | } | ||
