Hi Dhomas,

On 06/06/12 04:07, DHOMAS HATTA FUDHOLI wrote:
The code that I tried to write like the following :
-----
.......
OntModel m = ModelFactory.createOntologyModel();
m.read(input_filename);

DatatypeProperty dp = m.getDatatypeProperty(URI+"usd");

ExtendedIterator<Restriction>  i = m.listRestrictions();
while (i.hasNext()){
Restriction r = i.next();
if (r.onProperty(dp)&&  r.isMaxCardinalityRestriction()){
com.hp.hpl.jena.rdf.model.Property opt = r.getOnProperty();
r.removeOnProperty(opt);
}
}
As Chris said, the root problem you have:

> java.util.ConcurrentModificationException

is because you are modifying a collection that you are also iterating over. However, I'm not sure what you're trying to achieve by just removing the onProperty relation from the restriction. What you said you wanted to do was remove the entire restriction; just removing the onProperty will not do that.

A better approach would be (note: untested code):

OntModel m = ModelFactory.createOntologyModel();
m.read(input_filename);

List<Restriction> restrictionsToRemove = new ArrayList<Restriction>();

DatatypeProperty dp = m.getDatatypeProperty(URI+"usd");

ExtendedIterator<Restriction>  i = m.listRestrictions();
while (i.hasNext()){
  Restriction r = i.next();
  if (r.onProperty(dp)&&  r.isMaxCardinalityRestriction()){
    restrictionsToRemove.add( r );
  }
}

for (Restriction r: restrictionsToRemove) {
  r.remove();
}


Ian

Reply via email to