aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/uk/ac/ox/cs/acqua/implicits
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-15 19:28:02 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-15 19:28:02 +0100
commit2ebd0c8c4fd421dd676004e559b69ed8e5c9bb49 (patch)
tree8ff4094587baa1b7c3eecb533762f123383fe17b /src/main/scala/uk/ac/ox/cs/acqua/implicits
parentd99c80db73e8456c969b262a4b99714bb693bfe0 (diff)
downloadACQuA-2ebd0c8c4fd421dd676004e559b69ed8e5c9bb49.tar.gz
ACQuA-2ebd0c8c4fd421dd676004e559b69ed8e5c9bb49.zip
Finalise implementation of ACQuA query reasoner
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs/acqua/implicits')
-rw-r--r--src/main/scala/uk/ac/ox/cs/acqua/implicits/RSACombAnswerTuples.scala35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/acqua/implicits/RSACombAnswerTuples.scala b/src/main/scala/uk/ac/ox/cs/acqua/implicits/RSACombAnswerTuples.scala
index 4f19e62..d0bba72 100644
--- a/src/main/scala/uk/ac/ox/cs/acqua/implicits/RSACombAnswerTuples.scala
+++ b/src/main/scala/uk/ac/ox/cs/acqua/implicits/RSACombAnswerTuples.scala
@@ -44,20 +44,20 @@ object RSACombAnswerTuples {
44 val answers: ConjunctiveQueryAnswers 44 val answers: ConjunctiveQueryAnswers
45 ) extends AnswerTuples { 45 ) extends AnswerTuples {
46 46
47 /* TODO: this might not be the best choice, since the internal 47 /* Iterator simulated using an index over an [[IndexedSeq]]
48 * iterator in a collection is a single traverse iterator. 48 *
49 * We might be messing with internal state. 49 * This might not be the best solution, but at least it offers
50 * better flexibility than using the internal [[Seq]] iterator.
51 * On top of this, indexed access is guaranteed to be efficient.
50 */ 52 */
51 private var iter = answers.answers.iterator 53 private var iter = answers.answers.map(_._2).toIndexedSeq
54 private var idx: Int = 0
52 55
53 /** Reset the iterator over the answers. 56 /** Reset the iterator over the answers. */
54 * 57 def reset(): Unit = idx = 0
55 * @note this operation is currently not supported.
56 */
57 def reset(): Unit = ???
58 58
59 /** True if the iterator can provide more items. */ 59 /** True if the iterator can provide more items. */
60 def isValid: Boolean = iter.hasNext 60 def isValid: Boolean = idx < iter.length
61 61
62 /** Get arity of answer variables. */ 62 /** Get arity of answer variables. */
63 def getArity: Int = answers.query.answer.length 63 def getArity: Int = answers.query.answer.length
@@ -67,30 +67,31 @@ object RSACombAnswerTuples {
67 answers.query.answer.map(_.getName).toArray 67 answers.query.answer.map(_.getName).toArray
68 68
69 /** Advance iterator state */ 69 /** Advance iterator state */
70 def moveNext(): Unit = { } 70 def moveNext(): Unit = idx += 1
71 71
72 /** Get next [[uk.ac.ox.cs.pagoda.query.AnswerTuple]] from the iterator */ 72 /** Get next [[uk.ac.ox.cs.pagoda.query.AnswerTuple]] from the iterator */
73 def getTuple: AnswerTuple = iter.next() 73 def getTuple: AnswerTuple = iter(idx)
74 74
75 /** Return true if the input tuple is part of this collection. 75 /** Return true if the input tuple is part of this collection.
76 * 76 *
77 * @param tuple the answer to be checked. 77 * @param tuple the answer to be checked.
78 *
79 * @note this operation is currently not supported.
78 */ 80 */
79 def contains(tuple: AnswerTuple): Boolean = 81 def contains(tuple: AnswerTuple): Boolean = ???
80 answers.contains(tuple)
81 82
82 /** Skip one item in the iterator. 83 /** Skip one item in the iterator.
83 * 84 *
84 * @note that the semantic of this method is not clear to the 85 * @note that the semantic of this method is not clear to the
85 * author and the description is just an assumption. 86 * author and the description is just an assumption.
86 */ 87 */
87 def remove(): Unit = iter.next() 88 def remove(): Unit = moveNext()
88 } 89 }
89 90
90 /** Implicit convertion from RSAComb-style answers to [[uk.ac.ox.cs.pagoda.query.AnswerTuple]] */ 91 /** Implicit convertion from RSAComb-style answers to [[uk.ac.ox.cs.pagoda.query.AnswerTuple]] */
91 private implicit def asAnswerTuple( 92 private implicit def asAnswerTuple(
92 answer: (Long,Seq[Resource]) 93 answer: Seq[Resource]
93 ): AnswerTuple = new AnswerTuple(answer._2.map(res => 94 ): AnswerTuple = new AnswerTuple(answer.map(res =>
94 res match { 95 res match {
95 case r: IRI => OldIndividual.create(r.getIRI) 96 case r: IRI => OldIndividual.create(r.getIRI)
96 case r: BlankNode => OldBlankNode.create(r.getID) 97 case r: BlankNode => OldBlankNode.create(r.getID)