Question

I have a number of classes inside an ontology file and the same number of classes with different names inside xml files. I have created a RDF triple store from the XML files. Now I need to change the name of classes inside the triple store to those inside the Ontology.

Can anyone have an Idea how to make the equivalence by using SPARQL query? if it cannot be done by SPARQL query, what is the best way to do that?

----------- This is a small part of the RDF -------

<rdf:RDF
    xmlns:j.0="http://link/myLink/myOntology.rdf#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > 
  <rdf:Description rdf:about="http://myDomain/myLink/%a=class/class9/">
    <j.0:hadP>Sea Power</j.0:hadP>
    <j.0:hadP>Steel city</j.0:hadP>
    <j.0:hadP>Singer1</j.0:hadP>
    <j.0:hadV>20</j.0:hadV>
    <j.0:hadP>City</j.0:hadP>
    <j.0:hadP>Singer2</j.0:hadP>
    <j.0:hadP>Singer3</j.0:hadP>
    <j.0:hadV>80</j.0:hadV>
    <j.0:hadVEvent>web:V</j.0:hadVEvent>
    <j.0:hadP>Park</j.0:hadP>
    <j.0:hadP>Arctic</j.0:hadP>
    <j.0:hadP>Guns</j.0:hadP>
    <rdf:type rdf:resource="http://link/myLink/myOntology.rdf#**ClassName**"/>
    <j.0:hadP>City Center</j.0:hadP>
    <j.0:hadV>100</j.0:hadV>
    <j.0:hadV>40</j.0:hadV>
  </rdf:Description>
 </rdf:RDF>

I want to change the name (ClassName) into a different name for example(ClassA). Can I do that by writing a SPARQL QUERY?

As a toolkit I'm using gena I'm not sure what I'm asking about is possible or not!

Was it helpful?

Solution

In general, Jena resources are immutable: you can't change a Resource object once it has been created. This means that you can't change the URI of any Resource, including classes.

What you have do do instead is to update the model to exhibit the effect of renaming. Suppose you want to rename resource R to S. For each triple:

R P O

you need to add a new triple:

S P O

and remove the old R P O triple. Likewise each triple Q P R should be deleted and a triple Q P S added.

There is a utility in the Jena API to do this for you: ResourceUtils.renameResource. If you want to stick to SPARQL, you have to go through the same adding-and-removing triples process, but you can do it via SPARQL Update, which is supported in Jena.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top