Chapter 5. Deleting RDF

The method to delete imported RDF data is n10s.rdf.delete.fetch. It deletes from Neo4j the triples returned by an url. This url can point to an RDF file (local or remote) or a service producing RDF dynamically. All delete procedures take the following three parameters, like the import procedures:

Parameter Type Description

url

String

URL of the dataset

format

String

serialization format. Valid formats are: Turtle, N-Triples, JSON-LD, RDF/XML, TriG and N-Quads (For named graphs)

params

Map

Set of parameters (see description in table below)

In its most basic form the n10s.rdf.delete.fetch method just takes the url string to access the RDF data and the serialisation format. Let’s say you have already imported the following set of triples into Neo4j with this command:

CALL n10s.rdf.delete.fetch("https://github.com/neo4j-labs/neosemantics/raw/3.5/docs/rdf/deleteRDF/dataset.ttl","Turtle", {
  typesToLabels: true,
  keepCustomDataTypes: true,
  handleMultival: 'ARRAY'
});
@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:Resource1
  a ex:TestResource ;
  ex:Predicate1 "100"^^ex:CDT ;
  ex:Predicate2 "test";
  ex:Predicate3 ex:Resource2 ;
  ex:Predicate4 "val1" ;
  ex:Predicate4 "val2" ;
  ex:Predicate4 "val3" ;
  ex:Predicate4 "val4" .

ex:Resource2
  a ex:TestResource ;
  ex:Predicate1 "test";
  ex:Predicate2 ex:Resource3 ;
  ex:Predicate3 "100"^^xsd:long ;
  ex:Predicate3 "200"^^xsd:long ;
  ex:Predicate4 "300.0"^^xsd:double ;
  ex:Predicate4 "400.0"^^xsd:double .

Let’s say you’re trying to delete the following set of triples from Neo4j after the import above:

@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:Resource1
  ex:Predicate3 ex:Resource2 .

ex:Resource2
  a ex:TestResource ;
  ex:Predicate1 "test";
  ex:Predicate2 ex:Resource3 ;
  ex:Predicate3 "100"^^xsd:long ;
  ex:Predicate3 "200"^^xsd:long ;
  ex:Predicate4 "300.0"^^xsd:double ;
  ex:Predicate4 "400.0"^^xsd:double .

Here is the cypher snippet showing how to do that:

CALL n10s.rdf.delete.fetch("https://github.com/neo4j-labs/neosemantics/raw/3.5/docs/rdf/deleteRDF/delete.ttl","Turtle", {
  typesToLabels: true,
  keepCustomDataTypes: true,
  handleMultival: 'ARRAY'
});

n10s will delete the RDF data in your Neo4j graph. After this deletion your RDF data will look like this:

@prefix ex: <http://example.org/> .

ex:Resource1
  a ex:TestResource ;
  ex:Predicate1 "100"^^ex:CDT ;
  ex:Predicate2 "test";
  ex:Predicate4 "val1" ;
  ex:Predicate4 "val2" ;
  ex:Predicate4 "val3" ;
  ex:Predicate4 "val4" .

Note that currently blank nodes cannot be deleted using n10s.rdf.delete.fetch because we assume that blank node ids are not kept during parsing.

It is also possible to delete triples passed as text (as opposed to passing them by url like in the previous methods). The n10s.rdf.delete.inline procedure can be used for that purpose. n10s.rdf.delete.inline takes the same parameters and operates in exactly the same manner as n10s.rdf.delete.fetch. Here is an example of usage:

A first call to n10s.rdf.delete.inline creates a node in Neo4j based on a set of triples…​

CALL n10s.rdf.import.inline('<http://ind#123> a <http://voc#Type> ; <http://voc#property1> "Value"@en, "Valeur"@fr, "Valor"@es ; <http://voc#property2> 123 .',"Turtle", {
  handleMultival: 'ARRAY',
  keepLangTag: true
});

The previous example stores all values of property property1 in an array keeping the language annotaion. Notice that this import could have equally been carried out using importRDF.

Now we can delete a triples by passing them as text to the deleteRDFSnippet procedure. In this example we are removing the value of the property property1 tagged as english ('en').

CALL n10s.rdf.delete.inline('<http://ind#123> <http://voc#property1> "Value"@en .',"Turtle", {
  handleMultival: 'ARRAY',
  keepLangTag: true
});