neo4j-labs / neosemantics

Graph+Semantics: Import/Export RDF from Neo4j. SHACL Validation, Model mapping and more.... If you like it, please ★ ⇧
https://neo4j.com/labs/neosemantics/
Apache License 2.0
809 stars 140 forks source link

Importing N-triples requires quotes to be double escaped #288

Open danmichaelo opened 1 year ago

danmichaelo commented 1 year ago

Seems like there is an issue with importing strings with escaped quotes (\"):

CALL n10s.graphconfig.init({
  handleVocabUris: 'IGNORE',
  handleMultival: 'OVERWRITE',
  handleRDFTypes: 'LABELS',
  applyNeo4jNaming: true
});

CALL n10s.rdf.import.inline(
  '
<https://example.org/thing/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://example.org/prop/Event> .

<https://example.org/thing/1> <https://example.org/prop/name> "Test \"with\" quotes" .
',
  'N-Triples' 
)
terminationStatus triplesLoaded triplesParsed namespaces extraInfo callParams
KO 0 0   Content after '.' is not allowed [line 2] {}

It works if I double-escape them:

CALL n10s.rdf.import.inline(
  '
<https://example.org/thing/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://id.bs.no/cordata/class/Event> .

<https://example.org/thing/1> <https://example.org/prop/name> "Test \\"with\\" quotes" .
',
  'N-Triples' 
)

but that's not standard in the n-triples serialization, I think.

danmichaelo commented 1 year ago

Note: This only seems to be a problem with the inline import – importing from a file with n10s.rdf.import.fetch works fine with single escaped quotes!

jbarrasa commented 1 year ago

Hi @danmichaelo , I think the behavior is consistent. When you use the .inline method you need to pass a parseable string so additional escaping is needed. Let me use a simple example in python that shows the strings we are passing to the method in each case:

this_will_fail_parsing = '\"Test \"with\" quotes\"'
print('this_will_fail_parsing: ',this_will_fail_parsing)

>>  this_will_fail_parsing:  "Test "with" quotes"

this_will_parse = '\"Test \\"with\\" quotes\"'
print('this_will_parse: ', this_will_parse)

>>  this_will_parse:  "Test \"with\" quotes"

do you agree?

JB.

danmichaelo commented 1 year ago

Thanks, that makes sense, @jbarrasa 🙌 I was probably confused because I pasted N-triples into the "Import Data" dialog in Neosemantics and it didn't convert them:

image

Perhaps the real issue, if there is one, is with how the import dialog works? I think it could be argued that the import dialog should accept normal RDF input (single escaped quotes) and convert it to valid Cypher automatically? What do you think?

Sorry for the confusion btw.! Feel free to rename the issue or close it accordingly 👍

jbarrasa commented 1 year ago

Oh! I see what you mean. You're totally right, the app should take care of the escaping and produce valid cypher, for sure. I thought you were working on the browser, that's why I suggested it was up to you to generate a correct string.

Let us have a look at that, and thanks for explaining it in detail!