Jena Fuseki 内置推理规则实现Sparql查询推理结果

本文仅仅是能执行成功的步骤,具体原理希望看文的小伙伴自己去查一下~

1.owl文件的准备

我是用的protege自己建了一个本体,导出两个不同类型的本体文件,一个是rdf/xml格式,另一个是turtle三元组格式,都是owl文件(名字是当时建本体的时候不会改,现在也不会,有大佬会的话请您在百忙之中抽空教我一下~)。如果你的owl文件是从网上找的代码,也可以试试用protege打开,然后再另存为这两个格式。

Jena Fuseki 内置推理规则实现Sparql查询推理结果

Jena Fuseki 内置推理规则实现Sparql查询推理结果
<?xml version="1.0"?>
<rdf:rdf xmlns="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#" xml:base="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:untitled-ontology-23="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#">
    <owl:ontology rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23">

    <!--
    ///
    //
    // Object Properties
    //
    ///
     -->

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#contain -->

    <owl:objectproperty rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#contain">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
        <rdfs:range rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdfs:range rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#mediummedicine">
    </rdfs:range></rdfs:range></rdfs:domain></owl:objectproperty>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cure -->

    <owl:objectproperty rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cure">
        <owl:equivalentproperty rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x4E3B;&#x6CBB;">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#mediummedicine">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
        <rdfs:range rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#disease">
    </rdfs:range></rdfs:domain></rdfs:domain></rdfs:domain></owl:equivalentproperty></owl:objectproperty>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#不属于 -->

    <owl:objectproperty rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x4E0D;&#x5C5E;&#x4E8E;">
        <owl:inverseof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x5C5E;&#x4E8E;">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdfs:range rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
    </rdfs:range></rdfs:domain></owl:inverseof></owl:objectproperty>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#主治 -->

    <owl:objectproperty rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x4E3B;&#x6CBB;">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#traditionalmedicine">
        <rdfs:range rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#disease">
    </rdfs:range></rdfs:domain></owl:objectproperty>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#属于 -->

    <owl:objectproperty rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x5C5E;&#x4E8E;">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdfs:range rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
    </rdfs:range></rdfs:domain></owl:objectproperty>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#相同功效 -->

    <owl:objectproperty rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x76F8;&#x540C;&#x529F;&#x6548;">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
        <rdfs:range rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdfs:range rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
    </rdfs:range></rdfs:range></rdfs:domain></rdfs:domain></owl:objectproperty>

    <!--
    ///
    //
    // Data properties
    //
    ///
     -->

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#中药名 -->

    <owl:datatypeproperty rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x4E2D;&#x836F;&#x540D;">

    <!--
    ///
    //
    // Classes
    //
    ///
     -->

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#activity -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#activity">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#case">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#body -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#body">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#entities">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#case -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#case">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#traditionalmedicine">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#chemistry -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#chemistry">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#entities">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#color -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#color">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#chemistry">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#corporeity -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#corporeity">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#body">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cure -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cure">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#activity">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#disease -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#disease">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#phenomenon">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingfunction -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingfunction">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#entities">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingname -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingname">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#entities -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#entities">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#traditionalmedicine">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#function -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#function">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#phenomenon">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#mediummedicine -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#mediummedicine">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#entities">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#phenomenon -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#phenomenon">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#case">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#entities">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciptionfunction -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciptionfunction">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciptionname -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciptionname">
        <rdfs:subclassof rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
    </rdfs:subclassof></owl:class>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#traditionalmedicine -->

    <owl:class rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#traditionalmedicine">

    <!--
    ///
    //
    // Individuals
    //
    ///
     -->

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cough -->

    <owl:thing rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cough">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#disease">
    </rdf:type></rdf:type></owl:thing>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#午时茶颗粒 -->

    <owl:thing rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x5348;&#x65F6;&#x8336;&#x9897;&#x7C92;">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingname">
        <主治 rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cough">
    </主治></rdf:type></rdf:type></rdf:type></owl:thing>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#小柴胡颗粒 -->

    <owl:thing rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x5C0F;&#x67F4;&#x80E1;&#x9897;&#x7C92;">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingname">
        <相同功效 rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x677F;&#x84DD;&#x6839;&#x9897;&#x7C92;">
    </相同功效></rdf:type></rdf:type></rdf:type></owl:thing>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#板蓝根颗粒 -->

    <owl:thing rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x677F;&#x84DD;&#x6839;&#x9897;&#x7C92;">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingname">
        <主治 rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cough">
    </主治></rdf:type></rdf:type></rdf:type></owl:thing>

    <!-- http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#清热解毒方剂 -->

    <owl:thing rdf:about="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x6E05;&#x70ED;&#x89E3;&#x6BD2;&#x65B9;&#x5242;">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption">
        <rdf:type rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciptionname">
        <cure rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cough">
        <主治 rdf:resource="http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cough">
    </主治></cure></rdf:type></rdf:type></rdf:type></owl:thing>
</owl:class></owl:datatypeproperty></owl:ontology></rdf:rdf>

<!-- Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi -->

Jena Fuseki 内置推理规则实现Sparql查询推理结果

Jena Fuseki 内置推理规则实现Sparql查询推理结果

第二个我直接放在了fuseki的databases目录下,已经从owl格式直接改成了ttl格式,我是直接改的后缀名。 它是一定要放入databases文件夹中的。

@prefix : <http: 11 2021 www.semanticweb.org admin ontologies untitled-ontology-23#> .
@prefix owl: <http: 2002 www.w3.org 07 owl#> .
@prefix rdf: <http: 1999 www.w3.org 02 22-rdf-syntax-ns#> .
@prefix xml: <http: 1998 www.w3.org xml namespace> .
@prefix xsd: <http: 2001 www.w3.org xmlschema#> .
@prefix rdfs: <http: 2000 www.w3.org 01 rdf-schema#> .
@prefix untitled-ontology-23: <http: 11 2021 www.semanticweb.org admin ontologies untitled-ontology-23#> .
@base <http: 11 2021 www.semanticweb.org admin ontologies untitled-ontology-23> .

<http: 11 2021 www.semanticweb.org admin ontologies untitled-ontology-23> rdf:type owl:Ontology .

#################################################################
   Object Properties
#################################################################

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#contain
untitled-ontology-23:contain rdf:type owl:ObjectProperty ;
                             rdfs:domain untitled-ontology-23:presciption ;
                             rdfs:range untitled-ontology-23:drinkingmedicine ,
                                        untitled-ontology-23:mediummedicine .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cure
untitled-ontology-23:cure rdf:type owl:ObjectProperty ;
                          owl:equivalentProperty untitled-ontology-23:&#x4E3B;&#x6CBB; ;
                          rdfs:domain untitled-ontology-23:drinkingmedicine ,
                                      untitled-ontology-23:mediummedicine ,
                                      untitled-ontology-23:presciption ;
                          rdfs:range untitled-ontology-23:disease .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x4E0D;&#x5C5E;&#x4E8E;
untitled-ontology-23:&#x4E0D;&#x5C5E;&#x4E8E; rdf:type owl:ObjectProperty ;
                         owl:inverseOf untitled-ontology-23:&#x5C5E;&#x4E8E; ;
                         rdfs:domain untitled-ontology-23:drinkingmedicine ;
                         rdfs:range untitled-ontology-23:presciption .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x4E3B;&#x6CBB;
untitled-ontology-23:&#x4E3B;&#x6CBB; rdf:type owl:ObjectProperty ;
                        rdfs:domain untitled-ontology-23:traditionalmedicine ;
                        rdfs:range untitled-ontology-23:disease .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x5C5E;&#x4E8E;
untitled-ontology-23:&#x5C5E;&#x4E8E; rdf:type owl:ObjectProperty ;
                        rdfs:domain untitled-ontology-23:drinkingmedicine ;
                        rdfs:range untitled-ontology-23:presciption .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x76F8;&#x540C;&#x529F;&#x6548;
untitled-ontology-23:&#x76F8;&#x540C;&#x529F;&#x6548; rdf:type owl:ObjectProperty ;
                          rdfs:domain untitled-ontology-23:drinkingmedicine ,
                                      untitled-ontology-23:presciption ;
                          rdfs:range untitled-ontology-23:drinkingmedicine ,
                                     untitled-ontology-23:presciption .

#################################################################
   Data properties
#################################################################

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x4E2D;&#x836F;&#x540D;
untitled-ontology-23:&#x4E2D;&#x836F;&#x540D; rdf:type owl:DatatypeProperty .

#################################################################
   Classes
#################################################################

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#activity
untitled-ontology-23:activity rdf:type owl:Class ;
                              rdfs:subClassOf untitled-ontology-23:case .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#body
untitled-ontology-23:body rdf:type owl:Class ;
                          rdfs:subClassOf untitled-ontology-23:entities .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#case
untitled-ontology-23:case rdf:type owl:Class ;
                          rdfs:subClassOf untitled-ontology-23:traditionalmedicine .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#chemistry
untitled-ontology-23:chemistry rdf:type owl:Class ;
                               rdfs:subClassOf untitled-ontology-23:entities .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#color
untitled-ontology-23:color rdf:type owl:Class ;
                           rdfs:subClassOf untitled-ontology-23:chemistry .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#corporeity
untitled-ontology-23:corporeity rdf:type owl:Class ;
                                rdfs:subClassOf untitled-ontology-23:body .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cure
untitled-ontology-23:cure rdf:type owl:Class ;
                          rdfs:subClassOf untitled-ontology-23:activity .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#disease
untitled-ontology-23:disease rdf:type owl:Class ;
                             rdfs:subClassOf untitled-ontology-23:phenomenon .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingfunction
untitled-ontology-23:drinkingfunction rdf:type owl:Class ;
                                      rdfs:subClassOf untitled-ontology-23:drinkingmedicine .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingmedicine
untitled-ontology-23:drinkingmedicine rdf:type owl:Class ;
                                      rdfs:subClassOf untitled-ontology-23:entities .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#drinkingname
untitled-ontology-23:drinkingname rdf:type owl:Class ;
                                  rdfs:subClassOf untitled-ontology-23:drinkingmedicine .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#entities
untitled-ontology-23:entities rdf:type owl:Class ;
                              rdfs:subClassOf untitled-ontology-23:traditionalmedicine .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#function
untitled-ontology-23:function rdf:type owl:Class ;
                              rdfs:subClassOf untitled-ontology-23:phenomenon .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#mediummedicine
untitled-ontology-23:mediummedicine rdf:type owl:Class ;
                                    rdfs:subClassOf untitled-ontology-23:entities .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#phenomenon
untitled-ontology-23:phenomenon rdf:type owl:Class ;
                                rdfs:subClassOf untitled-ontology-23:case .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciption
untitled-ontology-23:presciption rdf:type owl:Class ;
                                 rdfs:subClassOf untitled-ontology-23:entities .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciptionfunction
untitled-ontology-23:presciptionfunction rdf:type owl:Class ;
                                         rdfs:subClassOf untitled-ontology-23:presciption .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#presciptionname
untitled-ontology-23:presciptionname rdf:type owl:Class ;
                                     rdfs:subClassOf untitled-ontology-23:presciption .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#traditionalmedicine
untitled-ontology-23:traditionalmedicine rdf:type owl:Class .

#################################################################
   Individuals
#################################################################

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#cough
untitled-ontology-23:cough rdf:type owl:NamedIndividual ,
                                    untitled-ontology-23:disease ,
                                    owl:Thing .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x5348;&#x65F6;&#x8336;&#x9897;&#x7C92;
untitled-ontology-23:&#x5348;&#x65F6;&#x8336;&#x9897;&#x7C92; rdf:type owl:NamedIndividual ,
                                    untitled-ontology-23:drinkingmedicine ,
                                    untitled-ontology-23:drinkingname ,
                                    owl:Thing ;
                           untitled-ontology-23:&#x4E3B;&#x6CBB; untitled-ontology-23:cough .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x5C0F;&#x67F4;&#x80E1;&#x9897;&#x7C92;
untitled-ontology-23:&#x5C0F;&#x67F4;&#x80E1;&#x9897;&#x7C92; rdf:type owl:NamedIndividual ,
                                    untitled-ontology-23:drinkingmedicine ,
                                    untitled-ontology-23:drinkingname ,
                                    owl:Thing ;
                           untitled-ontology-23:&#x76F8;&#x540C;&#x529F;&#x6548; untitled-ontology-23:&#x677F;&#x84DD;&#x6839;&#x9897;&#x7C92; .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x677F;&#x84DD;&#x6839;&#x9897;&#x7C92;
untitled-ontology-23:&#x677F;&#x84DD;&#x6839;&#x9897;&#x7C92; rdf:type owl:NamedIndividual ,
                                    untitled-ontology-23:drinkingmedicine ,
                                    untitled-ontology-23:drinkingname ,
                                    owl:Thing ;
                           untitled-ontology-23:&#x4E3B;&#x6CBB; untitled-ontology-23:cough .

###  http://www.semanticweb.org/admin/ontologies/2021/11/untitled-ontology-23#&#x6E05;&#x70ED;&#x89E3;&#x6BD2;&#x65B9;&#x5242;
untitled-ontology-23:&#x6E05;&#x70ED;&#x89E3;&#x6BD2;&#x65B9;&#x5242; rdf:type owl:NamedIndividual ,
                                     untitled-ontology-23:presciption ,
                                     untitled-ontology-23:presciptionname ,
                                     owl:Thing ;
                            untitled-ontology-23:cure untitled-ontology-23:cough ;
                            untitled-ontology-23:&#x4E3B;&#x6CBB; untitled-ontology-23:cough .

###  Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi
</http:></http:></http:></http:></http:></http:></http:></http:></http:>

Jena Fuseki 内置推理规则实现Sparql查询推理结果

run目录是在点击fuseki-server.bat运行成功后自动生成的。

2.生成TDB数据

jena使用TDB存储数据,所以我们要生成一个tdb文件,这里用上面导出的rdf/xml格式的owl文件,可以看到我的tdb文件夹建在JENA目录下。

tdbloader.bat --loc F:\JENA\tdb F:\medicinetwo.owl

在jena的bat目录下输入cmd进入控制台,输出结果如下

Jena Fuseki 内置推理规则实现Sparql查询推理结果

Jena Fuseki 内置推理规则实现Sparql查询推理结果

3.在 F:\JENA\apache-jena-fuseki-4.3.1\run\configuration下新建一个ttl文件

Jena Fuseki 内置推理规则实现Sparql查询推理结果

我的ttl文件,#后注释是我自己在代码块上加的,运行的时候最好把它删掉。

@prefix :      <http: base #> .
@prefix tdb:   <http: 2008 jena.hpl.hp.com tdb#> .
@prefix rdf:   <http: 1999 www.w3.org 02 22-rdf-syntax-ns#> .
@prefix ja:    <http: 11 2005 jena.hpl.hp.com assembler#> .
@prefix rdfs:  <http: 2000 www.w3.org 01 rdf-schema#> .
@prefix fuseki: <http: jena.apache.org fuseki#> .

:service1        a                fuseki:Service ;
fuseki:dataset                    <#dataset> ;
#&#x8FD9;&#x662F;&#x5728;fuseki&#x4E2D;&#x663E;&#x793A;&#x7684;dataset&#x540D;&#xFF0C;&#x4E0D;&#x8981;&#x548C;&#x4E4B;&#x524D;&#x6709;&#x7684;&#x91CD;&#x590D;&#x4E86;&#x5C31;&#x884C;
fuseki:name                       "medicinetest" ;
fuseki:serviceQuery               "query" , "sparql" ;
fuseki:serviceReadGraphStore      "get" ;
fuseki:serviceReadWriteGraphStore "data" ;
fuseki:serviceUpdate              "update" ;
fuseki:serviceUpload              "upload" .

<#dataset> rdf:type ja:RDFDataset ;
    ja:defaultGraph <#model_inf> ;
    .
<#model_inf> rdf:type ja:InfModel ;
ja:baseModel <#basemodel> ;
ja:reasoner [
#&#x8FD9;&#x91CC;&#x662F;&#x5BFC;&#x5165;&#x63A8;&#x7406;&#x89C4;&#x5219;&#xFF0C;&#x5185;&#x7F6E;&#x7684;&#x63A8;&#x7406;&#x673A;&#x5DF2;&#x7ECF;&#x88AB;&#x6CE8;&#x91CA;&#x6389;&#x4E86;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x9700;&#x8981;&#x81EA;&#x5B9A;&#x4E49;&#x89C4;&#x5219;&#x7684;&#xFF0C;&#x53EF;&#x4EE5;&#x628A;2&#x3001;3&#x884C;&#x6CE8;&#x91CA;&#x6389;&#xFF0C;&#x7B2C;&#x4E00;#&#x884C;&#x653E;&#x51FA;
             #ja:reasonerURL <http: 2003 jena.hpl.hp.com owlfbrulereasoner>
             ja:reasonerURL <http: 2003 jena.hpl.hp.com genericrulereasoner> ;
             ja:rulesFrom <file: f: jena apache-jena-fuseki-4.3.1 run databases medicinerules.ttl> ;#&#x89C4;&#x5219;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;
] ;
.
<#basemodel> rdf:type ja:UnionModel;
ja:subModel <#ontology>;
ja:rootModel <#tdbgraph>;
.

<#ontology> rdf:type ja:MemoryModel;
ja:content [ja:externalContent <file: f: jena apache-jena-fuseki-4.3.1 run databases medicinetest.ttl> ] ;#turtle&#x5F62;&#x5F0F;&#x7684;owl&#x6587;&#x4EF6;&#x8DEF;&#x5F84;
.

<#tdbgraph> rdf:type tdb:GraphTDB ;
tdb:dataset <#tdbdataset> ;
.

<#tdbdataset> rdf:type tdb:DatasetTDB ;
tdb:location  "F:/JENA/tdb"  ;#tdb&#x6570;&#x636E;&#x7684;&#x8DEF;&#x5F84;
#ja:context [ ja:cxtName "arq:queryTimeout" ; ja:cxtValue "1000" ] ;
.
</#tdbdataset></#tdbdataset></#tdbgraph></file:></#ontology></#tdbgraph></#ontology></#basemodel></file:></http:></http:></#basemodel></#model_inf></#model_inf></#dataset></#dataset></http:></http:></http:></http:></http:></http:>

我的规则文件

@prefix me: <http: 11 2021 www.semanticweb.org admin ontologies untitled-ontology-23#>.

@prefix rdf: <http: 1999 www.w3.org 02 22-rdf-syntax-ns#> .
@include <rdfs>.

@include <owl>.

[rule1: (?a me:&#x4E3B;&#x6CBB; ?c),(?b me:&#x4E3B;&#x6CBB; ?c),(?b rdf:type me:presciption)->(?a me:&#x5C5E;&#x4E8E; ?b)]
[rule2: (?a me:&#x4E3B;&#x6CBB; ?c),(?b me:&#x4E3B;&#x6CBB; ?c)->(?a me:&#x76F8;&#x540C;&#x529F;&#x6548; ?b)]
[rule3: (?a me:&#x76F8;&#x540C;&#x529F;&#x6548; ?b),(?a me:&#x4E3B;&#x6CBB; ?c)->(?b me:&#x4E3B;&#x6CBB; ?c)]
[rule4: (?a me:&#x76F8;&#x540C;&#x529F;&#x6548; ?b)->(?b me:&#x76F8;&#x540C;&#x529F;&#x6548; ?a)]</owl></rdfs></http:></http:>

把这些搞完就可以重新点击fuseki-server.bat.启动fuseki服务了

Jena Fuseki 内置推理规则实现Sparql查询推理结果

启动成功

4.sparql语句查询推理结果

先看fuseki页面

Jena Fuseki 内置推理规则实现Sparql查询推理结果

Jena Fuseki 内置推理规则实现Sparql查询推理结果

我只定义了清热解毒方剂为presciption类型,也就是方剂类型。其他的属性都是根据推理规则推理出来的。

我在eclipse里也查询了一下,就只能查询到我定义了的,不能查询到推理出来的。

Jena Fuseki 内置推理规则实现Sparql查询推理结果

我的项目是基于文本学习本体的中医药知识库构建,我主要负责的就是jena的学习和推理的实现,小白第一次写CSDN,有错误欢迎指正,也可以一起交流,互相学习,共同进步!

Original: https://blog.csdn.net/qq_45808425/article/details/121991434
Author: 烬烬2002
Title: Jena Fuseki 内置推理规则实现Sparql查询推理结果

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/555286/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球