0

I need to manipulate owl file using the Protege-Owl API. You know, creating classes and properties isn't too difficult.But I don't know how to delete a class or property.If we treat the owl file as a graph, deleting an class means deleting an node and its direct edge.For exemple:

<owl:unionOf rdf:parseType="Collection">
                <rdf:Description rdf:about="&data;DataBundle"/>
                <rdf:Description rdf:about="&data;DataItem"/>
</owl:unionOf>

if I want to delete the class DataItem,

  1. how should I do it using Protege-OWL API? Does RDFResource.delete()can achieve this? I have tried it,but I can't achieve this,maybe there is something wrong.

  2. what will I get after I delete the DataItem?

  3. If DataItem is the domain of an property, what will I get after I delete it?

I hope to get your answer.

Edit: the Protege OWL API is the api described here, not the OWL API described here.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ysfseu
  • 666
  • 1
  • 10
  • 20
  • I think you'll need to show at least some of your code. You mention that you've used RDFResource#delete, but that it didn't work. How did you use it? What didn't work about it? – Joshua Taylor Apr 02 '14 at 17:13
  • Duplicated at http://answers.semanticweb.com/questions/27371/manipulate-owl-file-using-protege-owl-apidelete-classesdelete-properties – Joshua Taylor Apr 02 '14 at 19:03
  • Thank you for your answer!Today I tried to fix my code,and now it works well. – ysfseu Apr 03 '14 at 16:27
  • I'm glad you found a solution to your problem. Can you add some comments to the code in your answer to show people what the difference is? Also, please [accept your answer](http://meta.stackexchange.com/q/5234/225437) to let other users know that you found a solution. – Joshua Taylor Apr 03 '14 at 17:08

1 Answers1

0

@Joshua Taylor,Thank you for your answer!I'm a new user and I make a mistake for posting this problem twice.Sorry for that.I make some mistakes in my code at first and today I tried to fix it.The following codes can delete a class or property.

 import java.io.FileInputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URI;
 import edu.stanford.smi.protegex.owl.ProtegeOWL;
 import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
 import edu.stanford.smi.protegex.owl.model.RDFResource;

 public class DeleteClass {

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub

    //get model from an owl file
    String filePath = "D:\\ss.owl";
    FileInputStream inFile= new FileInputStream(filePath);
    Reader in = new InputStreamReader(inFile,"UTF-8");
    JenaOWLModel jenaOwlModel = ProtegeOWL.createJenaOWLModelFromReader(in);
    //get an class from the model
    RDFResource oneClass=jenaOwlModel.getRDFResource("Person");
    RDFResource oneDataProperty=jenaOwlModel.getRDFResource("age");
    //delete the resource
    oneClass.delete();
    oneDataProperty.delete();
    //save the model to another owl file
    URI file=URI.create("file:///D:/ssChange.owl");
    System.out.println(file);
    jenaOwlModel.save(file);
    //System.out.println(oneClass);

}

}
ysfseu
  • 666
  • 1
  • 10
  • 20