我有一个使用 Protégé 4.3 创建的 RDF 本体文件,并且我正在尝试创建一个 Java 应用程序(使用 Netbeans 和 Jena)来添加具有六个数据类型属性的新个体。我如何添加这个人,并向推理机添加规则并进行推理?我的初始代码是:
package transportevaluation;
import java.io.InputStream;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
/**
*
* @author sara
*/
public class TransportEvaluation {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// create an empty model
Model model = ModelFactory.createDefaultModel();
String inputFileName = "C:\\Program Files\\Protege_4.3\\Evaluation\\Evaluation.owl";
// use the FileManager to find the input file
InputStream in = FileManager.get().open(inputFileName );
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName
+ " not found");
}
model.read(in, "", "RDF/XML");
// write it to standard out
model.write(System.out);
}
}
最佳答案
我建议从阅读 this resource 开始关于耶拿推论。 Jena 文档中的其他资源也非常有用,例如 Ontology API 上的这个资源。或
以下代码片段将为您提供一个基于规则的推理器,其中填充了您的本体,以及一个可以用来测试推理的个体。如果您不确定如何在耶拿设置/获取属性,那么您可能希望从 Introduction to the Jena API 开始
final OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
model.read( yourInputSource );
model.createIndividual("x-test://someTestIRI");
// TODO add whatever properties are necessary to trigger inference
// TODO test whatever properties are necessary to verify inference occured
如果您需要进行非 owl 基于规则的推理,并且需要构建自己的规则,那么上面的耶拿推理链接将是最好的起点。
关于java - 如何为推理器添加单个、六个数据类型属性和规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21912227/