java - 如何为推理器添加单个、六个数据类型属性和规则?

标签 java jena owl protege

我有一个使用 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/

相关文章:

java - 双代理接口(interface) : Could not generate CGLIB subclass of class 时 Spring AspectJ 失败

java - Fuseki如何添加Pellet推理机

jena - OWL API、Jena API、Protege API,用哪一个

java - 如何使用 OWLAPI 从 owl 个体获取注释

java - 使用 JNotify 库,您如何判断删除的文件是文件还是目录?

java - 将整数映射到对象的最佳方法是什么?以对象作为键

jena - 是否可以从 Jena SWRL 规则中触发 Java 方法

java - 如何在 TDB TripleStore 中加载模型

jena - Import ontology from file(本体本身导入了其他几个文件)

java - 如何初始化从内部类继承的类?