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

Support for rdf:HTML as a type of literal #292

Open
ralphtq opened this issue Aug 18, 2022 · 5 comments
Open

Support for rdf:HTML as a type of literal #292

ralphtq opened this issue Aug 18, 2022 · 5 comments

Comments

@ralphtq
Copy link
Contributor

ralphtq commented Aug 18, 2022

Could we extend object RDFNode as follows:

val RDFhtmlStringDatatypeIRI = IRI(rdfSyntax + "HTML")

in:

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")
val LangStringDatatypeIRI = IRI(rdfSyntax + "langString")
val BooleanDatatypeIRI = IRI(xsd + "boolean")
val IntegerDatatypeIRI = IRI(xsd + "integer")
val DoubleDatatypeIRI = IRI(xsd + "double")
val DecimalDatatypeIRI = IRI(xsd + "decimal")
val rdftype = IRI(rdfSyntax + "type")
val rdfnil = IRI(rdfSyntax + "nil")
val rdffirst = IRI(rdfSyntax + "first")
val rdfrest = IRI(rdfSyntax + "rest")
...
...

Ralph

@ralphtq
Copy link
Contributor Author

ralphtq commented Aug 19, 2022

I've forked srdf and made a start on supporting rdf:HTML.

This is the branch I have in my fork: https://github.com/ralphtq/srdf/tree/rh-master-rdfhtml

Need now to understand how to do the PR process and make snapshots.

Ralph

labra added a commit that referenced this issue Aug 19, 2022
@labra
Copy link
Member

labra commented Aug 19, 2022

Thanks for the suggestion and the code...in principle it seems it works.

I also added support for rdf:XMLLiteral as well and it has been published as version 0.1.113

I keep the isse open by now until you confirm it is working as expected and we can close the issue.

@ralphtq
Copy link
Contributor Author

ralphtq commented Aug 20, 2022

Further work was needed to overcome this error:

New branch is https://github.com/ralphtq/srdf/tree/rh-master-rdfhtml-inc2

This is the change:

node match {
  case b: BNode =>
    m.createResource(new AnonId(b.id.toString))
  case i: IRI =>
    m.createResource(resolve(i, base))
  case StringLiteral(str) =>
    m.createLiteral(str, false)
  case RDFHTMLLiteral(str) =>    // RH20220820
    m.createLiteral(str, false)  // RH20220820
    ....

Ralph

@ralphtq
Copy link
Contributor Author

ralphtq commented Aug 20, 2022

Changes also needed in shacl-s.

See weso/shacl-s#203

@ralphtq
Copy link
Contributor Author

ralphtq commented Apr 12, 2023

On recent testing the support for rdf:HTML is failing in the JenaMapper.

I have this test:

it("Should compare one triple with a rdf:HTML literal") {
  val ts = Set(RDFTriple(BNode("b" + 0), IRI("http://example.org#p"), RDFHTMLLiteral("<div>Test HTML markup</div>")))
  val s =
    """|@prefix : <http://example.org#> .
       |_:a :p "<div>Test HTML markup</div>"^^rdf:HTML .""".stripMargin
  println(s"ts: $ts")
  val empty = ModelFactory.createDefaultModel
  val model1 = RDFTriples2Model(ts, empty, None)
  val model2 = str2model(s)
  shouldBeIsomorphic(model1, model2)
}

With these results:

ts: Set(_:b0 http://example.org#p "

Test HTML markup
"^^rdf:HTML)
model1: <ModelCom {b0 @http://example.org#p "
Test HTML markup
"} | [b0, http://example.org#p, "
Test HTML markup
"]>
[info] - Should compare one triple with a rdf:HTML literal *** FAILED ***
[info] org.apache.jena.riot.RiotException: [line: 2, col: 39] Undefined prefix: rdf
[info] at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:163)
[info] at org.apache.jena.riot.system.ParserProfileStd.expandPrefixedName(ParserProfileStd.java:322)
[info] at org.apache.jena.riot.system.ParserProfileStd.create(ParserProfileStd.java:282)
[info] at org.apache.jena.riot.lang.LangTurtleBase.tokenAsNode(LangTurtleBase.java:577)
[info] at org.apache.jena.riot.lang.LangTurtleBase.node(LangTurtleBase.java:410)
[info] at org.apache.jena.riot.lang.LangTurtleBase.triplesNode(LangTurtleBase.java:445)
[info] at org.apache.jena.riot.lang.LangTurtleBase.objectList(LangTurtleBase.java:419)
[info] at org.apache.jena.riot.lang.LangTurtleBase.predicateObjectItem(LangTurtleBase.java:352)
[info] at org.apache.jena.riot.lang.LangTurtleBase.predicateObjectList(LangTurtleBase.java:333)
[info] at org.apache.jena.riot.lang.LangTurtleBase.triples(LangTurtleBase.java:314)
[info] ...

RDFHTMLLiteral is working but the transfer to the Jena model is failing.

I have traced the error to this function in "ParserProfileStd.java", starting at line 317:

private String expandPrefixedName(String prefix, String localPart, Token token) {
    String expansion = prefixMap.expand(prefix, localPart);
    if ( expansion == null ) {
        if ( ARQ.isTrue(ARQ.fixupUndefinedPrefixes) )
            return RiotLib.fixupPrefixIRI(prefix, localPart);
        errorHandler.fatal("Undefined prefix: " + prefix, token.getLine(), token.getColumn());
    }
    return expansion;
}

@ralphtq ralphtq changed the title Would like to have rdf:HTML as a type of literal Support for rdf:HTML as a type of literal Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants