原文地址:http://blog.sina.com.cn/s/blog_7afc04b70101mi4j.html
1 Protégé-OWL API的简单介绍
Protégé-OWL API是专门针对OWL和RDF(S)本体语言的开源Java类库,Protégé-OWL API程序员指南[http://protege.stanford.edu/plugins/owl/api/guide.html]提供了主要类和方法的使用,介绍如何使用Protégé-OWL API加载和保存OWL文件、查询和操作OWL数据模型,以及执行基于描述逻辑的推理。当然,它也可以处理RDF(S )本体,与此对应的类主要有RDFSNamedClass、RDFProperty 和RDFIndividual等。
2 如何使用Protégé-OWL API
Protégé-OWL API是Protégé-OWL被绑定在Protégé的完整安装(在安装Protégé时选择“Everything”)中。获得Protégé-OWL API的Java文档、源代码和一些例子对学习Protégé-OWL API很有帮助。Protégé-OWL API的jar文档被放置于Protégé安装目录下的edu.stanford.smi.protegex.owl包中。
下面以Eclipse为例,介绍使用Protégé-OWL API的使用。经过以上操作后,在Eclipse项目的Java构建路径(Java Build Path)中将所有Jar文件添加为外部Jar文件(程序员指南中的话是“add all the JAR files from the installation to your project classpath”)。这里选择添加\\Protege\plugins\edu.stanford.smi.protegex.owl目录下面的所有Jar文件和\\Protege\目录下的所有Jar文件。于是,就可以成功运行下面的例子了。
// OWLAPIDemoApplication.java源代码
import edu.stanford.smi.protege.exception.OntologyLoadException;
import edu.stanford.smi.protegex.owl.model.OWLModel;
import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
import edu.stanford.smi.protegex.owl.ProtegeOWL;
public class test {
try {
owlModel = ProtegeOWL.createJenaOWLModel();
} catch (OntologyLoadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
另外protege官方指导中有这样的提示:
Now let us configure our Java project and write a small "Hello World" application. If you are using a Java IDE such as Eclipse or IntelliJ, select the Protege installation folder as your project home. Next, add all the JAR files from the installation to your project classpath. Set your compiler output path to plugins/classes.
[1]
[2]