On 11/04/12 11:04, Herbie Porter wrote:
Hey everyone,

I'm developing an app to represent weather data in a semantic dataset using
Jena and TDB.

Interesting.

[I'm involved in a pilot project to represent the MetOffice site-specific forecasts in RDF. Though the requirement there is to match the WMO standard modelling. So while the observation sets themselves use Data Cube, the surrounding metadata needs to compatible with OGC Observations & Measurements (i.e. ISO 19156, ISO 19123 et al).]

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.

Not the cause of your current trouibles but that data has some problems:


*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>*

This is a literal, I strongly suspect you meant this to be a resource. There's similar problems with almost all the resources in the data.

<snip>

   <rdf:Description rdf:about="
http://www.semanticweb.org/ontologies/2012/1/monitoringStation.owl#MeteorlogicalObservationWind
">*
*<rdf:type rdf:resource="#Class"/>*

Suspect that shouldn't be #Class.

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*

The trick is to build a safe list of the things you want to delete, then delete them:

private void removeStationObservations(Model model, String station) {
    Resource stationR = model.getResource(station);
Set<RDFNode> observations = model.listObjectsOfProperty(stationR, predictedObservation).toSet();
    for (RDFNode obs : observations) {
        model.remove(stationR, predictedObservation, obs);
        Resource obsR = obs.asResource();
        obsR.getPropertyResourceValue(observationTime)
             .removeProperties();
        obsR.removeProperties();
    }
}

where the properties like observationTime and predicatedObservation would be typically created via schemagen.

Dave

Reply via email to