📄 reason(2).java
字号:
package com;
import java.io.*;
import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.rdf.model.*;
//import com.hp.hpl.jena.rdf.*;
import com.hp.hpl.jena.ontology.*;
//import com.hp.hpl.jena.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.reasoner.dig.*;
import com.hp.hpl.jena.reasoner.ReasonerRegistry;
import java.util.*;
class test extends Object{
public static void main(String args[])
{
Model cModel = ModelFactory.createDefaultModel();
Resource conf = cModel.createResource();
conf.addProperty( ReasonerVocabulary.EXT_REASONER_URL,
cModel.createResource( "http://localhost:8080" ) );
// create the reasoner factory and the reasoner
DIGReasonerFactory drf = (DIGReasonerFactory) ReasonerRegistry.theRegistry()
.getFactory( DIGReasonerFactory.URI );
DIGReasoner r = (DIGReasoner) drf.create( conf );
// now make a model
OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_DL_MEM );
spec.setReasoner( r );
OntModel modelInf = ModelFactory.createOntologyModel( spec, null );
// load an input document
modelInf.read( "file:animal.owl" );
///////////////////////////////////////////////////////////////////
// list the inconsistent classes
StmtIterator i = modelInf.listStatements( null, OWL.equivalentClass, OWL.Nothing );
while (i.hasNext())
{
System.out.println( "Class " + i.nextStatement().getSubject() + " is unsatisfiable" );
}
//////////////////////////////////////////////////////////////
//有效性检查
Iterator ii;
ValidityReport vrp1 = modelInf.validate();
if (vrp1.isValid()){
System.out.println("OWL VALIDO");
}else {
System.out.println("OWL NO VALIDO");
for (ii = vrp1.getReports(); ii.hasNext();)
{
System.out.println(" - " + ii.next());
}
}
//ResIterator iter = modelInf. listStatements(Lion, subClassOf , Carnivore);
/*
if(0!=iter)
System.out.println("Lion is a Carnivore ");
*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -