本文整理汇总了Java中org.semanticweb.owlapi.util.DefaultPrefixManager类的典型用法代码示例。如果您正苦于以下问题:Java DefaultPrefixManager类的具体用法?Java DefaultPrefixManager怎么用?Java DefaultPrefixManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultPrefixManager类属于org.semanticweb.owlapi.util包,在下文中一共展示了DefaultPrefixManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testOWLClassHashCode
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Test that two {@code OWLClass}es that are equal have a same hashcode,
* because the OWLGraphEdge bug get me paranoid.
*/
@Test
public void testOWLClassHashCode()
{
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
IRI iri = IRI.create("http://www.foo.org/#A");
OWLClass class1 = factory.getOWLClass(iri);
//get the class by another way, even if if I suspect the two references
//will point to the same object
PrefixManager pm = new DefaultPrefixManager("http://www.foo.org/#");
OWLClass class2 = factory.getOWLClass(":A", pm);
assertTrue("The two references point to different OWLClass objects",
class1 == class2);
//then of course the hashcodes will be the same...
assertTrue("Two OWLClasses are equal but have different hashcode",
class1.equals(class2) && class1.hashCode() == class2.hashCode());
}
开发者ID:owlcollab,项目名称:owltools,代码行数:23,代码来源:OWLGraphManipulatorTest.java
示例2: main
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
public static void main(String[] args) {
DefaultPrefixManager pm = new DefaultPrefixManager("http://test.com#");
OWLClass A = Class(":A", pm);
OWLClass B = Class(":B", pm);
OWLClass C = Class(":C", pm);
OWLObjectProperty prop = ObjectProperty(":p", pm);
OWLIndividual i = NamedIndividual(":i", pm);
OWLIndividual j = NamedIndividual(":j", pm);
OWLIndividual k = NamedIndividual(":k", pm);
OWLIndividual l = NamedIndividual(":l", pm);
OWLDataFactory df = new OWLDataFactoryImpl();
// OWLAxiom ax = SubClassOf(A, ObjectIntersectionOf(B, ObjectIntersectionOf(ObjectComplementOf(B), C)));
// OWLAxiom ax = SubClassOf(A, ObjectSomeValuesFrom(prop, OWLThing()));
// OWLAxiom ax = SubClassOf(A, ObjectAllValuesFrom(prop, B));
OWLAxiom ax = SubClassOf(A, ObjectOneOf(i, j, k, l));
// ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer());
System.out.println(ax);
System.out.println("---------------------------------------------------");
DeltaTransformation transformation = new DeltaTransformation(df);
for(OWLAxiom axt : transformation.transform(Collections.singleton(ax))) {
System.out.println(axt);
}
}
开发者ID:matthewhorridge,项目名称:owlexplanation,代码行数:26,代码来源:DeltaTransformation.java
示例3: OWLFuncionalSyntaxRefsetObjectRenderer
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* @param ontology
* the ontology
* @param writer
* the writer
*/
public OWLFuncionalSyntaxRefsetObjectRenderer(OWLOntology ontology, Writer writer) {
ont = ontology;
this.writer = writer;
defaultPrefixManager = new DefaultPrefixManager();
prefixManager = defaultPrefixManager;
OWLDocumentFormat ontologyFormat = ontology.getFormat();
// reuse the setting on the existing format
addMissingDeclarations = ontologyFormat.isAddMissingTypes();
if (ontologyFormat instanceof PrefixDocumentFormat) {
prefixManager.copyPrefixesFrom((PrefixDocumentFormat) ontologyFormat);
prefixManager.setPrefixComparator(((PrefixDocumentFormat) ontologyFormat).getPrefixComparator());
}
if (!ontology.isAnonymous()) {
String existingDefault = prefixManager.getDefaultPrefix();
String ontologyIRIString = ontology.getOntologyID().getOntologyIRI().get().toString();
if (existingDefault == null || !existingDefault.startsWith(ontologyIRIString)) {
String defaultPrefix = ontologyIRIString;
if (!ontologyIRIString.endsWith("/")) {
defaultPrefix = ontologyIRIString + '#';
}
prefixManager.setDefaultPrefix(defaultPrefix);
}
}
Map<OWLAnnotationProperty, List<String>> prefLangMap = new HashMap<>();
OWLOntologyManager manager = ontology.getOWLOntologyManager();
OWLDataFactory df = manager.getOWLDataFactory();
OWLAnnotationProperty labelProp = df.getOWLAnnotationProperty(RDFS_LABEL.getIRI());
labelMaker = new AnnotationValueShortFormProvider(Collections.singletonList(labelProp), prefLangMap, manager,
defaultPrefixManager);
}
开发者ID:termMed,项目名称:rf2-to-owl,代码行数:37,代码来源:OWLFuncionalSyntaxRefsetObjectRenderer.java
示例4: setPrefixManager
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* @param prefixManager
* the new prefix manager
*/
public void setPrefixManager(PrefixManager prefixManager) {
this.prefixManager = prefixManager;
if (prefixManager instanceof DefaultPrefixManager) {
defaultPrefixManager = (DefaultPrefixManager) prefixManager;
}
}
开发者ID:termMed,项目名称:rf2-to-owl,代码行数:11,代码来源:OWLFuncionalSyntaxRefsetObjectRenderer.java
示例5: ignoreChangesInNonImportedOntologies
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Testing correctness of the reasoner with respect to ontology changes
*/
@Test
public void ignoreChangesInNonImportedOntologies() throws Exception {
OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// set up resolution of prefixes
DefaultPrefixManager pm = new DefaultPrefixManager();
pm.setDefaultPrefix("http://www.example.com/main#");
pm.setPrefix("A:", "http://www.example.com/A#");
pm.setPrefix("B:", "http://www.example.com/B#");
OWLClass extA = dataFactory.getOWLClass("A:A", pm);
OWLClass extB = dataFactory.getOWLClass("B:B", pm);
// loading the root ontology
OWLOntology root = loadOntology(man, "root.owl");
// Create an ELK reasoner.
ElkReasoner reasoner = (ElkReasoner) new ElkReasonerFactory()
.createReasoner(root);
// make sure the reasoner loads the ontology
reasoner.flush();
reasoner.isConsistent();
try {
OWLOntology nonImported = loadOntology(man, "nonImported.owl");
OWLAxiom axiom = dataFactory.getOWLSubClassOfAxiom(extA, extB);
man.removeAxiom(nonImported, axiom);
reasoner.flush();
AbstractReasonerState state = reasoner.getInternalReasoner();
assertTrue(state.stageManager.inputLoadingStage.isCompleted());
} finally {
reasoner.dispose();
}
}
开发者ID:liveontologies,项目名称:elk-reasoner,代码行数:43,代码来源:IgnoreChangesInNonImportedOntologiesTest.java
示例6: initializeFormat
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Initialize the format with standard default prefixes
* (rdf, rdfs, xsd, owl) and with the prefixes we will use
* (obo, oio, iao).
*
* @return The format with the prefixes set.
*/
protected static RDFXMLDocumentFormat initializeFormat() {
RDFXMLDocumentFormat format = new RDFXMLDocumentFormat();
format.copyPrefixesFrom(new DefaultPrefixManager());
format.setPrefix("obo", OBO);
format.setPrefix("oio", OIO);
format.setPrefix("iao", IAO);
format.setPrefix("ncbi", NCBI);
format.setPrefix("ncbitaxon", OBO + "ncbitaxon#");
return format;
}
开发者ID:owlcollab,项目名称:owltools,代码行数:18,代码来源:OWLConverter.java
示例7: createObjectProperty
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
private static OWLObjectProperty createObjectProperty(OWLOntology ontology, DefaultPrefixManager pm, OWLOntologyManager manager, String name) {
OWLDataFactory factory = manager.getOWLDataFactory();
OWLObjectProperty objectProperty = factory.getOWLObjectProperty(name, pm);
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(objectProperty));
return objectProperty;
}
开发者ID:martin-kuba,项目名称:owl2-swrl-tutorial,代码行数:9,代码来源:CreateOntologyInCodeExample.java
示例8: OWLHelper
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
private OWLHelper() throws OWLOntologyCreationException, OWLOntologyStorageException {
manager = OWLManager.createOWLOntologyManager();
ontologyIRI = IRI.create(URI);
ontology = manager.createOntology(ontologyIRI);
factory = manager.getOWLDataFactory();
prefixManager = new DefaultPrefixManager(null, null, ontologyIRI + "#");
classeGenerica = factory.getOWLClass("Thing", prefixManager);
instanciasL = new HashMap<>();
}
开发者ID:arnaldosales,项目名称:java-pln,代码行数:13,代码来源:OWLHelper.java
示例9: main
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
public static void main(String[] args) {
DefaultPrefixManager pm = new DefaultPrefixManager("http://test.com#");
OWLClass clsA = Class("A", pm);
OWLClass clsB = Class("B", pm);
OWLClassExpression ce = ObjectIntersectionOf(clsA, ObjectIntersectionOf(clsB, clsA));
TauGenerator tauGenerator = new TauGenerator(new OWLDataFactoryImpl());
Set<OWLClassExpression> classExpressions = ce.accept(tauGenerator);
for(OWLClassExpression classExpression : classExpressions) {
System.out.println(classExpression);
}
}
开发者ID:matthewhorridge,项目名称:owlexplanation,代码行数:12,代码来源:NestedIntersectionTestCase.java
示例10: prefixManager
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.INTERFACES)
public PrefixManager prefixManager(RequestInformation requestInformation) {
return new DefaultPrefixManager(null, null, requestInformation.getOntologyIri());
}
开发者ID:VisualDataWeb,项目名称:OntoBench,代码行数:6,代码来源:OwlApiConfig.java
示例11: main
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的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
示例12: testNoChanges
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Testing correctness of the reasoner with respect to ontology changes
*
*/
@Test
public void testNoChanges() throws Exception {
OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// set up resolution of prefixes
PrefixManager pm = new DefaultPrefixManager();
pm.setDefaultPrefix("http://www.example.com/main#");
pm.setPrefix("A:", "http://www.example.com/A#");
pm.setPrefix("B:", "http://www.example.com/B#");
// define query classes
OWLClass mainX = dataFactory.getOWLClass(":X", pm);
OWLClass mainY = dataFactory.getOWLClass(":Y", pm);
OWLClass extA = dataFactory.getOWLClass("A:A", pm);
OWLClass extB = dataFactory.getOWLClass("B:B", pm);
OWLClass extC = dataFactory.getOWLClass("B:C", pm);
// loading the root ontology
OWLOntology root = loadOntology(man, "root.owl");
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(root);
try {
// statistics about the root ontology
assertEquals(root.getAxiomCount(), 3);
// all three ontologies should be in the closure
assertEquals(root.getImportsClosure().size(), 3);
// all axioms from three ontologies should be in the closure
assertEquals(getAxioms(root).size(), 6);
// reasoner queries -- all subclasses are there
assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
mainY));
assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
extA));
assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity(
extB));
assertTrue(reasoner.getSuperClasses(extA, true)
.containsEntity(extB));
assertTrue(reasoner.getSuperClasses(extB, true)
.containsEntity(extC));
} finally {
reasoner.dispose();
}
}
开发者ID:liveontologies,项目名称:elk-reasoner,代码行数:57,代码来源:ElkReasonerTest.java
示例13: testRemovingXY
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Testing correctness of the reasoner with respect to ontology changes
*
* removing an axiom ":X is-a :Y"
*/
@Test
public void testRemovingXY() throws Exception {
OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// set up resolution of prefixes
PrefixManager pm = new DefaultPrefixManager();
pm.setDefaultPrefix("http://www.example.com/main#");
pm.setPrefix("A:", "http://www.example.com/A#");
pm.setPrefix("B:", "http://www.example.com/B#");
// define query classes
OWLClass mainX = dataFactory.getOWLClass(":X", pm);
OWLClass mainY = dataFactory.getOWLClass(":Y", pm);
OWLClass extA = dataFactory.getOWLClass("A:A", pm);
OWLClass extB = dataFactory.getOWLClass("B:B", pm);
OWLClass extC = dataFactory.getOWLClass("B:C", pm);
// loading the root ontology
OWLOntology root = loadOntology(man, "root.owl");
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(root);
try {
// ************************************
// ** removing an axiom ":X is-a :Y"
// ************************************
OWLAxiom axiom = dataFactory.getOWLSubClassOfAxiom(mainX, mainY);
man.removeAxiom(root, axiom);
reasoner.flush();
// the root ontology contains one fewer axioms
assertEquals(root.getAxiomCount(), 2);
// the number of ontologies in the import closure does not change
assertEquals(root.getImportsClosure().size(), 3);
// the total number of axioms reduces
assertEquals(getAxioms(root).size(), 5);
// reasoner queries -- first subsumption is gone
assertFalse(reasoner.getSuperClasses(mainX, true).containsEntity(
mainY));
assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
extA));
assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity(
extB));
assertTrue(reasoner.getSuperClasses(extA, true)
.containsEntity(extB));
assertTrue(reasoner.getSuperClasses(extB, true)
.containsEntity(extC));
} finally {
reasoner.dispose();
}
}
开发者ID:liveontologies,项目名称:elk-reasoner,代码行数:65,代码来源:ElkReasonerTest.java
示例14: testRemovingAB
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Testing correctness of the reasoner with respect to ontology changes
* <p>
* trying to remove "A:A is-a B:B"
* <p>
* Because the removed axiom belongs to the imported ontology and
* not main ontology, the remove does not make any effect. So, we
* should end up with the ontology we have started with.
* <p>
* This test is ignored, because as of OWL API 4.1.3 the removal
* of the axiom is broadcasted even though the axiom is not removed.
*/
@Test
public void testRemovingAB() throws Exception {
OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// set up resolution of prefixes
PrefixManager pm = new DefaultPrefixManager();
pm.setDefaultPrefix("http://www.example.com/main#");
pm.setPrefix("A:", "http://www.example.com/A#");
pm.setPrefix("B:", "http://www.example.com/B#");
// define query classes
OWLClass mainX = dataFactory.getOWLClass(":X", pm);
OWLClass mainY = dataFactory.getOWLClass(":Y", pm);
OWLClass extA = dataFactory.getOWLClass("A:A", pm);
OWLClass extB = dataFactory.getOWLClass("B:B", pm);
OWLClass extC = dataFactory.getOWLClass("B:C", pm);
// loading the root ontology
OWLOntology root = loadOntology(man, "root.owl");
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(root);
try {
// ************************************
// ** trying to remove "A:A is-a B:B"
// ************************************
OWLSubClassOfAxiom axiom = dataFactory.getOWLSubClassOfAxiom(extA, extB);
man.removeAxiom(root, axiom);
reasoner.flush();
// Because the removed axiom belongs to the imported ontology and
// not main ontology, the remove does not make any effect. So, we
// should end up with the ontology we have started with
assertEquals(root.getAxiomCount(), 3);
// all three ontologies should be in the closure
assertEquals(root.getImportsClosure().size(), 3);
// all axioms from three ontologies should be in the closure
assertEquals(getAxioms(root).size(), 6);
// reasoner queries -- all subsumptions are there
assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
mainY));
assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
extA));
assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity(
extB));
assertTrue(reasoner.getSuperClasses(extA, true)
.containsEntity(extB));
assertTrue(reasoner.getSuperClasses(extB, true)
.containsEntity(extC));
} finally {
reasoner.dispose();
}
}
开发者ID:liveontologies,项目名称:elk-reasoner,代码行数:75,代码来源:ElkReasonerTest.java
示例15: testRemovingImpA
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Testing correctness of the reasoner with respect to ontology changes
* <p>
* removing the import declaration for </impA>
*/
@Test
public void testRemovingImpA() throws Exception {
OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// set up resolution of prefixes
PrefixManager pm = new DefaultPrefixManager();
pm.setDefaultPrefix("http://www.example.com/main#");
pm.setPrefix("A:", "http://www.example.com/A#");
pm.setPrefix("B:", "http://www.example.com/B#");
// define query classes
OWLClass mainX = dataFactory.getOWLClass(":X", pm);
OWLClass mainY = dataFactory.getOWLClass(":Y", pm);
OWLClass extA = dataFactory.getOWLClass("A:A", pm);
OWLClass extB = dataFactory.getOWLClass("B:B", pm);
OWLClass extC = dataFactory.getOWLClass("B:C", pm);
// loading the root ontology
OWLOntology root = loadOntology(man, "root.owl");
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(root);
try {
// ************************************
// ** removing the import declaration for </impA>
// ************************************
OWLImportsDeclaration importA = new OWLImportsDeclarationImpl(
IRI.create("http://www.example.com#impA"));
OWLOntologyChange change = new RemoveImport(root, importA);
man.applyChange(change);
reasoner.flush();
// Now the root ontology should not import anything
assertEquals(root.getAxiomCount(), 3);
assertEquals(root.getImportsClosure().size(), 1);
assertEquals(getAxioms(root).size(), 3);
// reasoner queries -- only subsumptions of the root ontology are
// there
assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
mainY));
assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity(
extA));
assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity(
extB));
assertFalse(reasoner.getSuperClasses(extA, true).containsEntity(
extB));
assertFalse(reasoner.getSuperClasses(extB, true).containsEntity(
extC));
} finally {
reasoner.dispose();
}
}
开发者ID:liveontologies,项目名称:elk-reasoner,代码行数:67,代码来源:ElkReasonerTest.java
示例16: testChangesToOtherOntologies
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Testing correctness of the reasoner when changes are made to other, imported or not, ontologies
*
*/
@Test
public void testChangesToOtherOntologies() throws Exception {
OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// set up resolution of prefixes
PrefixManager pm = new DefaultPrefixManager();
pm.setDefaultPrefix("http://www.example.com/main#");
pm.setPrefix("A:", "http://www.example.com/A#");
pm.setPrefix("B:", "http://www.example.com/B#");
// define query classes
OWLClass mainY = dataFactory.getOWLClass(":Y", pm);
OWLClass extA = dataFactory.getOWLClass("A:A", pm);
OWLClass extB = dataFactory.getOWLClass("B:B", pm);
OWLClass extC = dataFactory.getOWLClass("B:C", pm);
// loading the root ontology
OWLOntology root = loadOntology(man, "root.owl");
// the imported ontologies must be loaded
OWLOntology ontoA = man.getOntology(IRI.create("http://www.example.com/A"));
OWLOntology ontoB = man.getOntology(IRI.create("http://www.example.com/B"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(root);
try {
assertTrue(reasoner.getSuperClasses(extA, false).containsEntity(
extC));
assertTrue(reasoner.getSuperClasses(mainY, false).containsEntity(
extC));
// ************************************
// ** removing an axiom "A:A is-a B:B" from impA
// ************************************
OWLAxiom axiom = dataFactory.getOWLSubClassOfAxiom(extA, extB);
man.removeAxiom(ontoA, axiom);
reasoner.flush();
assertFalse(reasoner.getSuperClasses(extA, false).containsEntity(
extC));
// put it back
man.addAxiom(ontoA, axiom);
reasoner.flush();
assertTrue(reasoner.getSuperClasses(extA, false).containsEntity(
extC));
// ************************************
// ** removing an axiom "B:B is-a B:C" from impB
// ************************************
axiom = dataFactory.getOWLSubClassOfAxiom(extB, extC);
man.removeAxiom(ontoB, axiom);
reasoner.flush();
assertFalse(reasoner.getSuperClasses(mainY, false).containsEntity(
extC));
}
finally {
reasoner.dispose();
}
}
开发者ID:liveontologies,项目名称:elk-reasoner,代码行数:71,代码来源:ElkReasonerTest.java
示例17: main
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
// create new empty ontology
OWLOntology ontology = manager.createOntology(IRI.create(DOCUMENT_IRI));
//set up prefixes
DefaultPrefixManager pm = new DefaultPrefixManager();
pm.setDefaultPrefix(DOCUMENT_IRI + "#");
pm.setPrefix("var:", "urn:swrl#");
//class declarations
OWLClass personClass = factory.getOWLClass(":Person", pm);
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(personClass));
OWLClass manClass = factory.getOWLClass(":Man", pm);
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(manClass));
OWLClass englishProgrammerClass = factory.getOWLClass(":EnglishProgrammer", pm);
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(englishProgrammerClass));
//named individuals declarations
OWLNamedIndividual english = createIndividual(ontology, pm, manager, ":English");
OWLNamedIndividual comp = createIndividual(ontology, pm, manager, ":Computer-Programming");
OWLNamedIndividual john = createIndividual(ontology, pm, manager, ":John");
//annotated subclass axiom
OWLAnnotationProperty annotationProperty = factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT.getIRI());
OWLAnnotationValue value = factory.getOWLLiteral("States that every man is a person.");
OWLAnnotation annotation = factory.getOWLAnnotation(annotationProperty, value);
OWLSubClassOfAxiom subClassOfAxiom = factory.getOWLSubClassOfAxiom(manClass, personClass, Collections.singleton(annotation));
manager.addAxiom(ontology, subClassOfAxiom);
//object property declaration
OWLObjectProperty speaksLanguageProperty = createObjectProperty(ontology, pm, manager, ":speaksLanguage");
OWLObjectProperty hasKnowledgeOfProperty = createObjectProperty(ontology, pm, manager, ":hasKnowledgeOf");
//axiom - John is a Person
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(personClass, john));
//axiom - John speaksLanguage English
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(speaksLanguageProperty, john, english));
//axiom - John hasKnowledgeOf Computer-Programming
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasKnowledgeOfProperty, john, comp));
//axiom - EnglishProgrammers is equivalent to intersection of classes
OWLObjectHasValue c1 = factory.getOWLObjectHasValue(speaksLanguageProperty, english);
OWLObjectHasValue c2 = factory.getOWLObjectHasValue(hasKnowledgeOfProperty, comp);
OWLObjectIntersectionOf andExpr = factory.getOWLObjectIntersectionOf(personClass, c1, c2);
manager.addAxiom(ontology, factory.getOWLEquivalentClassesAxiom(englishProgrammerClass, andExpr));
//SWRL rule - Person(?x),speaksLanguage(?x,English),hasKnowledgeOf(?x,Computer-Programming)->englishProgrammer(?x)
SWRLVariable varX = factory.getSWRLVariable(pm.getIRI("var:x"));
Set<SWRLAtom> body = new LinkedHashSet<>();
body.add(factory.getSWRLClassAtom(personClass, varX));
body.add(factory.getSWRLObjectPropertyAtom(speaksLanguageProperty, varX, factory.getSWRLIndividualArgument(english)));
body.add(factory.getSWRLObjectPropertyAtom(hasKnowledgeOfProperty, varX, factory.getSWRLIndividualArgument(comp)));
Set<? extends SWRLAtom> head = Collections.singleton(factory.getSWRLClassAtom(englishProgrammerClass, varX));
SWRLRule swrlRule = factory.getSWRLRule(body, head);
manager.addAxiom(ontology, swrlRule);
//save to a file
FunctionalSyntaxDocumentFormat ontologyFormat = new FunctionalSyntaxDocumentFormat();
ontologyFormat.copyPrefixesFrom(pm);
manager.saveOntology(ontology, ontologyFormat, IRI.create(new File("example.owl").toURI()));
//reason
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology, new SimpleConfiguration());
for (OWLNamedIndividual person : reasoner.getInstances(personClass, false).getFlattened()) {
System.out.println("person : " + renderer.render(person));
}
for (OWLNamedIndividual englishProgrammer : reasoner.getInstances(englishProgrammerClass, false).getFlattened()) {
System.out.println("englishProgrammer : " + renderer.render(englishProgrammer));
}
}
开发者ID:martin-kuba,项目名称:owl2-swrl-tutorial,代码行数:78,代码来源:CreateOntologyInCodeExample.java
示例18: createIndividual
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
private static OWLNamedIndividual createIndividual(OWLOntology ontology, DefaultPrefixManager pm, OWLOntologyManager manager, String name) {
OWLDataFactory factory = manager.getOWLDataFactory();
OWLNamedIndividual individual = factory.getOWLNamedIndividual(name, pm);
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(individual));
return individual;
}
开发者ID:martin-kuba,项目名称:owl2-swrl-tutorial,代码行数:7,代码来源:CreateOntologyInCodeExample.java
示例19: loadOntology
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
/**
* Load the root ontology and all imports and apply normalization.
*/
private void loadOntology() {
clearState();
axioms = new OWLAxioms();
Collection<OWLOntology> importClosure = rootOntology.getImportsClosure();
if(configuration.getDomainIndividuals() == null) {
configuration.setDomainIndividuals(rootOntology.getIndividualsInSignature(Imports.INCLUDED));
}
normalization = new OWLNormalization(rootOntology.getOWLOntologyManager().getOWLDataFactory(), axioms, 0, configuration.getDomainIndividuals());
for (OWLOntology ontology : importClosure) {
normalization.processOntology(ontology);
}
axioms.m_namedIndividuals.clear();
axioms.m_namedIndividuals.addAll(configuration.getDomainIndividuals());
try {
tmpFile = File.createTempFile("wolpertinger-base-program", ".lp");
tmpFile.deleteOnExit();
output = new PrintWriter(tmpFile);
naiveTranslation = new NaiveTranslation(configuration, output);
naiveTranslation.translateOntology(axioms);
} catch (IOException e) {
e.printStackTrace();
}
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
PrefixManager pManager = new DefaultPrefixManager();
OWLClassExpression thing = factory.getOWLClass("owl:Thing", pManager);
for (OWLNamedIndividual individual : axioms.m_namedIndividuals) {
OWLClassAssertionAxiom assertion = factory.getOWLClassAssertionAxiom(thing, individual);
manager.addAxiom(rootOntology, assertion);
}
enumerator = new ClingoModelEnumerator(new String[] {tmpFile.getAbsolutePath()});
}
开发者ID:wolpertinger-reasoner,项目名称:Wolpertinger,代码行数:45,代码来源:Wolpertinger.java
示例20: DLQueryParser
import org.semanticweb.owlapi.util.DefaultPrefixManager; //导入依赖的package包/类
public DLQueryParser(OWLOntology rootOntology) {
this(rootOntology, new DefaultPrefixManager());
}
开发者ID:isa-group,项目名称:ppinot,代码行数:4,代码来源:DLQueryParser.java
注:本文中的org.semanticweb.owlapi.util.DefaultPrefixManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论