neosemantics
neosemantics copied to clipboard
Importing N-triples requires quotes to be double escaped
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.
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!
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.
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:

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 👍
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!