Sparql 基于多个单一类的等价类本体研究
我在玩比萨饼本体论,我试图获得我所理解的推断知识。 对于一些单独的类,我想获得使用它们的其他类的名称 确切地说,在比萨饼本体中,我们可以找到:Sparql 基于多个单一类的等价类本体研究,sparql,rdf,jena,owl,ontology,Sparql,Rdf,Jena,Owl,Ontology,我在玩比萨饼本体论,我试图获得我所理解的推断知识。 对于一些单独的类,我想获得使用它们的其他类的名称 确切地说,在比萨饼本体中,我们可以找到: 食物 食物/比萨饼 食品/比萨饼/奶酪比萨饼(相当于比萨饼和(hasTopping some CheeseTopping);hasBase some PizzaBase的子类) 食物/比萨饼基地 食品/比萨饼基地/深盘基地 食物/比萨配料 食物/比萨配料/莫扎里拉 我正在尝试使用Mozzarellating和DeepPanBase编写SPARQL请求
- 食物
- 食物/比萨饼
- 食品/比萨饼/奶酪比萨饼(相当于
;hasBase some PizzaBase的子类)比萨饼和(hasTopping some CheeseTopping)
- 食物/比萨饼基地
- 食品/比萨饼基地/深盘基地
- 食物/比萨配料
- 食物/比萨配料/莫扎里拉
Mozzarellating
和DeepPanBase
编写SPARQL请求,这可能会在结果CheeseyPizza
中给出结果。。。但我不知道怎么做,也不知道是否有可能做到。
(我在某个地方读到,可以对个人进行推断,而不是对类进行推断()……但Protégé似乎可以对奶酪比萨饼
)进行推断)
现在,我刚刚得到了共同祖先列表(使用Jena示例):
在不知道本体结构的情况下,是否存在从单个类获取推断类的SPARQL请求?
(在不知道本体结构的情况下:在祖先的请求中,我只给出了两个类的名称,但我从未给出食物/比萨饼的结构……我真的想对整个本体进行真正的研究,包括需要Mozzarella和DeepPan的所有内容)
谢谢大家!
编辑:
我忘了说我也在考虑使用推理机(我正在研究耶拿)。
但是我不知道这样做是否正确。我使用了大量文档,我想我终于找到了解决方案。 这并不完全是我所期望的,但现在已经足够了。 主要思想:创建个体(概念/类的实例),将它们联系在一起,并让推理者发现事物(推论) 有用的文档(感谢StakOverflow提供的链接): 首先,我的解决方案是什么:
- 实例化基础模型(并加载pizza本体)
- 实例化推理模型(并选择推理机)
- 在基础模型中创建:多个个体及其之间的属性/关系
- 检查模型的有效性,请求断言(在基本模型中)和
public static final String SOURCE = "./resources/";
public static final String PIZZA_NS = "http://www.co-ode.org/ontologies/pizza/pizza.owl#";
public void run()
{
// Prefix/Header for SPARQL requests
final String prefix = "prefix pizza: <" + PIZZA_NS + ">\n"
+ "prefix rdfs: <" + RDFS.getURI() + ">\n" + "prefix owl: <"
+ OWL.getURI() + ">\n";
// Prefix for classes, individuals, ... for every object
final String NS = PIZZA_NS;
System.out.println("CREATE THE BASE MODEL\n");
// CREATE THE BASE MODEL
OntModel base = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
base.read(SOURCE + "pizza.owl.rdf", "RDF/XML");
在java中获取有用的类和属性,以便将来个人实例化:
System.out.println("CREATE INDIVIDUALS FOR TESTING PURPOSE\n");
// CREATE INDIVIDUALS FOR TESTING PURPOSE
// Instantiate each useful Class
OntClass ThingClass = base.getOntClass(NS + "owl:Thing");
OntClass FoodClass = base.getOntClass(NS + "Food");
OntClass IceCreamClass = base.getOntClass(NS + "IceCream");
OntClass PizzaClass = base.getOntClass(NS + "Pizza");
OntClass MozzaToppingClass = base.getOntClass(NS + "MozzarellaTopping");
OntClass DeepPanBaseClass = base.getOntClass(NS + "DeepPanBase");
// Instantiate each useful Property (relation)
OntProperty hasIngredientProperty = base.createObjectProperty(NS + "hasIngredient");
OntProperty hasBaseProperty = base.createObjectProperty(NS + "hasBase");
OntProperty hasToppingProperty = base.createObjectProperty(NS + "hasTopping");
// Instantiate each useful individual
Individual MozzaTopping = base.createIndividual(NS + "MyMozzaTopping", MozzaToppingClass);
Individual DeepPanBase = base.createIndividual(NS + "MyDeepPanBase", DeepPanBaseClass);
然后,我首先检查一个同时有两个类的个体(Mozzarellatting和DeepPanBase)。。。推理者看到了奶酪比萨饼,但有效性报告不起作用:
/*
* BEGINNING OF THE TESTS HERE
*/
System.out.println("\nTEST VALIDITY BEFORE ADDING INDIVIDUALS\n");
checkValidity(inf);
// Instantiate testing individuals
// MyPizza1 : individual with 2 classes simultaneously (Mozza & DeepPan)
Individual MyPizza1 = base.createIndividual(NS + "MyPizza1", ThingClass);
MyPizza1.setOntClass(MozzaToppingClass);
MyPizza1.addOntClass(DeepPanBaseClass);
System.out.println("\nTest MyPizza1\n");
showAsserted(base, NS + "MyPizza1");
showInferred(inf, NS + "MyPizza1");
System.out.println("\nTest Validity of MyPizza1 : ");
checkValidity(inf); // ERROR
MyPizza1.remove();
System.out.println("\nRemove MyPizza1, Validity should be OK now : ");
checkValidity(inf); // OK
然后,我尝试了一个“食物”(或“比萨饼”)个体,我和这个个体有一个亲戚hasBase DeepPanBase,另一个亲戚hasTopping mozzarlating。它正在工作,有效性检查中出现问题:
// MyPizza2 : individual of class "Food", linked with Mozza & DeepPan
Individual MyPizza2 = base.createIndividual(NS + "MyPizza2", FoodClass);
MyPizza2.addProperty(hasBaseProperty, DeepPanBase);
MyPizza2.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest MyPizza2\n");
showAsserted(base, NS + "MyPizza2");
showInferred(inf, NS + "MyPizza2");
System.out.println("\nTest Validity of MyPizza2 : ");
checkValidity(inf); // OK
MyPizza2.remove();
System.out.println("\nRemove MyPizza2, Validity should be OK now : ");
checkValidity(inf); // OK
然后,我尝试一个DeepPanBase个体,我给它一个属性/关系hasTopping mozzarlating。推理者的行为也和你想象的一样:他说这是一个奶酪比萨饼,但是,有效性检查表明这是错误的
// MyPizza3 : individual of class "DeepPanBase", linked with Mozza
Individual MyPizza3 = base.createIndividual(NS + "MyPizza3", DeepPanBaseClass);
MyPizza3.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest MyPizza3\n");
showAsserted(base, NS + "MyPizza3");
showInferred(inf, NS + "MyPizza3");
System.out.println("\nTest Validity of MyPizza3 : ");
checkValidity(inf); // ERROR
MyPizza3.remove();
System.out.println("\nRemove MyPizza3, Validity should be OK now : ");
checkValidity(inf); // OK
// IceCream : individual of class "IceCream", linked with Moza & DeePan
Individual MyIceCream = base.createIndividual(NS + "MyIceCream", IceCreamClass);
MyIceCream.addProperty(hasBaseProperty, DeepPanBase);
MyIceCream.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest IceCream\n");
showAsserted(base, NS + "MyIceCream");
showInferred(inf, NS + "MyIceCream");
System.out.println("\nTest Validity of IceCream : ");
checkValidity(inf);
最后,对冰淇淋个体(食物)进行测试。我给它一个关系hasBase DeepPanBase,另一个关系hasTopping mozzarleting。推理者说这是一个奶酪比萨饼,而有效性检查表明这是错误的
// MyPizza3 : individual of class "DeepPanBase", linked with Mozza
Individual MyPizza3 = base.createIndividual(NS + "MyPizza3", DeepPanBaseClass);
MyPizza3.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest MyPizza3\n");
showAsserted(base, NS + "MyPizza3");
showInferred(inf, NS + "MyPizza3");
System.out.println("\nTest Validity of MyPizza3 : ");
checkValidity(inf); // ERROR
MyPizza3.remove();
System.out.println("\nRemove MyPizza3, Validity should be OK now : ");
checkValidity(inf); // OK
// IceCream : individual of class "IceCream", linked with Moza & DeePan
Individual MyIceCream = base.createIndividual(NS + "MyIceCream", IceCreamClass);
MyIceCream.addProperty(hasBaseProperty, DeepPanBase);
MyIceCream.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest IceCream\n");
showAsserted(base, NS + "MyIceCream");
showInferred(inf, NS + "MyIceCream");
System.out.println("\nTest Validity of IceCream : ");
checkValidity(inf);
有效性检查是正确的。如果你检查什么是比萨饼,你会发现它是一种单独的“食物”,包含“配料”/“配料”,以及至少一个比萨饼底。。。但它也不是披萨配料,不是披萨底料,也不是冰淇淋。(这就是为什么有效性检查在哭泣……如果我试图在冰淇淋上放比萨酱,那是不可能的……)
无论如何,正如我承诺的,我在这里给出了完整的代码:
/*
* Example of usage of reasoner with Java. Everything is coming from Apache JENA
* examples. I modified a lot of things for making my personal requests.
* Fabrice Boissier
*/
package Jena_Reasoner_Simple;
import java.util.Date;
import java.util.Iterator;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntClass;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.ontology.OntProperty;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.reasoner.ValidityReport;
import org.apache.jena.vocabulary.OWL;
import org.apache.jena.vocabulary.RDFS;
public class Simple_Reasoner_StepByStep
{
public static void main(String[] args)
{
System.out.println("BEGIN : " + new Date());
new Simple_Reasoner_StepByStep().run();
System.out.println("END : " + new Date());
}
public static final String SOURCE = "./resources/";
public static final String PIZZA_NS = "http://www.co-ode.org/ontologies/pizza/pizza.owl#";
public void run()
{
// Prefix/Header for SPARQL requests
final String prefix = "prefix pizza: <" + PIZZA_NS + ">\n"
+ "prefix rdfs: <" + RDFS.getURI() + ">\n" + "prefix owl: <"
+ OWL.getURI() + ">\n";
// Prefix for classes, individuals, ... for every object
final String NS = PIZZA_NS;
System.out.println("CREATE THE BASE MODEL\n");
// CREATE THE BASE MODEL
OntModel base = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
base.read(SOURCE + "pizza.owl.rdf", "RDF/XML");
System.out.println("CREATE THE REASONING MODEL USING THE BASE\n");
// CREATE THE REASONING MODEL USING THE BASE
OntModel inf = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, base);
// OWL_MEM_MICRO_RULE_INF // It works + Very quick
// OWL_MEM_MINI_RULE_INF // It works + Slow (40Mins) + 1,1Go RAM (Validity is slow)
// OWL_MEM_RULE_INF // It works (mights loop if error) + VERY SLOW + 2,1 GO RAM (unfinished)
// OWL_MEM_TRANS_INF // It works (SPARQL mights not work) + Ultra Speed / No inference
System.out.println("CREATE INDIVIDUALS FOR TESTING PURPOSE\n");
// CREATE INDIVIDUALS FOR TESTING PURPOSE
// Instantiate each useful Class
OntClass ThingClass = base.getOntClass(NS + "owl:Thing");
OntClass FoodClass = base.getOntClass(NS + "Food");
OntClass IceCreamClass = base.getOntClass(NS + "IceCream");
OntClass PizzaClass = base.getOntClass(NS + "Pizza");
OntClass MozzaToppingClass = base.getOntClass(NS + "MozzarellaTopping");
OntClass DeepPanBaseClass = base.getOntClass(NS + "DeepPanBase");
// Instantiate each useful Property (relation)
OntProperty hasIngredientProperty = base.createObjectProperty(NS + "hasIngredient");
OntProperty hasBaseProperty = base.createObjectProperty(NS + "hasBase");
OntProperty hasToppingProperty = base.createObjectProperty(NS + "hasTopping");
// Instantiate each useful individual
Individual MozzaTopping = base.createIndividual(NS + "MyMozzaTopping", MozzaToppingClass);
Individual DeepPanBase = base.createIndividual(NS + "MyDeepPanBase", DeepPanBaseClass);
/*
* BEGINNING OF THE TESTS HERE
*/
System.out.println("\nTEST VALIDITY BEFORE ADDING INDIVIDUALS\n");
checkValidity(inf);
// Instantiate testing individuals
// MyPizza1 : individual with 2 classes simultaneously (Mozza & DeepPan)
Individual MyPizza1 = base.createIndividual(NS + "MyPizza1", ThingClass);
MyPizza1.setOntClass(MozzaToppingClass);
MyPizza1.addOntClass(DeepPanBaseClass);
System.out.println("\nTest MyPizza1\n");
showAsserted(base, NS + "MyPizza1");
showInferred(inf, NS + "MyPizza1");
System.out.println("\nTest Validity of MyPizza1 : ");
checkValidity(inf); // ERROR
MyPizza1.remove();
System.out.println("\nRemove MyPizza1, Validity should be OK now : ");
checkValidity(inf); // OK
// MyPizza2 : individual of class "Food", linked with Mozza & DeepPan
Individual MyPizza2 = base.createIndividual(NS + "MyPizza2", FoodClass);
MyPizza2.addProperty(hasBaseProperty, DeepPanBase);
MyPizza2.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest MyPizza2\n");
showAsserted(base, NS + "MyPizza2");
showInferred(inf, NS + "MyPizza2");
System.out.println("\nTest Validity of MyPizza2 : ");
checkValidity(inf); // OK
MyPizza2.remove();
System.out.println("\nRemove MyPizza2, Validity should be OK now : ");
checkValidity(inf); // OK
// MyPizza3 : individual of class "DeepPanBase", linked with Mozza
Individual MyPizza3 = base.createIndividual(NS + "MyPizza3", DeepPanBaseClass);
MyPizza3.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest MyPizza3\n");
showAsserted(base, NS + "MyPizza3");
showInferred(inf, NS + "MyPizza3");
System.out.println("\nTest Validity of MyPizza3 : ");
checkValidity(inf); // ERROR
MyPizza3.remove();
System.out.println("\nRemove MyPizza3, Validity should be OK now : ");
checkValidity(inf); // OK
// IceCream : individual of class "IceCream", linked with Moza & DeePan
Individual MyIceCream = base.createIndividual(NS + "MyIceCream", IceCreamClass);
MyIceCream.addProperty(hasBaseProperty, DeepPanBase);
MyIceCream.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest IceCream\n");
showAsserted(base, NS + "MyIceCream");
showInferred(inf, NS + "MyIceCream");
System.out.println("\nTest Validity of IceCream : ");
checkValidity(inf);
/*
* END OF THE TESTS HERE
*/
System.out.println("End Tests\n");
}
protected void showAsserted(OntModel m, String individualURI)
{
// list the asserted types
Individual instance = m.getIndividual(individualURI); // BASE
for (Iterator<Resource> i = instance.listRDFTypes(false); i.hasNext();)
{
System.out
.println(instance.getURI() + " is asserted in class " + i.next());
}
}
protected void showInferred(OntModel m, String individualURI)
{
// list the inferred types
Individual instance = m.getIndividual(individualURI); // INFERED
for (Iterator<Resource> i = instance.listRDFTypes(false); i.hasNext();)
{
System.out.println(
instance.getURI() + " is inferred to be in class " + i.next());
}
}
protected void checkValidity(OntModel inf)
{
ValidityReport validity = inf.validate();
if (validity.isValid())
{
System.out.println("OK");
}
else
{
System.out.println("Conflicts");
for (Iterator i = validity.getReports(); i.hasNext();)
{
System.out.println(" - " + i.next());
}
}
}
}
/*
*将reasoner与Java结合使用的示例。一切都来自阿帕奇·耶纳
*例子。我修改了很多东西来提出我的个人要求。
*法布里斯·波西耶
*/
包装Jena_Reasoner_Simple;
导入java.util.Date;
导入java.util.Iterator;
导入org.apache.jena.ontology.Individual;
导入org.apache.jena.ontology.OntClass;
导入org.apache.jena.ontology.OntModel;
导入org.apache.jena.ontology.OntModelSpec;
导入org.apache.jena.ontology.ontroperty;
导入org.apache.jena.rdf.model.ModelFactory;
导入org.apache.jena.rdf.model.Resource;
导入org.apache.jena.reasoner.ValidityReport;
导入org.apache.jena.词汇表.OWL;
导入org.apache.jena.词汇表.RDFS;
公共类简单推理器
{
公共静态void main(字符串[]args)
{
System.out.println(“开始:+newdate());
新的Simple_Reasoner_StepByStep().run();
System.out.println(“结束:+newdate());
}
公共静态最终字符串SOURCE=“./resources/”;
公共静态最终字符串\u NS=”http://www.co-ode.org/ontologies/pizza/pizza.owl#";
公开募捐
{
//SPARQL请求的前缀/头
final String prefix=“prefix pizza:\n”
+“前缀rdfs:\n”+“前缀owl:\n”;
//每个对象的类、个体等的前缀
最后一个字符串NS=比萨饼;
System.out.println(“创建基本模型\n”);
//创建基础模型
OntModel base=ModelFactory.createOntologyModel(OntModelSpec.OWL\u MEM);
read(SOURCE+“pizza.owl.rdf”,“rdf/XML”);
System.out.println(“使用BASE\n创建推理模型”);
//使用TH创建推理模型
package Jena_Reasoner_SPARQL;
import java.util.Date;
import java.util.Iterator;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntClass;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.ontology.OntProperty;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.ResultSetFormatter;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.reasoner.ValidityReport;
import org.apache.jena.vocabulary.OWL;
import org.apache.jena.vocabulary.RDFS;
public class Simple_Reasoner_and_SPARQL_Request
{
public static final String SOURCE = "./resources/";
public static final String PIZZA_NS = "http://www.co-ode.org/ontologies/pizza/pizza.owl#";
public static final String prefix = "prefix pizza: <" + PIZZA_NS + ">\n"
+ "prefix rdfs: <" + RDFS.getURI() + ">\n"
+ "prefix owl: <" + OWL.getURI() + ">\n";
public static void main(String[] args)
{
System.out.println("BEGIN " + new Date());
new Simple_Reasoner_and_SPARQL_Request().run();
System.out.println("END " + new Date());
}
public void run()
{
String NS = PIZZA_NS;
System.out.println("CREATE AND LOAD THE BASE MODEL");
// CREATE AND LOAD THE BASE MODEL
OntModel base = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
base.read(SOURCE + "pizza.owl.rdf", "RDF/XML");
System.out.println("CREATE THE REASONING MODEL USING THE BASE\n");
// CREATE THE REASONING MODEL USING THE BASE
OntModel inf = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, base);
// OWL_MEM_MICRO_RULE_INF // It works + Very quick
// OWL_MEM_MINI_RULE_INF // It works + Slow (40Mins) + 1,1Go RAM (Validity is slow)
// OWL_MEM_RULE_INF // It works (mights loop if error) + VERY SLOW + 2,1Go RAM (unfinished)
// OWL_MEM_TRANS_INF // It works (SPARQL mights not work) + Ultra Speed / No inference
System.out.println("CREATE INDIVIDUALS FOR TESTING PURPOSE\n");
// CREATE INDIVIDUALS FOR TESTING PURPOSE
// Instantiate each useful Class
OntClass ThingClass = base.getOntClass(NS + "owl:Thing");
OntClass FoodClass = base.getOntClass(NS + "Food");
OntClass IceCreamClass = base.getOntClass(NS + "IceCream");
OntClass PizzaClass = base.getOntClass(NS + "Pizza");
OntClass MozzaToppingClass = base.getOntClass(NS + "MozzarellaTopping");
OntClass DeepPanBaseClass = base.getOntClass(NS + "DeepPanBase");
// Instantiate each useful Property (relation)
OntProperty hasIngredientProperty = base.createObjectProperty(NS + "hasIngredient");
OntProperty hasBaseProperty = base.createObjectProperty(NS + "hasBase");
OntProperty hasToppingProperty = base.createObjectProperty(NS + "hasTopping");
// Instantiate each useful individual
Individual MozzaTopping = base.createIndividual(NS + "MyMozzaTopping", MozzaToppingClass);
Individual DeepPanBase = base.createIndividual(NS + "MyDeepPanBase", DeepPanBaseClass);
/*
* BEGINNING OF THE TESTS HERE
*/
System.out.println("\nTEST VALIDITY BEFORE ADDING INDIVIDUALS " + new Date() + "\n");
checkValidity(inf);
// Instantiate testing individuals
// MyPizza1 : individual of class "Food", linked with Mozza & DeepPan
Individual MyPizza1 = base.createIndividual(NS + "MyPizza1", FoodClass);
MyPizza1.addProperty(hasBaseProperty, DeepPanBase);
MyPizza1.addProperty(hasToppingProperty, MozzaTopping);
System.out.println("\nTest MyPizza1 " + new Date() + "\n");
showAsserted(base, NS + "MyPizza1");
showInferred(inf, NS + "MyPizza1");
System.out.println("\nTest Validity of MyPizza1 : " + new Date());
checkValidity(inf); // OK
// SPARQL Tests now
System.out.println("\nSPARQL TESTS\n");
printPrefix();
// Research every Food
System.out.println("\nResearch Food in Base model");
showQuery(base,
prefix + "SELECT ?individual " + "WHERE { "
+ " ?individual a pizza:Food . "
+ " FILTER ( ! isBlank(?individual) ) " + "} ");
System.out.println("\nResearch Food in Inference model");
showQuery(inf,
prefix + "SELECT ?individual " + "WHERE { "
+ " ?individual a pizza:Food . "
+ " FILTER ( ! isBlank(?individual) ) " + "} ");
// Research every CheeseyPizza
System.out.println("\nResearch CheeseyPizza in Base model");
showQuery(base,
prefix + "SELECT ?individual " + "WHERE { "
+ " ?individual a pizza:CheeseyPizza . "
+ " FILTER ( ! isBlank(?individual) ) " + "} ");
System.out.println("\nResearch CheeseyPizza in Inference model");
showQuery(inf,
prefix + "SELECT ?individual " + "WHERE { "
+ " ?individual a pizza:CheeseyPizza . "
+ " FILTER ( ! isBlank(?individual) ) " + "} ");
/*
* END OF THE TESTS HERE
*/
System.out.println("End Tests\n");
}
protected void showAsserted(OntModel m, String individualURI)
{
// list the asserted types
Individual instance = m.getIndividual(individualURI); // BASE
for (Iterator<Resource> i = instance.listRDFTypes(false); i.hasNext();)
{
System.out
.println(instance.getURI() + " is asserted in class " + i.next());
}
}
protected void showInferred(OntModel m, String individualURI)
{
// list the inferred types
Individual instance = m.getIndividual(individualURI); // INFERED
for (Iterator<Resource> i = instance.listRDFTypes(false); i.hasNext();)
{
System.out.println(
instance.getURI() + " is inferred to be in class " + i.next());
}
}
protected void checkValidity(OntModel inf)
{
ValidityReport validity = inf.validate();
if (validity.isValid())
{
System.out.println("OK");
}
else
{
System.out.println("Conflicts");
for (Iterator i = validity.getReports(); i.hasNext();)
{
System.out.println(" - " + i.next());
}
}
}
protected void printPrefix()
{
System.out.println(prefix);
}
protected void showQuery(Model m, String q)
{
Query query = QueryFactory.create(q);
QueryExecution qexec = QueryExecutionFactory.create(query, m);
try
{
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(results, m);
}
finally
{
qexec.close();
}
}
}