本文整理匯總了Java中org.semanticweb.owlapi.model.OWLOntologyManager.applyChange方法的典型用法代碼示例。如果您正苦於以下問題:Java OWLOntologyManager.applyChange方法的具體用法?Java OWLOntologyManager.applyChange怎麽用?Java OWLOntologyManager.applyChange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.semanticweb.owlapi.model.OWLOntologyManager
的用法示例。
在下文中一共展示了OWLOntologyManager.applyChange方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: translate
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Translate the given {@link GafDocument} into an OWL representation of the LEGO model.
*
* @param gaf
* @return lego ontology
* @throws OWLException
* @throws UnknownIdentifierException
*/
public OWLOntology translate(GafDocument gaf) throws OWLException, UnknownIdentifierException {
final OWLOntologyManager m = graph.getManager();
OWLOntology lego = m.createOntology(IRI.generateDocumentIRI());
OWLOntology sourceOntology = graph.getSourceOntology();
OWLOntologyID ontologyID = sourceOntology.getOntologyID();
if (ontologyID != null) {
Optional<IRI> ontologyIRI = ontologyID.getOntologyIRI();
if (ontologyIRI.isPresent()) {
OWLDataFactory f = m.getOWLDataFactory();
OWLImportsDeclaration importDeclaration = f.getOWLImportsDeclaration(ontologyIRI.get());
m.applyChange(new AddImport(lego, importDeclaration ));
}
}
translate(gaf.getGeneAnnotations(), lego);
return lego;
}
示例2: addPTBoxConstraints
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
protected void addPTBoxConstraints(OWLOntology ontology, PTBox ptbox,
OWLOntologyManager manager, OWLDataFactory factory) {
ConceptConverter converter = new ConceptConverter(ptbox.getClassicalKnowledgeBase(), factory);
for (ConditionalConstraint cc : ptbox.getDefaultConstraints()) {
OWLAnnotationProperty annProp = factory.getOWLAnnotationProperty( IRI.create(Constants.CERTAINTY_ANNOTATION_URI ));
OWLAnnotationValue annValue = factory.getOWLStringLiteral( cc.getLowerBound() + ";" + cc.getUpperBound() );
OWLAnnotation annotation = factory.getOWLAnnotation( annProp, annValue );
OWLClassExpression clsEv = (OWLClassExpression)converter.convert( cc.getEvidence() );
OWLClassExpression clsCn = (OWLClassExpression)converter.convert( cc.getConclusion() );
OWLAxiom axiom = factory.getOWLSubClassOfAxiom( clsEv, clsCn, Collections.singleton( annotation ) );
try {
manager.applyChange( new AddAxiom(ontology, axiom) );
} catch( OWLOntologyChangeException e ) {
e.printStackTrace();
}
}
}
示例3: handleVersion
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private String handleVersion(String ontologyId) {
// TODO add an option to set/overwrite the version manually via command-line
// TODO re-use/create a method in obo2owl for creating an version IRI
String version;
OWLOntology ontology = mooncat.getOntology();
OWLOntologyID owlOntologyId = ontology.getOntologyID();
Optional<IRI> versionIRI = owlOntologyId.getVersionIRI();
if (versionIRI.isPresent() == false) {
// set a new version IRI using the current date
version = OntologyVersionTools.format(new Date());
versionIRI = Optional.of(IRI.create(Obo2OWLConstants.DEFAULT_IRI_PREFIX+ontologyId+"/"+oortConfig.getVersionSubdirectory()+"/"+version+"/"+ontologyId+".owl"));
OWLOntologyManager m = mooncat.getManager();
m.applyChange(new SetOntologyID(ontology, new OWLOntologyID(owlOntologyId.getOntologyIRI(), versionIRI)));
}
else {
String versionIRIString = versionIRI.get().toString();
version = OntologyVersionTools.parseVersion(versionIRIString);
if (version == null) {
// use the whole IRI? escape?
logError("Could not parse a version from ontolgy version IRI: "+versionIRIString);
version = versionIRIString;
}
}
return version;
}
示例4: handleSupportOntologies
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private static List<OWLOntologyChange> handleSupportOntologies(OWLGraphWrapper graph)
{
OWLOntology ontology = graph.getSourceOntology();
OWLOntologyManager manager = ontology.getOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
List<OWLOntologyChange> removeImportChanges = new ArrayList<OWLOntologyChange>();
Set<OWLOntology> supportOntologySet = graph.getSupportOntologySet();
for (OWLOntology support : supportOntologySet) {
Optional<IRI> supportIRI = support.getOntologyID().getOntologyIRI();
if(supportIRI.isPresent()) {
IRI ontologyIRI = supportIRI.get();
OWLImportsDeclaration importDeclaration = factory.getOWLImportsDeclaration(ontologyIRI);
ChangeApplied status = manager.applyChange(new AddImport(ontology, importDeclaration));
if (ChangeApplied.SUCCESSFULLY == status) {
// the change was successful, create remove import for later
removeImportChanges.add(new RemoveImport(ontology, importDeclaration));
}
}
}
return removeImportChanges;
}
示例5: exportModel
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Export the ABox, will try to set the ontologyID to the given modelId (to
* ensure import assumptions are met)
*
* @param model
* @param ontologyFormat
* @return modelContent
* @throws OWLOntologyStorageException
*/
public String exportModel(ModelContainer model, OWLDocumentFormat ontologyFormat) throws OWLOntologyStorageException {
final OWLOntology aBox = model.getAboxOntology();
final OWLOntologyManager manager = aBox.getOWLOntologyManager();
// make sure the exported ontology has an ontologyId and that it maps to the modelId
final IRI expectedABoxIRI = model.getModelId();
Optional<IRI> currentABoxIRI = aBox.getOntologyID().getOntologyIRI();
if (currentABoxIRI.isPresent() == false) {
manager.applyChange(new SetOntologyID(aBox, expectedABoxIRI));
}
else {
if (expectedABoxIRI.equals(currentABoxIRI) == false) {
OWLOntologyID ontologyID = new OWLOntologyID(Optional.of(expectedABoxIRI), Optional.of(expectedABoxIRI));
manager.applyChange(new SetOntologyID(aBox, ontologyID));
}
}
// write the model into a buffer
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
if (ontologyFormat != null) {
manager.saveOntology(aBox, ontologyFormat, outputStream);
}
else {
manager.saveOntology(aBox, outputStream);
}
// extract the string from the buffer
String modelString = outputStream.toString();
return modelString;
}
示例6: addPABoxConstraints
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
protected void addPABoxConstraints(OWLOntology ontology, PABox pabox, KnowledgeBase kb,
OWLOntologyManager manager, OWLDataFactory factory) {
ConceptConverter converter = new ConceptConverter(kb, factory);
for (Map.Entry<ATermAppl, Set<ConditionalConstraint>> entry : pabox.getConstraintsMap().entrySet()) {
for (ConditionalConstraint cc : entry.getValue()) {
OWLAnnotationProperty annProp = factory.getOWLAnnotationProperty( IRI.create( Constants.CERTAINTY_ANNOTATION_URI ));
OWLAnnotationValue annValue = factory.getOWLStringLiteral( cc.getLowerBound() + ";" + cc.getUpperBound() );
OWLAnnotation annotation = factory.getOWLAnnotation( annProp, annValue );
OWLIndividual indiv = factory.getOWLNamedIndividual( IRI.create( entry.getKey().getName()) );
OWLClassExpression clsCn = (OWLClassExpression)converter.convert( cc.getConclusion() );
OWLAxiom axiom = factory.getOWLClassAssertionAxiom( clsCn, indiv, Collections.singleton( annotation ) );
try {
manager.applyChange( new AddAxiom(ontology, axiom) );
} catch( OWLOntologyChangeException e ) {
e.printStackTrace();
}
}
}
}
示例7: mergeOntology
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public void mergeOntology(OWLOntology extOnt, LabelPolicy labelPolicy) throws OWLOntologyCreationException {
OWLOntologyManager manager = getManager();
LOG.info("Merging "+extOnt+" policy: "+labelPolicy);
for (OWLAxiom axiom : extOnt.getAxioms()) {
if (labelPolicy != LabelPolicy.ALLOW_DUPLICATES) {
if (axiom instanceof OWLAnnotationAssertionAxiom) {
OWLAnnotationAssertionAxiom aa = (OWLAnnotationAssertionAxiom)axiom;
if (aa.getProperty().isLabel()) {
OWLAnnotationSubject subj = aa.getSubject();
if (subj instanceof IRI) {
Optional<OWLLiteral> label = null;
for (OWLAnnotationAssertionAxiom a1 : sourceOntology.getAnnotationAssertionAxioms(subj)) {
if (a1.getProperty().isLabel()) {
label = a1.getValue().asLiteral();
}
}
if (label != null && label.isPresent()) {
if (labelPolicy == LabelPolicy.PRESERVE_SOURCE) {
LOG.info("Preserving existing label:" +subj+" "+label+" // ditching: "+axiom);
continue;
}
if (labelPolicy == LabelPolicy.PRESERVE_EXT) {
LOG.info("Replacing:" +subj+" "+label+" with: "+axiom);
LOG.error("NOT IMPLEMENTED");
}
}
}
}
}
}
manager.applyChange(new AddAxiom(sourceOntology, axiom));
}
for (OWLImportsDeclaration oid: extOnt.getImportsDeclarations()) {
manager.applyChange(new AddImport(sourceOntology, oid));
}
addCommentToOntology(sourceOntology, "Includes "+summarizeOntology(extOnt));
}
示例8: test
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
@Test
public void test() throws Exception {
// load the base ontology
ParserWrapper pw = new ParserWrapper();
OWLOntology direct = pw.parseOBO(getResourceIRIString("graph/xref_test.obo"));
OWLGraphWrapper directGraph = new OWLGraphWrapper(direct);
// check that the test class has the expected number of xrefs
OWLClass c = directGraph.getOWLClassByIdentifier("FOO:0001");
List<String> directDefXrefs = directGraph.getDefXref(c);
assertEquals(2, directDefXrefs.size());
List<String> directXrefs = directGraph.getXref(c);
assertEquals(2, directXrefs.size());
// create an ontology using an import
OWLOntologyManager manager = pw.getManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology importer = manager.createOntology();
OWLImportsDeclaration importDeclaration = factory.getOWLImportsDeclaration(direct.getOntologyID().getOntologyIRI().orNull());
manager.applyChange(new AddImport(importer, importDeclaration));
OWLGraphWrapper importerGraph = new OWLGraphWrapper(importer);
// check that the wrapper uses also imports for lookups of xrefs
List<String> importedDefXrefs = importerGraph.getDefXref(c);
assertEquals(2, importedDefXrefs.size());
List<String> importedXrefs = importerGraph.getXref(c);
assertEquals(2, importedXrefs.size());
}
示例9: testEdgeCache
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
@Test
public void testEdgeCache() throws Exception {
OWLGraphWrapper g = getGraph("graph/cache-test.obo");
OWLOntology o = g.getSourceOntology();
OWLOntologyManager m = o.getOWLOntologyManager();
OWLDataFactory f = m.getOWLDataFactory();
OWLClass orphan = g.getOWLClassByIdentifier("FOO:0004");
OWLClass root = g.getOWLClassByIdentifier("FOO:0001");
g.getEdgesBetween(orphan, root); //just to trigger the cache
OWLSubClassOfAxiom ax = f.getOWLSubClassOfAxiom(orphan, root);
AddAxiom addAx = new AddAxiom(o, ax);
m.applyChange(addAx);
Set<OWLGraphEdge> edges = g.getEdgesBetween(orphan, root);
assertNotNull(edges);
assertEquals(0, edges.size());
g.clearCachedEdges(); // test clear cache method
edges = g.getEdgesBetween(orphan, root);
assertNotNull(edges);
assertEquals(1, edges.size());
}
示例10: addAxiom
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private void addAxiom(String info, OWLAxiom ax, OWLOntology ont, OWLOntologyManager manager, OWLDataFactory factory, List<String> reasonerReportLines) {
if (oortConfig.isUseIsInferred()) {
ax = AxiomAnnotationTools.markAsInferredAxiom(ax, factory);
}
manager.applyChange(new AddAxiom(ont, ax));
String ppax = owlpp.render(ax);
String rptLine = info+"\t"+ppax;
reasonerReportLines.add(rptLine);
}
示例11: annotate
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Convenience method for adding an annotation assertion to the
* ontology itself, taking a CURIE for the property and an Boolean literal.
*
* @param ontology the current ontology
* @param propertyCURIE will be expanded to the full annotation
* property IRI
* @param value the literal value of the annotation
* @return the annotation axiom
*/
protected static OWLAnnotation annotate(OWLOntology ontology,
String propertyCURIE, IRI value) {
OWLOntologyManager manager = ontology.getOWLOntologyManager();
OWLDataFactory dataFactory = manager.getOWLDataFactory();
IRI iri = format.getIRI(propertyCURIE);
OWLAnnotationProperty property =
dataFactory.getOWLAnnotationProperty(iri);
OWLAnnotation annotation = dataFactory.getOWLAnnotation(
property, value);
manager.applyChange(
new AddOntologyAnnotation(ontology, annotation));
return annotation;
}
示例12: testUpdateImports
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
@Test
public void testUpdateImports() throws Exception {
final OWLOntologyManager m = OWLManager.createOWLOntologyManager();
final OWLDataFactory f = m.getOWLDataFactory();
// setup other import
final IRI other = IRI.generateDocumentIRI();
m.createOntology(other);
// setup additional
final IRI add1 = IRI.generateDocumentIRI();
m.createOntology(add1);
final IRI add2 = IRI.generateDocumentIRI();
m.createOntology(add2);
final Set<IRI> additional = new HashSet<IRI>();
additional.add(add1);
additional.add(add2);
// setup tbox
final IRI tboxIRI = IRI.generateDocumentIRI();
m.createOntology(tboxIRI);
// setup abox
final OWLOntology abox = m.createOntology(IRI.generateDocumentIRI());
// add initial imports to abox
m.applyChange(new AddImport(abox, f.getOWLImportsDeclaration(other)));
// update imports
CoreMolecularModelManager.updateImports(abox, tboxIRI, additional);
// check the resulting imports
Set<OWLImportsDeclaration> declarations = abox.getImportsDeclarations();
assertEquals(4, declarations.size());
Set<IRI> declaredImports = new HashSet<IRI>();
for (OWLImportsDeclaration importsDeclaration : declarations) {
declaredImports.add(importsDeclaration.getIRI());
}
assertEquals(4, declaredImports.size());
assertTrue(declaredImports.contains(tboxIRI));
assertTrue(declaredImports.contains(add1));
assertTrue(declaredImports.contains(add1));
assertTrue(declaredImports.contains(other));
}
示例13: testRemovingImpA
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的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();
}
}
示例14: addComment
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private void addComment(String comment, OWLOntology ontology) {
final OWLOntologyManager manager = ontology.getOWLOntologyManager();
final OWLDataFactory factory = manager.getOWLDataFactory();
OWLAnnotation ontAnn = factory.getOWLAnnotation(factory.getRDFSComment(), factory.getOWLLiteral(comment));
manager.applyChange(new AddOntologyAnnotation(ontology, ontAnn));
}
示例15: makeUnionUsingReflexiveProperty
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* makes a reduced union expression.
*
* Uses the following two reduction rules:
*
* (r1 some X) U (r2 some Y) ==> lcs(r1,r2) some MakeUnionOf(X,Y)
* (r1 some X) U X ==> reflexive-version-of-r1 some X
*
* TODO: test for (r some r some X) u (r some X) cases. needs to be done over final expression.
*
* if a reduced form cannot be made, returns null
*
* @param xa
* @param xb
* @return class expression
*/
private OWLClassExpression makeUnionUsingReflexiveProperty(OWLClassExpression xa, OWLClassExpression xb) {
LOG.info("testing if there is a more compact union expression for "+xa+" ++ "+xb);
OWLDataFactory df = graph.getDataFactory();
if (xa instanceof OWLQuantifiedRestriction) {
// TODO - check before casting
OWLObjectProperty prop = (OWLObjectProperty) ((OWLQuantifiedRestriction) xa).getProperty();
OWLClassExpression xaRest = (OWLClassExpression) ((OWLQuantifiedRestriction)xa).getFiller();
if (xb instanceof OWLQuantifiedRestriction) {
OWLObjectPropertyExpression p2 =
propertySubsumer(prop,
((OWLQuantifiedObjectRestriction) xb).getProperty());
if (p2 != null) {
OWLClassExpression xbRest = (OWLClassExpression) ((OWLQuantifiedRestriction)xb).getFiller();
OWLClassExpression x = makeUnionWithReduction(xaRest,xbRest);
// todo - mixing some and all
if (xa instanceof OWLObjectSomeValuesFrom)
return df.getOWLObjectSomeValuesFrom(p2,x);
else if (xa instanceof OWLObjectAllValuesFrom)
return df.getOWLObjectAllValuesFrom(p2, x);
}
}
LOG.info(" test: "+xaRest+" == "+xb);
if (xaRest.equals(xb)) {
LOG.info(" TRUE: "+xaRest+" == "+xb);
OWLObjectProperty rprop = null;
if (graph.getIsReflexive(prop)) {
rprop = prop;
}
if (forceReflexivePropertyCreation) {
OWLOntologyManager manager = graph.getManager();
OWLOntology ont = graph.getSourceOntology();
rprop =
df.getOWLObjectProperty(IRI.create(prop.getIRI().toString()+"_reflexive"));
manager.applyChange(new AddAxiom(ont, df.getOWLSubObjectPropertyOfAxiom(prop, rprop)));
manager.applyChange(new AddAxiom(ont, df.getOWLTransitiveObjectPropertyAxiom(rprop)));
LOG.info(" reflexive prop:"+rprop);
}
if (rprop != null) {
if (xa instanceof OWLObjectSomeValuesFrom)
return df.getOWLObjectSomeValuesFrom(rprop,xb);
else if (xa instanceof OWLObjectAllValuesFrom)
return df.getOWLObjectAllValuesFrom(rprop, xb);
}
}
}
return null;
}