Skip to content

Commit 6900702

Browse files
committed
Repaired small bug in shape maps
1 parent 6b28768 commit 6900702

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

modules/shapeMaps/src/main/scala/es/weso/shapeMaps/Parser.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ object Parser extends LazyLogging {
3434
val s = removeBOM(str)
3535
val reader: JavaReader =
3636
new InputStreamReader(new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8)))
37-
val r = parseSchemaReader(reader, base, nodesPrefixMap, shapesPrefixMap)
38-
r
37+
parseSchemaReader(reader, base, nodesPrefixMap, shapesPrefixMap)
3938
}
4039

4140
def parseSchemaReader(

modules/shapeMaps/src/main/scala/es/weso/shapeMaps/ShapeMap.scala

+9-5
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ object ShapeMap {
9393
queryMap <- {
9494
Parser.parse(str, base, rdf.getPrefixMap, shapesPrefixMap)
9595
}
96-
fixMap <- fixShapeMap(queryMap, rdf, rdf.getPrefixMap, shapesPrefixMap)
97-
} yield ResultShapeMap(fixMap.shapeMap, rdf.getPrefixMap, shapesPrefixMap)
98-
96+
fixMap <- {
97+
fixShapeMap(queryMap, rdf, rdf.getPrefixMap, shapesPrefixMap) }
98+
} yield {
99+
ResultShapeMap(fixMap.shapeMap, rdf.getPrefixMap, shapesPrefixMap)
100+
}
99101
/**
100102
* Resolve triple patterns according to an RDF
101103
*/
@@ -116,10 +118,12 @@ object ShapeMap {
116118
current: Either[String, FixedShapeMap]
117119
): Either[String, FixedShapeMap] = for {
118120
fixed <- current
119-
newShapeMap <- fixed.addAssociation(Association(RDFNodeSelector(node), a.shape))
121+
newShapeMap <- fixed.addAssociation(Association(RDFNodeSelector(node), a.shape, a.info))
120122
} yield newShapeMap
121123

122-
def combine(a: Association, current: Either[String, FixedShapeMap]): Either[String, FixedShapeMap] = {
124+
def combine(a: Association,
125+
current: Either[String, FixedShapeMap]
126+
): Either[String, FixedShapeMap] = {
123127
for {
124128
nodes <- a.node.select(rdf)
125129
r <- nodes.foldRight(current)(addNode(a))

modules/shapeMaps/src/test/scala/es/weso/shapeMaps/ResultShapeMapTest.scala

+31-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import org.scalatest._
77

88
class ResultShapeMapTest extends FunSpec with Matchers with TryValues with OptionValues {
99

10-
describe("ResultShapeMaps") {
10+
/* describe("ResultShapeMaps") {
1111
val rdfStr =
1212
"""prefix : <http://example.org/>
1313
|:a :b :c .
1414
""".stripMargin
15+
1516
compareResultMaps(":a@:S", ":a@:S", rdfStr, true)
1617
compareResultMaps(":a@:S", ":b@:S", rdfStr, false)
1718
compareResultMaps(":a@:S", ":a@:S,:b@:S", rdfStr, false)
19+
compareResultMaps(":a@!:S", ":a@!:S", rdfStr, true)
20+
1821
}
1922
2023
def compareResultMaps(strMap1: String, strMap2: String, rdfStr: String, expectedEqual: Boolean): Unit = {
@@ -39,8 +42,33 @@ class ResultShapeMapTest extends FunSpec with Matchers with TryValues with Optio
3942
})
4043
}
4144
}
45+
*/
46+
describe(s"Parse result shape map") {
47+
it(s"Should parse result shape map") {
48+
val rdfStr =
49+
"""|prefix : <http://example.org/>
50+
|:x :p 1 .
51+
""".stripMargin
4252

43-
describe(s"Get conformant shapes") {
53+
val result = for {
54+
rdf <- RDFAsJenaModel.fromChars(rdfStr,"TURTLE",None)
55+
resultMap <- ShapeMap.parseResultMap(":x@!:S", None, rdf, rdf.getPrefixMap)
56+
} yield (rdf,resultMap)
57+
58+
result match {
59+
case Left(err) => fail(s"Error: $err")
60+
case Right((rdf,result)) => {
61+
val x = IRI("http://example.org/x")
62+
val s = IRILabel(IRI("http://example.org/S"))
63+
val r: ResultShapeMap = ResultShapeMap(Map(x -> Map(s -> Info(NonConformant, None, None))), rdf.getPrefixMap, rdf.getPrefixMap)
64+
println(s"Result: $result\nr=$r")
65+
result should be(r)
66+
}
67+
}
68+
}
69+
}
70+
71+
/* describe(s"Get conformant shapes") {
4472
val pm = PrefixMap.empty.addPrefix("",IRI("http://example.org/"))
4573
val x: RDFNode = IRI("http://example.org/x")
4674
val y: RDFNode = IRI("http://example.org/y")
@@ -82,5 +110,5 @@ class ResultShapeMapTest extends FunSpec with Matchers with TryValues with Optio
82110
rm.getInfo(z,t).status should be(NonConformant)
83111
rm.getInfo(z,u).status should be(Undefined)
84112
}
85-
}
113+
} */
86114
}

out

Whitespace-only changes.

sbt

Whitespace-only changes.

0 commit comments

Comments
 (0)