修改了Jena的模型,如何将此owl文件重新加载到Protege

时间:2014-04-11 09:04:27

标签: io jena ontology protege

如标题所示,我读了由Protege生成的Jena文件,通过添加一些NamedIndividuals修改它,我想通过Protege读取修改后的文件。事情进行得很顺利,直到我用Protege打开这个猫头鹰文件。 Protege就是看不懂! 我尝试了每一个" RDF / XML"," RDF / XML - ABBREV"," N-TRIPLE"," TTL",仍然没有

一个好消息是,当我使用" RDF / XML时 - ABBREV"并删除我添加的所有NamedIndividual,Protege有效。 但我想要我的个人!!!

public class Pizza00 {

public static void main(String[] args) throws IOException{
    String SOURCE = "http://www.seaice.com/ontologies/seaice.owl";
    String NS = SOURCE + "#";
    OntModel m = ModelFactory.createOntologyModel();

    try {
        m.read(new FileInputStream("G:/Protege/owl files/SeaIce.owl"), null);
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }

    reason rec = new reason();
    rec = readFileByLines("G:/data/seaice_property.txt");

    int i;
    OntClass tmp = m.getOntClass(NS + "SeaIceProperty");

    for(i = 1; i <= rec.line - 1; i ++){
        m.createIndividual(NS + rec.s[i], tmp);
    }
    m.write(System.out);

    OutputStream out = new FileOutputStream("G:/Protege/owl files/SeaIce - by jena.owl");
    m.write(out, "RDF/XML-ABBREV", null);
    out.close();
}
static class reason{
    String[] s= new String[1000];
    int line;
}
public static reason readFileByLines(String fileName) {
    File file = new File(fileName);
    BufferedReader reader = null;
    reason x = new reason();
    try {
        reader = new BufferedReader(new FileReader(file));
        String tempString = null;
        // 一次读入一行,直到读入null为文件结束
        while ((tempString = reader.readLine()) != null) {
            // 显示行号
            x.s[x.line] = tempString;
            x.line++;
        }
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e1) {
            }
        }
    }
    return x;
}

}

1 个答案:

答案 0 :(得分:0)

正如您在评论中提到的,错误是

  

此行<j.0:SeaIceProperty rdf:about="seaice.com/ontologies/seaice.owl#Optical Band Imagery"/>   发生错误。

     

Protege的错误是   org.semanticweb.owlapi.rdf.syntax.RDFParserException: [line=30:column=101] IRI 'seaice.com/ontologies/seaice.owl#Optical Band Imagery' cannot be resolved against curent base IRI file:/G:/Protege/owl%20files/SeaIce%20-%20by%20jena.owl

不完全IRI seaice.com/ontologies/seaice.owl#Optical Band Imagery是相对的,无法针对当前基础IRI解析,IRI是文件IRI:file:/G:/Protege/owl%20files/SeaIce%20-%20by%20jena.owl。解决此问题的最简单方法是在创建命名个体时使用绝对IRI。