Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request for issue #292 #293

Merged
merged 3 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ object RDFNode {
val xsd = "http://www.w3.org/2001/XMLSchema#"
val rdfSyntax = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
val StringDatatypeIRI = IRI(xsd + "string")
val RDFhtmlStringDatatypeIRI = IRI(rdfSyntax + "HTML") // RH20220819
val LangStringDatatypeIRI = IRI(rdfSyntax + "langString")
val BooleanDatatypeIRI = IRI(xsd + "boolean")
val IntegerDatatypeIRI = IRI(xsd + "integer")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package es.weso.rdf.nodes

case class RDFhtmlStringLiteral(lexicalForm: String) extends Literal {
val xsd = "http://www.w3.org/2001/XMLSchema#"
val rdfSyntax = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
val StringDatatypeIRI: IRI = IRI(xsd + "string")
val RDFhtmlStringDatatypeIRI: IRI = IRI(rdfSyntax + "HTML")

// TODO: write a condition to see if we need rdf:HTML -- RH20220819

val MyStringDatatypeIRI: IRI = if (false) StringDatatypeIRI else RDFhtmlStringDatatypeIRI // StringDatatypeIRI

override val dataType : IRI = RDFhtmlStringDatatypeIRI // MyStringDatatypeIRI // StringDatatypeIRI

override def isLangLiteral = false
override def hasLang(lang: Lang) = false

override def toString: String = {
// TODO: Check if literal contains extended chars
"\"" + lexicalForm + "\"^^rdf:HTML"
}

override def getLexicalForm = lexicalForm

override def isEqualTo(other: RDFNode): Either[String,Boolean] = other match {
case StringLiteral(s) => Right(s == lexicalForm)
case _ => Right(false)
}

def lessThan(other: RDFNode): Either[String,Boolean] = other match {
case StringLiteral(str) => Right(lexicalForm < str)
case _ => Left(s"Cannot compare string literal $this < $other which is not a string")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ trait RDFParser {

def checkString(obj: RDFNode, p:IRI): RDFParser[String] = obj match {
case StringLiteral(str) => parseOk(str)
case RDFhtmlStringLiteral(str) => parseOk(str) // RH20220819
case _ => parseFail("Value of predicate " + p + " must be a string literal but it is: " + obj)
}

Expand Down Expand Up @@ -553,6 +554,7 @@ trait RDFParser {
} yield v

def checkString(n: RDFNode): RDFParser[String] = n match {
case s: RDFhtmlStringLiteral => parseOk(s.getLexicalForm) // RH20220819
case s: StringLiteral => parseOk(s.getLexicalForm)
case _ => parseFail(s"Expected string literal for node $n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ object JenaMapper {
}
case lit: JenaLiteral => {
extendNS(lit.getDatatype.getURI) match {
case Some(RDFNode.`RDFhtmlStringDatatypeIRI`) => // RH20220819
ok(RDFhtmlStringLiteral(lit.getLexicalForm))
case None | Some(RDFNode.`StringDatatypeIRI`) =>
ok(StringLiteral(lit.getLexicalForm))
case Some(RDFNode.`IntegerDatatypeIRI`) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class GraphTest extends CatsEffectSuite {

def bnode(s: String): BNode = BNode(s)

def int(n: Int): IntegerLiteral = IntegerLiteral(n, n.toString)
def int(n: Int) : IntegerLiteral = IntegerLiteral(n, n.toString)

def string(s: String): StringLiteral = StringLiteral(s)

def rdfHTML(s: String): RDFhtmlStringLiteral = RDFhtmlStringLiteral(s)

shouldTraverse(
iri("x"),
Expand Down Expand Up @@ -79,6 +83,39 @@ class GraphTest extends CatsEffectSuite {
true
)

shouldTraverse(
iri("x"),
"""|prefix : <http://example.org/>
|:x :p _:1, _:2 ;
| :q "Plain String" .
|_:1 :p :y, :z .
|:r :q :x .
""".stripMargin,
LazyList(
iri("x"), iri("y"), iri("z"),
bnode("1"), bnode("2"),
string("Plain String")
),
true
)

shouldTraverse(
iri("x2"),
"""|prefix : <http://example.org/>
|prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|:x2 :p _:1, _:2 ;
| :q "<p>HTML String 2</p>"^^rdf:HTML .
|_:1 :p :y2, :z2 .
|:r :q :x2 .
""".stripMargin,
LazyList(
iri("x2"), iri("y2"), iri("z2"),
bnode("1"), bnode("2"),
rdfHTML("<p>HTML String 2</p>")
),
true
)

def shouldTraverse(node: RDFNode,
str: String,
expected: LazyList[RDFNode],
Expand All @@ -95,8 +132,6 @@ class GraphTest extends CatsEffectSuite {
}
}



shouldTraverseWithArcs(
iri("x"),
"""|prefix : <http://example.org/>
Expand Down