本文整理汇总了Java中org.semanticweb.owlapi.util.DefaultPrefixManager类的典型用法代码示例。如果您正苦于以下问题:Java DefaultPrefixManager类的具体用法?Java DefaultPrefixManager怎么用?Java DefaultPrefixManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultPrefixManager类属于org.semanticweb.owlapi.util包,在下文中一共展示了DefaultPrefixManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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<>();
}
示例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);
}
}
示例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());
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}