Hey everyone,

I'm developing an app to represent weather data in a semantic dataset using
Jena and TDB.  I've got all the data into Jena but I'm having trouble
updating it.  Every 3 hours for every weather monitoring station in my
dataset I would like to be able to delete all old observations and replace
them with new predictions.

An example of my RDF xml representing a *#LandMeterologicalStation* in
Southampton, an *#MeteorlogicalObservation* for this station and
the associated */2006/time#Instant *time/date object.

*RDF/XML:*
*<rdf:Description rdf:about="http://www.witw.com/Data/Stations/Southampton";>
*
*    <rdf:type rdf:resource="
http://www.semanticweb.org/ontologies/2012/1/monitoringStation.owl#LandMeterologicalStation
"/>*
*    <wgs84_pos:location>http://www.witw.com/Data/Points/1234
</wgs84_pos:location>*
*    <j.0:currentObservation>
http://www.witw.com/Data/Observations/1234_2012-04-11T10:31:24.184+01:00
</j.0:currentObservation>*
*    <j.0:predictedObservation>
http://www.witw.com/Data/Observations/1234_2012-04-11T10:31:24.258+01:00
</j.0:predictedObservation>*
*    <j.0:predictedObservation>
http://www.witw.com/Data/Observations/1234_2012-04-11T10:32:22.577+01:00
</j.0:predictedObservation>*
*    <j.0:predictedObservation>
http://www.witw.com/Data/Observations/1234_2012-04-11T10:42:36.491+01:00
</j.0:predictedObservation>*
*    <j.0:spatialGranularity rdf:datatype="
http://www.w3.org/2001/XMLSchema#integer";>1</j.0:spatialGranularity>*
*    <j.0:stationContinent rdf:datatype="
http://www.w3.org/2001/XMLSchema#string";>UK</j.0:stationContinent>*
*    <j.0:stationCountry rdf:datatype="
http://www.w3.org/2001/XMLSchema#string";>England</j.0:stationCountry>*
*    <j.0:stationId rdf:datatype="http://www.w3.org/2001/XMLSchema#string
">1234</j.0:stationId>*
*    <j.0:stationName rdf:datatype="http://www.w3.org/2001/XMLSchema#string
">Southampton</j.0:stationName>*
*  </rdf:Description>*
*
*
*  <rdf:Description rdf:about="
http://www.witw.com/Data/Observations/1234_2012-04-11T10:31:24.258+01:00";>*
*    <rdf:type rdf:resource="
http://www.semanticweb.org/ontologies/2012/1/monitoringStation.owl#MeteorlogicalObservation
"/>*
*    <j.0:observationTime>
http://www.witw.com/Data/Instants/1234_2012-04-11T10:31:24.258+01:00
</j.0:observationTime>*
*    <j.0:temperature rdf:datatype="http://www.w3.org/2001/XMLSchema#integer
">2</j.0:temperature>*
*    <j.0:temperatureFeelsLike rdf:datatype="
http://www.w3.org/2001/XMLSchema#integer";>3</j.0:temperatureFeelsLike>*
*    <j.0:uvIndex rdf:datatype="http://www.w3.org/2001/XMLSchema#integer
">1</j.0:uvIndex>*
*    <j.0:visibility rdf:datatype="http://www.w3.org/2001/XMLSchema#string
">VG</j.0:visibility>*
*    <j.0:weatherType rdf:datatype="http://www.w3.org/2001/XMLSchema#integer
">2</j.0:weatherType>*
*    <j.0:windDir rdf:datatype="http://www.w3.org/2001/XMLSchema#double
">180.0</j.0:windDir>*
*    <j.0:windSpeed rdf:datatype="http://www.w3.org/2001/XMLSchema#integer
">4</j.0:windSpeed>*
*    <j.0:windSpeedGust rdf:datatype="
http://www.w3.org/2001/XMLSchema#integer";>5</j.0:windSpeedGust>*
*  </rdf:Description>*
*
*
*
  <rdf:Description rdf:about="
http://www.witw.com/Data/Instants/1234_2012-04-11T10:31:24.258+01:00";>
    <rdf:type rdf:resource="/2006/time#Instant"/>
    <j.1:inXSDDateTime rdf:datatype="
http://www.w3.org/2001/XMLSchema#dateTime
">2012-04-11T09:31:24.258Z</j.1:inXSDDateTime>
  </rdf:Description>
*
*
  <rdf:Description rdf:about="
http://www.semanticweb.org/ontologies/2012/1/monitoringStation.owl#MeteorlogicalObservationWind
">*
*    <rdf:type rdf:resource="#Class"/>*
*  </rdf:Description>*
*
*
*Code snippet:*
*
*
* /***
* * Used when no current database for the RDF model exists. Loads an
ontology*
* * from the ontologyPath provided by the Spring config file and builds a*
* * database at the provided tbdDBPath.*
* */*
* public void setUpDatabase() {*
* logger.info("Setting Up RDF Database");*
* logger.info("Database Path: " + tbdDBPath);*
* logger.info("Ontology Path: " + ontologyPath);*
*
*
* dataset = TDBFactory.createDataset(tbdDBPath);*
* model = dataset.getDefaultModel();*
* ontModel = ModelFactory*
* .createOntologyModel(OntModelSpec.OWL_MEM, model);*
* ontModel.read(ontologyPath);*
* model.commit();*
* logger.info("Database UP :)");*
* } *

* public boolean removeAllStationProperties(String individualSubjectURI,*
* String propertyObjectURI, String individualObjectURI) {*
*
*
* logger.info("Trying to remove object with URI: " + propertyObjectURI);*
* *
* String encodedIndividualSubjectURI = URIref*
* .encode(individualSubjectURI);*
* String encodedPropertyObjectURI = URIref.encode(propertyObjectURI);*
* String encodedIndividualObjectURI = URIref.encode(individualObjectURI);*
* *
* dataset.begin(ReadWrite.WRITE);*
* model = dataset.getDefaultModel();*
* *
* ontModel = ModelFactory*
* .createOntologyModel(OntModelSpec.OWL_MEM, model);*
* try {*
* Individual individualSubject = ontModel*
* .getIndividual(encodedIndividualSubjectURI);*
*
*
* Resource objectResource = ontModel*
* .getResource(encodedIndividualObjectURI);*
* OntClass thisClass = objectResource.as(OntClass.class);*
* Iterator classIterator = thisClass.listInstances();*
*
*
* while (classIterator.hasNext()) {*
* OntResource thisResource = (OntResource) classIterator.next();*
* classIterator.remove();*
* }*
*
*
*// Second method of removing objects. *
*// *
*// Property thisProperty = ontModel*
*// .getProperty(encodedPropertyObjectURI);*
*//*
*// Individual individualObject = ontModel*
*// .getIndividual(encodedIndividualObjectURI);*
*//*
*// ontModel.remove(individualSubject, thisProperty, individualObject);*
*
*
* *
*// Third method attempted*
*//*
*// individualObject.removeProperties();*
*// individualObject.remove(); *
* *
* dataset.commit();*
* logger.info("Sucessfully removed object and all properties: "*
* + propertyObjectURI);*
* return true;*
*
*
* } finally {*
* dataset.end();*
* }*
* }*

I've tried using the following above method to delete all the *
#MeteorlogicalObservation** *instances but to no avail after 3
different approaches:

   1. Using an iterator over all the instances of the Class *
   #MeteorlogicalObservation.*
      1. Throws UnsupportedOperationException
   2. Calling ontModel.remove() and a predicate describing the relationship.
   3. Calling removeProperties() and remove on the *
   #LandMeterologicalStation.*
      1. This deletes all the *#LandMeterologicalStation *objects but not
      the *#MeteorlogicalObservations.*


To test I call removeAllStationProperties(); using:

* witwDataAdaptor*
* .removeAllStationProperties(*
* witwDataAdaptor.getLandStationIndividualURIPrefix()*
* + "Southampton",*
* "
http://www.semanticweb.org/ontologies/2012/1/witwWorldModel.owl#predictedObservation
",*
* "
http://www.semanticweb.org/ontologies/2012/1/monitoringStation.owl#MeteorlogicalObservation
");*
*
*
My main question is what is the best way to search for and delete all
instances of a class? Including deleting all associated class objects.  In
this example, I'd like to delete all  *#MeteorlogicalObservation *
and associated *#Instant *objects for a given *#LandMeterologicalStation*
 URI.

Thanks in advance for any help you guys can offer and sorry if its a big
post, I've tried to be as complete as possible :)

Herbie

Reply via email to