blake-regalia / graphy.js

A collection of RDF libraries for JavaScript
https://graphy.link/
ISC License
161 stars 3 forks source link

Unexpected output for quoted literals with datatype #51

Closed CrocoDillon closed 2 years ago

CrocoDillon commented 2 years ago

Hello, I'm pretty much a newb to any of this so sorry for this question (I did my best to search for the answer though). I need to implement an export to .ttl format. However when I try to include a quoted literal with datatype the output is not what I expect. Am I doing something wrong?

Input:

'gwsw:hasAspect': {
    a: 'gwsw:Punt',
    'gwsw:hasValue':
        '"<gml:Point xmlns:gml="http://www.opengis.net/gml"><gml:pos>150000 400000 -5</gml:pos></gml:Point>"^^geo:gmlLiteral',
},

Red is actual output, green is expected output (closing quote is escaped and new closing quote is added):

gwsw:hasAspect [
    rdf:type gwsw:Punt ;
-   gwsw:hasValue "<gml:Point xmlns:gml=\"http://www.opengis.net/gml\"><gml:pos>150000 400000 -5</gml:pos></gml:Point>\"^^geo:gmlLiteral" ;
+   gwsw:hasValue "<gml:Point xmlns:gml=\"http://www.opengis.net/gml\"><gml:pos>150000 400000 -5</gml:pos></gml:Point>"^^geo:gmlLiteral ;
] ;

It doesn't seem to matter whether or not the quoted literal contains double quotes.

blake-regalia commented 2 years ago

Hi 👋

C1 strings are an original syntax, so they can be a bit confusing at first.

For literals, the language or datatype comes first, then the contents of the literal. So for example, @en"Hello world, or ^xsd:integer"10. So in your example, try this:

({
  'gwsw:hasAspect': {
      a: 'gwsw:Punt',
      'gwsw:hasValue':
          '^geo:gmlLiteral"<gml:Point xmlns:gml="http://www.opengis.net/gml"><gml:pos>150000 400000 -5</gml:pos>
  </gml:Point>',
})

Notice how the " quotes inside the literal's contents don't need to be escaped :)

CrocoDillon commented 2 years ago

How did I miss this 🙈 This works (obviously), thanks a lot for your answer! 😄