OWLで公理を書く
次の形式のルールを追加しようとしているようです。
x の気温が 32.0 F 以下の場合、x の気象条件は寒いです。
x の気温が 32.0 F 以上 70.0 F 以下の場合、x の気象条件は Warm です。
x の気温が 70.0 F を超える場合、x の気象条件は暑いです。
これらは、次のような公理で問題なく OWL で実行できます。
hasTemperature some double[> 32.0, <= 70.0] SubClassOf hasWeatherCondition値Warm
これらは、左側に原子クラス名ではなくクラス式があるため、一般クラス公理と呼ばれます。上で説明した完全なセットは、次のように Protégé に入力されます。

イエナとペレットで結果を見る
数字について推論するには、推論器が必要です。Jena のルール推論者がこの種の推論を実行できるかどうかはわかりませんが、Pellet が実行できることはわかっています。次のコードでは、Pellet を利用した推論モデルを使用しています。
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.mindswap.pellet.jena.PelletReasonerFactory;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.OWL;
public class WeatherExample {
public static void main(String[] args) throws FileNotFoundException, IOException {
final String NS = "http://stackoverflow.com/q/20489574/1281433/weather#";
// Create an OntModel and read in the content from the ontology. We're creating an model
// that has Pellet doing inference behind the scenes. Pellet can handle the types of datatype
// reasoning that we need for this particular problem.
final OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );
try ( final FileInputStream in = new FileInputStream( "/home/taylorj/tmp/ontologies/weather/weather.owl" )) {
model.read( in, null, "RDF/XML" );
}
// create an individual and list the things that the model knows about it.
final Individual todaysWeather = model.createIndividual( NS+"weatherOfToday", OWL.Thing );
System.out.println( "== Initial Knowledge ==" );
for ( final StmtIterator it = model.listStatements( todaysWeather, null, (RDFNode) null ); it.hasNext(); ) {
System.out.println( it.next() );
}
// Add the information that todaysWeather had temperature 28.0.
final OntProperty hasTemperature = model.createOntProperty( NS+"hasTemperature" );
todaysWeather.addLiteral( hasTemperature, model.createTypedLiteral( "28.0", XSDDatatype.XSDdouble ));
// Show the new knowledge about todaysWeather.
System.out.println( "== Later Knowledge ==" );
for ( final StmtIterator it = model.listStatements( todaysWeather, null, (RDFNode) null ); it.hasNext(); ) {
System.out.println( it.next() );
}
}
}
出力は次のとおりです。2 番目のチャンクにあることに注意してくださいtodaysWeather hasWeatherCondition Cold
。
== Initial Knowledge ==
[http://stackoverflow.com/q/20489574/1281433/weather#weatherOfToday, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Thing]
[http://stackoverflow.com/q/20489574/1281433/weather#weatherOfToday, http://www.w3.org/2002/07/owl#sameAs, http://stackoverflow.com/q/20489574/1281433/weather#weatherOfToday]
== Later Knowledge ==
[http://stackoverflow.com/q/20489574/1281433/weather#weatherOfToday, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Thing]
[http://stackoverflow.com/q/20489574/1281433/weather#weatherOfToday, http://www.w3.org/2002/07/owl#sameAs, http://stackoverflow.com/q/20489574/1281433/weather#weatherOfToday]
[http://stackoverflow.com/q/20489574/1281433/weather#weatherOfToday, http://stackoverflow.com/q/20489574/1281433/weather#hasWeatherCondition, http://stackoverflow.com/q/20489574/1281433/weather#Cold]
[http://stackoverflow.com/q/20489574/1281433/weather#weatherOfToday, http://stackoverflow.com/q/20489574/1281433/weather#hasTemperature, "28.0"^^http://www.w3.org/2001/XMLSchema#double]
オントロジー
スクリーンショットを作成したオントロジーの内容は以下からコピペできます。
<rdf:RDF
xmlns="http://stackoverflow.com/q/20489574/1281433/weather#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://stackoverflow.com/q/20489574/1281433/weather"/>
<owl:ObjectProperty rdf:about="http://stackoverflow.com/q/20489574/1281433/weather#hasWeatherCondition"/>
<owl:DatatypeProperty rdf:about="http://stackoverflow.com/q/20489574/1281433/weather#hasTemperature">
<rdfs:comment>temperature in degrees Fahrenheit </rdfs:comment>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
</owl:DatatypeProperty>
<owl:Restriction>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://stackoverflow.com/q/20489574/1281433/weather#hasWeatherCondition"/>
<owl:hasValue>
<owl:NamedIndividual rdf:about="http://stackoverflow.com/q/20489574/1281433/weather#Hot"/>
</owl:hasValue>
</owl:Restriction>
</rdfs:subClassOf>
<owl:onProperty rdf:resource="http://stackoverflow.com/q/20489574/1281433/weather#hasTemperature"/>
<owl:someValuesFrom>
<rdfs:Datatype>
<owl:onDatatype rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
<owl:withRestrictions rdf:parseType="Collection">
<rdf:Description>
<xsd:minExclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#double"
>70.0</xsd:minExclusive>
</rdf:Description>
</owl:withRestrictions>
</rdfs:Datatype>
</owl:someValuesFrom>
</owl:Restriction>
<owl:Restriction>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://stackoverflow.com/q/20489574/1281433/weather#hasWeatherCondition"/>
<owl:hasValue>
<owl:NamedIndividual rdf:about="http://stackoverflow.com/q/20489574/1281433/weather#Warm"/>
</owl:hasValue>
</owl:Restriction>
</rdfs:subClassOf>
<owl:onProperty rdf:resource="http://stackoverflow.com/q/20489574/1281433/weather#hasTemperature"/>
<owl:someValuesFrom>
<rdfs:Datatype>
<owl:onDatatype rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
<owl:withRestrictions rdf:parseType="Collection">
<rdf:Description>
<xsd:maxInclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#double"
>70.0</xsd:maxInclusive>
</rdf:Description>
<rdf:Description>
<xsd:minExclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#double"
>32.0</xsd:minExclusive>
</rdf:Description>
</owl:withRestrictions>
</rdfs:Datatype>
</owl:someValuesFrom>
</owl:Restriction>
<owl:Restriction>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://stackoverflow.com/q/20489574/1281433/weather#hasWeatherCondition"/>
<owl:hasValue>
<owl:NamedIndividual rdf:about="http://stackoverflow.com/q/20489574/1281433/weather#Cold"/>
</owl:hasValue>
</owl:Restriction>
</rdfs:subClassOf>
<owl:onProperty rdf:resource="http://stackoverflow.com/q/20489574/1281433/weather#hasTemperature"/>
<owl:someValuesFrom>
<rdfs:Datatype>
<owl:onDatatype rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
<owl:withRestrictions rdf:parseType="Collection">
<rdf:Description>
<xsd:maxInclusive rdf:datatype="http://www.w3.org/2001/XMLSchema#double"
>32.0</xsd:maxInclusive>
</rdf:Description>
</owl:withRestrictions>
</rdfs:Datatype>
</owl:someValuesFrom>
</owl:Restriction>
</rdf:RDF>