Globally replace IRI with a new value #4480
-
Sometimes, it may be necessary to change the value of an IRI, e.g. because there is a typo in it or because an initially automatically generated IRI should be replaced with something more semantic. What would be the best and most efficient way of using the RDF4J API to globally replace all occurrences of a given IRI with a new value? |
Beta Was this translation helpful? Give feedback.
Answered by
abrokenjester
Mar 10, 2023
Replies: 2 comments 3 replies
-
I bet that a SPARQL update would be the fastest. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Alternatively, directly using the API: conn.begin();
conn.getStatements(oldIRI, null, null).forEach(st -> { conn.remove(st); conn.add(newIRI, st.getPredicate(), st.getObject()); });
conn.getStatements(null, oldIRI, null).forEach(st -> { conn.remove(st); conn.add(st.getSubject(), newIRI, st.getObject()); });
conn.getStatements(null, null, oldIRI).forEach(st -> { conn.remove(st); conn.add(st.getSubject(), st.getPredicate(), newIRI); });
conn.commit(); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
reckart
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, directly using the API: