diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java b/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java new file mode 100644 index 0000000..ba6a4d4 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | |||
| 5 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 6 | |||
| 7 | import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; | ||
| 8 | import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom; | ||
| 9 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; | ||
| 10 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 11 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | ||
| 12 | import uk.ac.ox.cs.pagoda.rules.GeneralProgram; | ||
| 13 | import uk.ac.ox.cs.pagoda.tracking.QueryTracker; | ||
| 14 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 15 | |||
| 16 | public class IterativeRefinement { | ||
| 17 | |||
| 18 | private static final int depthLimit = 1; | ||
| 19 | |||
| 20 | QueryRecord m_record; | ||
| 21 | QueryTracker m_tracker; | ||
| 22 | BasicQueryEngine m_trackingStore; | ||
| 23 | QueryRecord[] botQueryRecords; | ||
| 24 | |||
| 25 | int m_depth = 0; | ||
| 26 | |||
| 27 | public IterativeRefinement(QueryRecord queryRecord, QueryTracker tracker, BasicQueryEngine trackingStore, QueryRecord[] botQueryRecords) { | ||
| 28 | m_record = queryRecord; | ||
| 29 | m_tracker = tracker; | ||
| 30 | m_trackingStore = trackingStore; | ||
| 31 | this.botQueryRecords = botQueryRecords; | ||
| 32 | } | ||
| 33 | |||
| 34 | String tempDataFile = "temp.ttl"; | ||
| 35 | |||
| 36 | public OWLOntology extractWithFullABox(String dataset, BottomStrategy upperBottom) { | ||
| 37 | GeneralProgram program; | ||
| 38 | boolean update; | ||
| 39 | while (m_depth < depthLimit) { | ||
| 40 | ++m_depth; | ||
| 41 | program = new GeneralProgram(m_record.getRelevantClauses(), m_record.getRelevantOntology()); | ||
| 42 | |||
| 43 | MultiStageQueryEngine tEngine = new MultiStageQueryEngine("query-tracking", true); | ||
| 44 | try { | ||
| 45 | tEngine.importRDFData("data", dataset); | ||
| 46 | if (tEngine.materialise4SpecificQuery(program, m_record, upperBottom) != 1) { | ||
| 47 | return m_record.getRelevantOntology(); | ||
| 48 | } | ||
| 49 | |||
| 50 | update = m_record.updateUpperBoundAnswers(tEngine.evaluate(m_record.getQueryText())); | ||
| 51 | } finally { | ||
| 52 | tEngine.dispose(); | ||
| 53 | } | ||
| 54 | |||
| 55 | if (m_record.processed()) | ||
| 56 | return null; | ||
| 57 | |||
| 58 | if (!update) break; | ||
| 59 | |||
| 60 | m_record.updateSubID(); | ||
| 61 | m_tracker.extract(m_trackingStore, botQueryRecords, true); | ||
| 62 | } | ||
| 63 | |||
| 64 | return m_record.getRelevantOntology(); | ||
| 65 | } | ||
| 66 | |||
| 67 | public OWLOntology extract(UpperUnaryBottom upperBottom) { | ||
| 68 | GeneralProgram program; | ||
| 69 | boolean update; | ||
| 70 | while (m_depth < depthLimit) { | ||
| 71 | m_record.saveABoxInTurtle(tempDataFile); | ||
| 72 | program = new GeneralProgram(m_record.getRelevantClauses(), m_record.getRelevantOntology()); | ||
| 73 | |||
| 74 | MultiStageQueryEngine tEngine = new MultiStageQueryEngine("query-tracking", true); | ||
| 75 | try { | ||
| 76 | tEngine.importRDFData("fragment abox", tempDataFile); | ||
| 77 | if (tEngine.materialise4SpecificQuery(program, m_record, upperBottom) != 1) { | ||
| 78 | return m_record.getRelevantOntology(); | ||
| 79 | } | ||
| 80 | |||
| 81 | update = m_record.updateUpperBoundAnswers(tEngine.evaluate(m_record.getQueryText())); | ||
| 82 | } finally { | ||
| 83 | tEngine.dispose(); | ||
| 84 | } | ||
| 85 | |||
| 86 | if (m_record.processed()) | ||
| 87 | return null; | ||
| 88 | |||
| 89 | if (!update) break; | ||
| 90 | |||
| 91 | m_record.updateSubID(); | ||
| 92 | m_tracker.extract(m_trackingStore, botQueryRecords, true); | ||
| 93 | } | ||
| 94 | |||
| 95 | return m_record.getRelevantOntology(); | ||
| 96 | } | ||
| 97 | |||
| 98 | public void dispose() { | ||
| 99 | File file = new File(tempDataFile); | ||
| 100 | if (file.exists()) { | ||
| 101 | file.delete(); | ||
| 102 | Utility.logDebug(file.getAbsolutePath() + " is deleted."); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | } | ||
