当前位置: 首页>>代码示例>>Java>>正文


Java OWLReasoner.getInstances方法代码示例

本文整理汇总了Java中org.semanticweb.owlapi.reasoner.OWLReasoner.getInstances方法的典型用法代码示例。如果您正苦于以下问题:Java OWLReasoner.getInstances方法的具体用法?Java OWLReasoner.getInstances怎么用?Java OWLReasoner.getInstances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.semanticweb.owlapi.reasoner.OWLReasoner的用法示例。


在下文中一共展示了OWLReasoner.getInstances方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
/**
 * @param args
 * @throws OWLOntologyCreationException
 */
public static void main(String[] args) throws OWLOntologyCreationException {
	OWLOntologyManager man = OWLManager.createOWLOntologyManager();

	// Load your ontology.
	OWLOntology ont = man
			.loadOntologyFromOntologyDocument(new File(args[0]));
	
	// Create an ELK reasoner.
	OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
	OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
	
	// Precompute instances for each named class in the ontology
	reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS);

	// List representative instances for each class.
	for (OWLClass clazz : ont.getClassesInSignature()) {
		for (Node<OWLNamedIndividual> individual : reasoner.getInstances(
				clazz, true)) {
			System.out.println(clazz + "("
					+ individual.getRepresentativeElement() + ")");
		}
	}

	// Terminate the worker threads used by the reasoner.
	reasoner.dispose();
}
 
开发者ID:liveontologies,项目名称:elk-reasoner,代码行数:31,代码来源:RetrievingInstances.java

示例2: main

import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public static void main(String[] args) throws OWLOntologyCreationException {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = manager.loadOntologyFromOntologyDocument(IRI.create(BASE_URL));
    OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();

    OWLReasoner reasoner = reasonerFactory.createReasoner(ontology, new SimpleConfiguration());
    Version v = reasoner.getReasonerVersion();
    System.out.println("reasoner "+reasoner.getReasonerName()+ " " + v.getMajor()+"."+v.getMinor()+"."+v.getPatch()+" build "+v.getBuild());

    OWLDataFactory factory = manager.getOWLDataFactory();
    OWLClass aClass = factory.getOWLClass(IRI.create(BASE_URL+"#A"));
    System.out.println("it will hang on the next line for Pellet 2.3 ...");
    NodeSet<OWLNamedIndividual> nodeSet = reasoner.getInstances(aClass, false);
    System.out.println("this is never printed");
}
 
开发者ID:martin-kuba,项目名称:owl2-swrl-tutorial,代码行数:16,代码来源:Pellet230Error.java

示例3: main

import org.semanticweb.owlapi.reasoner.OWLReasoner; //导入方法依赖的package包/类
public static void main(String[] args) throws OWLOntologyCreationException {
	OWLOntologyManager man = OWLManager.createOWLOntologyManager();
	OWLDataFactory dataFactory = man.getOWLDataFactory();

	// Load your ontology.
	OWLOntology ont = man.loadOntologyFromOntologyDocument(new File(
			"c:/ontologies/ontology.owl"));

	// Create an ELK reasoner.
	OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
	OWLReasoner reasoner = reasonerFactory.createReasoner(ont);

	// Create your desired query class expression. In this example we
	// will query ObjectIntersectionOf(A ObjectSomeValuesFrom(R B)).
	PrefixManager pm = new DefaultPrefixManager("http://example.org/");
	OWLClass A = dataFactory.getOWLClass(":A", pm);
	OWLObjectProperty R = dataFactory.getOWLObjectProperty(":R", pm);
	OWLClass B = dataFactory.getOWLClass(":B", pm);
	OWLClassExpression query = dataFactory.getOWLObjectIntersectionOf(A,
			dataFactory.getOWLObjectSomeValuesFrom(R, B));

	// Create a fresh name for the query.
	OWLClass newName = dataFactory.getOWLClass(IRI.create("temp001"));
	// Make the query equivalent to the fresh class
	OWLAxiom definition = dataFactory.getOWLEquivalentClassesAxiom(newName,
			query);
	man.addAxiom(ont, definition);

	// Remember to either flush the reasoner after the ontology change
	// or create the reasoner in non-buffering mode. Note that querying
	// a reasoner after an ontology change triggers re-classification of
	// the whole ontology which might be costly. Therefore, if you plan
	// to query for multiple complex class expressions, it will be more
	// efficient to add the corresponding definitions to the ontology at
	// once before asking any queries to the reasoner.
	reasoner.flush();

	// You can now retrieve subclasses, superclasses, and instances of
	// the query class by using its new name instead.
	reasoner.getSubClasses(newName, true);
	reasoner.getSuperClasses(newName, true);
	reasoner.getInstances(newName, false);

	// After you are done with the query, you should remove the definition
	man.removeAxiom(ont, definition);

	// You can now add new definitions for new queries in the same way

	// After you are done with all queries, do not forget to free the
	// resources occupied by the reasoner
	reasoner.dispose();
}
 
开发者ID:liveontologies,项目名称:elk-reasoner,代码行数:53,代码来源:QueryingUnnamedClassExpressions.java


注:本文中的org.semanticweb.owlapi.reasoner.OWLReasoner.getInstances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。