summaryrefslogtreecommitdiff
path: root/examples/sparql_update_example.py
blob: fd7bce4eff62f6e296240ee46c85a5a08b439e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
SPARQL Update statements can be applied with :meth:`rdflib.graph.Graph.update`
"""

import rdflib

if __name__ == "__main__":

    g = rdflib.Graph()
    g.load("foaf.n3", format="n3")

    print("Initially there are {} triples in the graph".format(len(g)))

    g.update(
        """
        PREFIX foaf: <http://xmlns.com/foaf/0.1/>
        PREFIX dbpedia: <http://dbpedia.org/resource/>
        INSERT
            { ?s a dbpedia:Human . }
        WHERE
            { ?s a foaf:Person . }
        """
    )

    print("After the UPDATE, there are {} triples in the graph".format(len(g)))