@Chris : Thank you.
@Ian : It works perfectly to remove the restriction. Thank you.
You guys are awesome.
I tried to use the script, and add the minCardinalityRestriction, so that I can
remove all the restriction (min and max). Then I tried to write it into new
output OWL file using write() method, just like the following :
-----
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() |
r.isMinCardinalityRestriction())){
restrictionsToRemove.add( r );
}
}
for (Restriction r: restrictionsToRemove) {
r.remove();
}
m.write(new PrintWriter(new FileOutputStream(output_filename)));
----
After I get the output file (output.owl), I tried to open it in Protege, to see
visually the structure of ontology. The thing is the min and max Cardinality is
gone, but the IntersectionOf declaration in the priceType class still there and
it contains the following string :
"<empty class
edu.stanford.smi.protegex.owl.model.impl.DefaultOWLIntersectionClass>"
The Pellet consistency check in Protege not resulting an inconsistency though.
but how can I remove it completely? Any advise is very appreciated.
regards,
Dhomas Hatta Fudholi
PhD Candidate, Department of Computer Science and Computer Engineering
La Trobe University, Victoria 3086, Australia
________________________________________
From: Ian Dickinson [[email protected]]
Sent: Wednesday, June 06, 2012 8:13 PM
To: [email protected]
Subject: Re: [ASK] How to remove restriction using Jena?
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