FYI ,
I fixed the input in my application's forms: if URI String From User has
spaces, 1) trim , 2) log an Error and remove them .
And here is a simple query that shows the bad triples ( having incorrect
"URI" with spaces) :
SELECT * WHERE {
GRAPH ?G {
{ ?S ?P ?O .
FILTER ( isURI(?O) ) .
FILTER ( contains( str(?O), " " ) ) .
} UNION { ?S ?P ?O .
FILTER ( isURI(?S) ) .
FILTER ( contains( str(?S), " " ) ) .
}
} }
Then a SPARQL update that fixes the database:
delete { GRAPH ?G {
?S ?P ?O .
} }
insert { GRAPH ?G {
?S ?P ?OnewURI .
?SnewURI ?P ?O .
} }
WHERE {
GRAPH ?G {
{ ?S ?P ?O .
FILTER ( isURI(?O) ) .
FILTER ( contains( str(?O), " " ) ) .
BIND ( URI(replace( str(?O), " ", "")) AS ?OnewURI )
} UNION
{ ?S ?P ?O .
FILTER ( isURI(?S) ) .
FILTER ( contains( str(?S), " " ) ) .
BIND ( URI(replace( str(?S), " ", "")) AS ?SnewURI )
}
} }
( reading delete { GRAPH ?G {?S ?P ?O ... is frightening , but the
variables are well constrained ! ) .
I tested that it indeed fixes the database, and that everything else looks
fine .
2017-12-20 18:09 GMT+01:00 Andy Seaborne <[email protected]>:
>
>
> On 20/12/17 16:31, Laura Morales wrote:
>
>> 1. shouldn't Jena throw an exception when adding such a triple ?
>>>
>>
>> Yes.
>>
>
> Maybe. Depends on route in.
>
> API calls are not checked. URIs presented by the application are expected
> to be correct.
>
> Parsers are expected to check. JSON-LD only prints a warning IIRC.
>
> 2. what is the best way to remove the erroneous triple ?
>>>
>>
>> Validate before inserting.
>>
>>
> The proposal using update and str() looks good to me. That, or dump the
> database to Q-quads and fix the text format.
>
> Andy
>
--
Jean-Marc Vanel
http://www.semantic-forms.cc:9111/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me#subject
<http://www.semantic-forms.cc:9111/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me>
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
+33 (0)6 89 16 29 52
Twitter: @jmvanel , @jmvanel_fr ; chat: irc://irc.freenode.net#eulergui