Java 类org.semanticweb.owlapi.model.RemoveImport 实例源码

项目:owltools    文件:OWLGraphWrapperBasic.java   
public void mergeImportClosure(boolean isRemovedImportsDeclarations) throws OWLOntologyCreationException {
    OWLOntologyManager manager = getManager();
    Set<OWLOntology> imports = sourceOntology.getImportsClosure();
    for (OWLOntology o : imports) {
        if (o.equals(sourceOntology))
            continue;

        String comment = "Includes "+summarizeOntology(o);
        LOG.info(comment);
        addCommentToOntology(sourceOntology, comment);

        manager.addAxioms(sourceOntology, o.getAxioms());
    }
    Set<OWLImportsDeclaration> oids = sourceOntology.getImportsDeclarations();
    for (OWLImportsDeclaration oid : oids) {
        RemoveImport ri = new RemoveImport(sourceOntology, oid);
        getManager().applyChange(ri);
    }
}
项目:owltools    文件:OWLGraphWrapperBasic.java   
/**
 * Merge a specific ontology from the import closure into the main ontology.
 * Removes the import statement.
 * 
 * @param ontologyIRI id of the ontology to merge
 * @throws OWLOntologyCreationException
 */
public void mergeSpecificImport(IRI ontologyIRI) throws OWLOntologyCreationException {
    OWLOntologyManager manager = getManager();
    Set<OWLOntology> imports = sourceOntology.getImportsClosure();
    for (OWLOntology o : imports) {
        if (o.equals(sourceOntology))
            continue;
        Optional<IRI> currentIRI = o.getOntologyID().getOntologyIRI();
        if (currentIRI.isPresent() && currentIRI.get().equals(ontologyIRI)) {
            String comment = "Includes "+summarizeOntology(o);
            LOG.info(comment);
            addCommentToOntology(sourceOntology, comment);
            manager.addAxioms(sourceOntology, o.getAxioms());   
        }
    }
    Set<OWLImportsDeclaration> oids = sourceOntology.getImportsDeclarations();
    for (OWLImportsDeclaration oid : oids) {
        if (ontologyIRI.equals(oid.getIRI())) {
            RemoveImport ri = new RemoveImport(sourceOntology, oid);
            getManager().applyChange(ri);
        }
    }
}
项目:owltools    文件:AssertInferenceTool.java   
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;
}
项目:sdlnot-rules    文件:SparqlDLNotRulesController.java   
@Override
public void updateOntology( OWLOntology generatedOntology, 
        IRI generatedOntologyIRI, 
        IRI previousOntologyIRI, 
        URI physicalURI) {
    final OWLModelManager mm = getOWLModelManager();
    IRI iri = generatedOntologyIRI;
    OWLOntology generatedOntologyToDelete = null;
    final List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    final Collection<OWLOntology> ontologies = mm.getOntologies();
    for (OWLOntology oo : ontologies) {
        if (iri.equals(oo.getOntologyID().getOntologyIRI())) {
            log.info("Removing ontology " + iri);
            generatedOntologyToDelete = oo;
        }
        changes.add(new RemoveImport(oo, getOWLOntologyManager().getOWLDataFactory()
                .getOWLImportsDeclaration(iri)));
    }
    mm.applyChanges(changes);
    changes.clear();

    if (generatedOntologyToDelete != null) {
        if ( !mm.removeOntology(generatedOntologyToDelete) ) {
            log.info("Removing ontology " + generatedOntologyToDelete.getOntologyID() + " NOT succesful.");
        }
    }

    changes.add(new SetOntologyID(generatedOntology, iri));
    changes.add(new AddImport(generatedOntology, mm.getOWLDataFactory()
            .getOWLImportsDeclaration(previousOntologyIRI)));
    mm.applyChanges(changes);   
    mm.setPhysicalURI(generatedOntology, physicalURI);      
}
项目:sdlnot-rules    文件:SparqlDLNotRulesCLIController.java   
@Override
public void updateOntology(
        OWLOntology generatedOntology, IRI generatedOntologyIRI, IRI previousOntologyIRI,
        URI physicalURI) {
    IRI iri = generatedOntologyIRI;
    OWLOntology generatedOntologyToDelete = null;

    final List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    final Collection<OWLOntology> ontologies = m.getOntologies();
    for (OWLOntology oo : ontologies) {
        if (iri.equals(oo.getOntologyID().getOntologyIRI())) {
            log.info("Removing ontology " + iri);
            generatedOntologyToDelete = oo;
        }
        changes.add(new RemoveImport(oo, getOWLOntologyManager()
                .getOWLDataFactory().getOWLImportsDeclaration(iri)));
    }
    m.applyChanges(changes);
    changes.clear();

    if (generatedOntologyToDelete != null) {
        m.removeOntology(generatedOntologyToDelete);
    }

    changes.add(new SetOntologyID(generatedOntology, iri));
    changes.add(new AddImport(generatedOntology, m.getOWLDataFactory()
            .getOWLImportsDeclaration(previousOntologyIRI)));
    m.applyChanges(changes);
    m.setOntologyDocumentIRI(generatedOntology, IRI.create(physicalURI));       
    try {
        m.saveOntology(generatedOntology);
    } catch (OWLOntologyStorageException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
项目:minerva    文件:ReverseChangeGenerator.java   
public OWLOntologyChange visit(AddImport addImport) {
    return new RemoveImport(addImport.getOntology(), addImport.getImportDeclaration());
}
项目:minerva    文件:ReverseChangeGenerator.java   
public OWLOntologyChange visit(RemoveImport removeImport) {
    return new AddImport(removeImport.getOntology(), removeImport.getImportDeclaration());
}
项目:elk-reasoner    文件:OwlOntologyChangeProcessorVisitor.java   
@Override
public void visit(RemoveImport change) {
    defaultVisit(change);
}
项目:elk-reasoner    文件:ElkReasonerTest.java   
/**
 * 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();
    }

}
项目:owltools    文件:QuerySubsetGenerator.java   
public void createSubSet(OWLGraphWrapper targetGraph, 
        Set<OWLClass> subset, Set<OWLOntology> toMerge, boolean isExcludeClosure,
        boolean isRemoveDangling) throws OWLOntologyCreationException  {

    OWLOntology targetOntology = targetGraph.getSourceOntology();

    // import axioms set
    Set<OWLAxiom> importAxioms = new HashSet<OWLAxiom>();
    for (OWLOntology mergeOntology : toMerge) {
        for (OWLClass cls : subset) {
            importAxioms.addAll(mergeOntology.getAxioms(cls, Imports.EXCLUDED));
        }
    }

    // remove merge imports
    OWLOntologyManager targetManager = targetOntology.getOWLOntologyManager();
    List<OWLOntologyChange> removeImports = new ArrayList<OWLOntologyChange>();
    for(OWLOntology m : toMerge) {
        removeImports.add(new RemoveImport(targetOntology, new OWLImportsDeclarationImpl(m.getOntologyID().getOntologyIRI().get())));
    }
    targetManager.applyChanges(removeImports);

    // add axiom set to target ontology.
    targetManager.addAxioms(targetOntology, importAxioms);

    LOG.info("Start Mooncat for subset.");
    Mooncat mooncat = new Mooncat(targetGraph);
    for (OWLOntology ont : toMerge) {
        mooncat.addReferencedOntology(ont);
    }

    if (!isExcludeClosure) {
        // create Closure
        Set<OWLAxiom> axioms = mooncat.getClosureAxiomsOfExternalReferencedEntities();
        mooncat.addSubAnnotationProperties(axioms);

        // add missing axioms
        targetManager.addAxioms(targetOntology, axioms);
        LOG.info("Added "+axioms.size()+" axioms to the query ontology");
    }

    if (isRemoveDangling) {
        mooncat.removeDanglingAxioms();
    }

    return;
}
项目:jcel    文件:JcelOntologyChangeVisitorEx.java   
@Override
public Boolean visit(RemoveImport change) {
    Objects.requireNonNull(change);
    return false;
}
项目:ecco    文件:Ecco.java   
/**
 * Remove all imports from the given ontology
 * @param ont   OWL ontology
 */
private void removeImports(OWLOntology ont) {
    for(OWLImportsDeclaration importDecl : ont.getImportsDeclarations())
        ont.getOWLOntologyManager().applyChange(new RemoveImport(ont.getOWLOntologyManager().getImportedOntology(importDecl), importDecl));
}