diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-07 13:50:50 +0000 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-07 13:50:50 +0000 |
| commit | bbbb61ee13fa258cbed0b502426534afad49b651 (patch) | |
| tree | ae2cbeb271bfedad4948499fc45f4c81cd567ff3 | |
| parent | 920a42b4b55666c582e1d1420336996f4af324fc (diff) | |
| download | RSAComb-bbbb61ee13fa258cbed0b502426534afad49b651.tar.gz RSAComb-bbbb61ee13fa258cbed0b502426534afad49b651.zip | |
Update answers pretty printer
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala | 9 | ||||
| -rw-r--r-- | src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala | 4 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala index 0f830eb..327ae8e 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | package uk.ac.ox.cs.rsacomb.sparql | 1 | package uk.ac.ox.cs.rsacomb.sparql |
| 2 | 2 | ||
| 3 | import tech.oxfordsemantic.jrdfox.logic.expression.{Resource, Variable} | 3 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Resource, Variable} |
| 4 | 4 | ||
| 5 | /** A collections of answers to a query. | 5 | /** A collections of answers to a query. |
| 6 | * | 6 | * |
| @@ -25,7 +25,12 @@ class ConjunctiveQueryAnswers( | |||
| 25 | "NO ANSWER." | 25 | "NO ANSWER." |
| 26 | else { | 26 | else { |
| 27 | val header = variables map (_.getName) mkString "\t" | 27 | val header = variables map (_.getName) mkString "\t" |
| 28 | val body = answers.map(_.mkString("\t")).mkString("\n") | 28 | val body = answers |
| 29 | .map(_.map { | ||
| 30 | case x: IRI => x.getIRI | ||
| 31 | case x => x.toString | ||
| 32 | }.mkString("\t")) | ||
| 33 | .mkString("\n") | ||
| 29 | s"$header\n$body" | 34 | s"$header\n$body" |
| 30 | } | 35 | } |
| 31 | } | 36 | } |
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala index ddc6377..b2319bc 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala | |||
| @@ -43,11 +43,11 @@ class ConjunctiveQueryAnswerSpec extends AnyFlatSpec with Matchers { | |||
| 43 | import ConjunctiveQueryAnswerSpec._ | 43 | import ConjunctiveQueryAnswerSpec._ |
| 44 | 44 | ||
| 45 | "A conjunctive query" should "print an header and a single line if it has a single answer" in { | 45 | "A conjunctive query" should "print an header and a single line if it has a single answer" in { |
| 46 | oneAnswer.toString shouldBe s"X\tY\tZ\n$iri1\t$iri2\t$iri3" | 46 | oneAnswer.toString shouldBe s"X\tY\tZ\n${iri1.getIRI}\t${iri2.getIRI}\t${iri3.getIRI}" |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | it should "print a header and multiple answers on multiple lines" in { | 49 | it should "print a header and multiple answers on multiple lines" in { |
| 50 | multipleAnswers.toString shouldBe s"Y\tZ\n$iri1\t$iri1\n$iri1\t$iri2\n$iri1\t$iri3" | 50 | multipleAnswers.toString shouldBe s"Y\tZ\n${iri1.getIRI}\t${iri1.getIRI}\n${iri1.getIRI}\t${iri2.getIRI}\n${iri1.getIRI}\t${iri3.getIRI}" |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | it should "print a special \"NO ANSWER.\" string when it has no answer" in { | 53 | it should "print a special \"NO ANSWER.\" string when it has no answer" in { |
