diff options
Diffstat (limited to 'src/org/semanticweb/karma2/MyKarma.java')
| -rw-r--r-- | src/org/semanticweb/karma2/MyKarma.java | 64 |
1 files changed, 25 insertions, 39 deletions
diff --git a/src/org/semanticweb/karma2/MyKarma.java b/src/org/semanticweb/karma2/MyKarma.java index 60938df..b2b4352 100644 --- a/src/org/semanticweb/karma2/MyKarma.java +++ b/src/org/semanticweb/karma2/MyKarma.java | |||
| @@ -121,30 +121,19 @@ public class MyKarma { | |||
| 121 | private Set<AnswerTuple> answerCQ_multiThread(ConjunctiveQuery q, AnswerTuples soundAnswerTuples, boolean isGround) { | 121 | private Set<AnswerTuple> answerCQ_multiThread(ConjunctiveQuery q, AnswerTuples soundAnswerTuples, boolean isGround) { |
| 122 | Set<Future<AnswerTuple>> set = new HashSet<Future<AnswerTuple>>(); | 122 | Set<Future<AnswerTuple>> set = new HashSet<Future<AnswerTuple>>(); |
| 123 | ExtendedConjunctiveQuery qext = ExtendedConjunctiveQuery.computeExtension(q); | 123 | ExtendedConjunctiveQuery qext = ExtendedConjunctiveQuery.computeExtension(q); |
| 124 | TupleIterator tupleIterator; | 124 | TupleIterator tupleIterator = null; |
| 125 | ExecutorService es = null; | ||
| 125 | try { | 126 | try { |
| 126 | tupleIterator = store.compileQuery(qext.toString(), prefixes, parameters); | 127 | tupleIterator = store.compileQuery(qext.toString(), prefixes, parameters); |
| 127 | } catch (JRDFStoreException e) { | 128 | es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); |
| 128 | e.printStackTrace(); | 129 | AnswerTuple tuple; |
| 129 | return null; | 130 | for (long multi = tupleIterator.open(); multi != 0; multi = tupleIterator.getNext()) { |
| 130 | } | 131 | Map<Term, GroundTerm> match = new HashMap<Term, GroundTerm>(); |
| 131 | ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); | 132 | for (int i = 0; i < qext.getNumberOfAnswerTerms(); i++) { |
| 132 | AnswerTuple tuple; | 133 | match.put(qext.getAnswerTerm(i), tupleIterator.getGroundTerm(i)); |
| 133 | try { | ||
| 134 | try { | ||
| 135 | for (long multi = tupleIterator.open(); multi != 0; multi = tupleIterator.getNext()) { | ||
| 136 | Map<Term, GroundTerm> match = new HashMap<Term, GroundTerm>(); | ||
| 137 | for (int i = 0; i < qext.getNumberOfAnswerTerms(); i++) { | ||
| 138 | match.put(qext.getAnswerTerm(i), tupleIterator.getGroundTerm(i)); | ||
| 139 | } | ||
| 140 | if ((tuple = contains(qext, soundAnswerTuples, match)) != null) | ||
| 141 | set.add(es.submit(new Spurious(qext, match, tuple, isGround))); | ||
| 142 | } | 134 | } |
| 143 | } catch (JRDFStoreException e) { | 135 | if ((tuple = contains(qext, soundAnswerTuples, match)) != null) |
| 144 | e.printStackTrace(); | 136 | set.add(es.submit(new Spurious(qext, match, tuple, isGround))); |
| 145 | return null; | ||
| 146 | } finally { | ||
| 147 | tupleIterator.dispose(); | ||
| 148 | } | 137 | } |
| 149 | Set<AnswerTuple> result = new HashSet<AnswerTuple>(set.size()); | 138 | Set<AnswerTuple> result = new HashSet<AnswerTuple>(set.size()); |
| 150 | while(!set.isEmpty()) { | 139 | while(!set.isEmpty()) { |
| @@ -166,28 +155,28 @@ public class MyKarma { | |||
| 166 | } | 155 | } |
| 167 | } | 156 | } |
| 168 | return result; | 157 | return result; |
| 158 | } catch (JRDFStoreException e1) { | ||
| 159 | e1.printStackTrace(); | ||
| 160 | return null; | ||
| 169 | } finally { | 161 | } finally { |
| 170 | es.shutdown(); | 162 | if (tupleIterator != null) tupleIterator.dispose(); |
| 163 | if (es != null) es.shutdown(); | ||
| 171 | } | 164 | } |
| 172 | } | 165 | } |
| 173 | 166 | ||
| 174 | private Set<AnswerTuple> answerCQ_singleThread(ConjunctiveQuery q, AnswerTuples soundAnswerTuples, boolean isGround) { | 167 | private Set<AnswerTuple> answerCQ_singleThread(ConjunctiveQuery q, AnswerTuples soundAnswerTuples, boolean isGround) { |
| 175 | ExtendedConjunctiveQuery qext = ExtendedConjunctiveQuery.computeExtension(q); | 168 | ExtendedConjunctiveQuery qext = ExtendedConjunctiveQuery.computeExtension(q); |
| 176 | TupleIterator tupleIterator; | ||
| 177 | try { | ||
| 178 | tupleIterator = store.compileQuery(qext.toString(), prefixes, parameters); | ||
| 179 | } catch (JRDFStoreException e) { | ||
| 180 | e.printStackTrace(); | ||
| 181 | return null; | ||
| 182 | } | ||
| 183 | |||
| 184 | boolean useBushyValue = parameters.m_useBushy, allAnswersInRootValue = parameters.m_allAnswersInRoot; | 169 | boolean useBushyValue = parameters.m_useBushy, allAnswersInRootValue = parameters.m_allAnswersInRoot; |
| 185 | parameters.m_useBushy = false; | ||
| 186 | parameters.m_allAnswersInRoot = false; | ||
| 187 | try { | ||
| 188 | Set<AnswerTuple> result = new HashSet<AnswerTuple>(); | 170 | Set<AnswerTuple> result = new HashSet<AnswerTuple>(); |
| 189 | AnswerTuple tuple; | 171 | |
| 172 | TupleIterator tupleIterator = null; | ||
| 190 | try { | 173 | try { |
| 174 | tupleIterator = store.compileQuery(qext.toString(), prefixes, parameters); | ||
| 175 | parameters.m_useBushy = false; | ||
| 176 | parameters.m_allAnswersInRoot = false; | ||
| 177 | |||
| 178 | AnswerTuple tuple; | ||
| 179 | |||
| 191 | for (long multi = tupleIterator.open(); multi != 0; multi = tupleIterator.getNext()) { | 180 | for (long multi = tupleIterator.open(); multi != 0; multi = tupleIterator.getNext()) { |
| 192 | Map<Term, GroundTerm> match = new HashMap<Term, GroundTerm>(); | 181 | Map<Term, GroundTerm> match = new HashMap<Term, GroundTerm>(); |
| 193 | for (int i = 0; i < qext.getNumberOfAnswerTerms(); i++) { | 182 | for (int i = 0; i < qext.getNumberOfAnswerTerms(); i++) { |
| @@ -200,14 +189,11 @@ public class MyKarma { | |||
| 200 | e.printStackTrace(); | 189 | e.printStackTrace(); |
| 201 | return null; | 190 | return null; |
| 202 | } finally { | 191 | } finally { |
| 203 | tupleIterator.dispose(); | 192 | if (tupleIterator != null) tupleIterator.dispose(); |
| 204 | } | ||
| 205 | return result; | ||
| 206 | } finally { | ||
| 207 | parameters.m_useBushy = useBushyValue; | 193 | parameters.m_useBushy = useBushyValue; |
| 208 | parameters.m_allAnswersInRoot = allAnswersInRootValue; | 194 | parameters.m_allAnswersInRoot = allAnswersInRootValue; |
| 209 | } | 195 | } |
| 210 | 196 | return result; | |
| 211 | } | 197 | } |
| 212 | 198 | ||
| 213 | private AnswerTuple contains(ExtendedConjunctiveQuery qext, AnswerTuples answerTuples, Map<Term, GroundTerm> match) { | 199 | private AnswerTuple contains(ExtendedConjunctiveQuery qext, AnswerTuples answerTuples, Map<Term, GroundTerm> match) { |
