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

项目:ontocomplib    文件:ELIndividualContext.java   
/**
 * Asserts that the given individual is an instance of the complement of the given type.
 * @param type the given type
 * @param indObj the given individual about which the assertion will be made
 * @return <code>true</code> if the assertion is successful
 */
@Override
public boolean addNegatedAttributeToObject(OWLClass type,IndividualObject indObj) {
    OWLClassAssertionAxiom axiom = getFactory().getOWLClassAssertionAxiom(
            ELIndividualObject.getComplement(getOntology(), type),
            indObj.getIdentifier());
    AddAxiom  addAxiom = new AddAxiom(getOntology(),axiom); 
    try {
        getManager().applyChange(addAxiom);
        reClassifyOntology();
        updateObjects(Constants.AFTER_MODIFICATION);
        updateObjectDescriptions(Constants.AFTER_MODIFICATION);
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    getHistory().push(new ClassAssertionChange(this,addAxiom,indObj.getIdentifier(),type,true));
    return true;
}
项目:ontocomplib    文件:IndividualContext.java   
/**
 * Adds a given individual to the ontology as an instance of <code>Thing</code>
 * @param object the given object to be added
 * @return <code>true</code> if the object is successfully added
 */
// @Override
public boolean addIndividualToOntology(OWLNamedIndividual object) {
    OWLClassAssertionAxiom axiom = getFactory().getOWLClassAssertionAxiom(getFactory().getOWLThing(), object);
    AddAxiom  addAxiom = new AddAxiom(getOntology(),axiom); 
    Set<OWLClass> attrs = new HashSet<OWLClass>();
    try {
        getManager().applyChange(addAxiom);
        reClassifyOntology();
        IndividualObject indObj = createIndividualObject(object);
        indObj.updateDescription(Constants.AFTER_MODIFICATION);
        addObject(indObj);
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    attrs.add(getFactory().getOWLThing());
    getHistory().push(new NewIndividualChange(this,addAxiom,object,attrs));
    return true;
}
项目:ontocomplib    文件:IndividualContext.java   
/**
 * Adds a given individual to the ontology as an instance of the conjunction of the 
 * given set of classes
 * @param object the individual to be added
 * @param attributes the set of classes
 * @return <code>true</code> if the individual is successfully added
 */
public boolean addIndividualToOntology(OWLNamedIndividual object, Set<OWLClass> attributes) {
    // OWLObjectIntersectionOf description = toOWLDescription(attributes);
    OWLClassExpression description = toOWLDescription(attributes);
    OWLClassAssertionAxiom axiom = getFactory().getOWLClassAssertionAxiom(description, object);
    AddAxiom  addAxiom = new AddAxiom(getOntology(),axiom); 
    try {
        getManager().applyChange(addAxiom);
        reClassifyOntology();
        IndividualObject indObj = createIndividualObject(object);
        // for (OWLClass attribute : attributes) {
        //  indObj.getDescription().addAttribute(attribute);
        // }
        indObj.getDescription().addAttributes(attributes);
        indObj.updateDescription(Constants.AFTER_MODIFICATION);
        addObject(indObj);
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    getHistory().push(new NewIndividualChange(this,addAxiom,object,attributes));
    return true;
}
项目:ontocomplib    文件:IndividualContext.java   
/**
 * Asserts that the given individual is an instance of the given type.
 * @param type the given type
 * @param indObj the given individual about which the assertion will be made
 * @return <code>true</code> if the assertion is successful
 */
public boolean addAttributeToObject(OWLClass type,IndividualObject indObj) {
    OWLClassAssertionAxiom axiom = getFactory().getOWLClassAssertionAxiom(type, indObj.getIdentifier());
    AddAxiom  addAxiom = new AddAxiom(getOntology(),axiom); 
    try {
        getManager().applyChange(addAxiom);
        reClassifyOntology();
        updateObjects(Constants.AFTER_MODIFICATION);
        updateObjectDescriptions(Constants.AFTER_MODIFICATION);
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    getHistory().push(new ClassAssertionChange(this,addAxiom,indObj.getIdentifier(),type,false));
    return true;
}
项目:ontocomplib    文件:IndividualContext.java   
/**
 * Asserts that the given individual is an instance of the complement of the given type.
 * @param type the given type
 * @param indObj the given individual about which the assertion will be made
 * @return <code>true</code> if the assertion is successful
 */
public boolean addNegatedAttributeToObject(OWLClass type,IndividualObject indObj) {
    OWLClassAssertionAxiom axiom = getFactory().getOWLClassAssertionAxiom(getFactory().getOWLObjectComplementOf(type), indObj.getIdentifier());
    AddAxiom  addAxiom = new AddAxiom(getOntology(),axiom); 
    try {
        getManager().applyChange(addAxiom);
        reClassifyOntology();
        updateObjects(Constants.AFTER_MODIFICATION);
        updateObjectDescriptions(Constants.AFTER_MODIFICATION);
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    getHistory().push(new ClassAssertionChange(this,addAxiom,indObj.getIdentifier(),type,true));
    return true;
}
项目:ontocomplib    文件:CounterExampleCandidateDescriptionChange.java   
public void undo() {
    OWLClassAssertionAxiom axiom = null;
    if (isTypePlus) {
        axiom = theContext.getFactory().getOWLClassAssertionAxiom(changedType, candidate);
    }
    else {
        axiom = theContext.getFactory().getOWLClassAssertionAxiom( 
                theContext.getFactory().getOWLObjectComplementOf(changedType), candidate);
    }
    RemoveAxiom  removeAxiom = new RemoveAxiom(theContext.getOntology(),axiom); 
    try {
        theContext.getManager().applyChange(removeAxiom);
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
项目:pronto    文件:PKBXMLSerializer.java   
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();
        }
    }
}
项目:ontocomplib    文件:ELIndividualContext.java   
/** 
 * Adds a given attribute to the attributes of this context, updates the 'local' set of objects.
 * @param attribute the attribute to be added
 * @return <code>true</code> if the <code>attribute</code> is successfully added
 * @throws IllegalAttributeException if the given attribute is already in the set of 
 * attributes
 */
@Override
public boolean addAttribute(OWLClass attribute) {
    boolean added = getAttributes().add(attribute);
    if (!added) {
        throw new IllegalAttributeException("Attribute " + attribute + " has already been added");
    }
    try {
        for (OWLNamedIndividual individual : getReasoner().getInstances(attribute, false).getFlattened()) {
            IndividualObject o = createIndividualObject(individual);
            o.getDescription().addAttribute(attribute);
            addObject(o);
        }
        // the CEL reasoner is being used
        // add new concept name for the complement of the added attribute
        OWLClass complementOfAttribute = ELIndividualObject.getComplement(getOntology(), attribute);
        // make them disjoint
        Set<OWLClass> disjoint = new HashSet<OWLClass>();
        disjoint.add(attribute);
        disjoint.add(complementOfAttribute);
        OWLDisjointClassesAxiom disjointnessAxiom = getFactory().getOWLDisjointClassesAxiom(disjoint);
        // create a new AddAxiom object
        AddAxiom addAxiom = new AddAxiom(getOntology(),disjointnessAxiom);
        getManager().applyChange(addAxiom);
        reClassifyOntology();
        //TODO
        // updateObjectDescriptions should be overridden for EL contexts
        updateObjectDescriptions(Constants.AFTER_MODIFICATION);
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    return added;
}
项目:ontocomplib    文件:AbstractContextModification.java   
public void undo() {
    RemoveAxiom removeAxiom = new RemoveAxiom(getContext().getOntology(),
            getChange().getAxiom());
    try {
        getContext().getManager().applyChange(removeAxiom);
        // context.reClassifyOntology();
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
项目:ontocomplib    文件:QuestionConfirmedAction.java   
/**
 * Adds the confirmed question to the set of implications of the context, adds the corresponing
 * axiom to the ontology, pushes the change to the history stack and continues exploration with 
 * the next premise computed by using the new set of implications.
 */
@Override
public void actionPerformed(ActionEvent e) {
    logger.info("Expert accepted implication: " + getQuestion());
    // first create the GCI
    OWLSubClassOfAxiom axiom = getContext().getFactory().getOWLSubClassOfAxiom(
            getContext().toOWLDescription(getQuestion().getPremise()),
            getContext().toOWLDescription(getQuestion().getConclusion()));
    // create a new AddAxiom object
    AddAxiom addAxiom = new AddAxiom(getContext().getOntology(),axiom);
    // apply the change
    try {
        // add the new implication to the base
        getContext().getImplications().add(getQuestion());
        // also to the KB as a GCI
        getContext().getManager().applyChange(addAxiom);
        getContext().getHistory().push(new NewSubClassAxiomChange(getContext(),getQuestion(),addAxiom));
        getContext().reClassifyOntology();
        // update objects, update object descriptions
        getContext().updateObjects(Constants.AFTER_MODIFICATION);
        getContext().updateObjectDescriptions(Constants.AFTER_MODIFICATION);
        getContext().continueExploration(getContext().getNextPremise(getQuestion().getPremise()));
    }
    catch (OWLOntologyChangeException x) {
        x.printStackTrace();
        System.exit(-1);
    }

}
项目:pronto    文件:PKBXMLSerializer.java   
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();
            }
        }
    }
}
项目:relex    文件:OWLView.java   
/**
* Print out RelEx relations. All relations shown
* in a binary form.
*
* Example:
*       _subj(throw, John)
*       _obj(throw, ball)
*       tense(throw, past)
*       definite-FLAG(ball, T)
*       noun_number(ball, singular)
*/
public void printRelations(ParsedSentence parse, String sentence, int sentence_id, String ontologyname)
{
    try
    {
        sent = sentence;

        //Add the sentence to Sentence Class
        this.sentence_id = sentence_id;
        sentenceInd = factory.getOWLNamedIndividual(IRI.create(ontologyURI + "#" + "sentence_" + sentence_id));
        //OWLAnnotationProperty p = new OWLAnnotationPropertyImpl(IRI.create(sentence));

        //OWLAnnotation label = factory.getOWLAnnotation(sentence);
        OWLOntologyFormat ontologyFormat = manager.getOntologyFormat(ontology);
        OWLAnnotation label = (OWLAnnotation) factory.getOWLAnnotationProperty(sentence, (PrefixManager) ontologyFormat);

        OWLClassAssertionAxiom sentClass = factory.getOWLClassAssertionAxiom(this.sentence,sentenceInd);
        OWLAnnotationAssertionAxiom labelClass = factory.getOWLAnnotationAssertionAxiom((OWLAnnotationSubject) sentClass, label);
        manager.applyChange(new AddAxiom(ontology, sentClass));
        manager.applyChange(new AddAxiom(ontology, labelClass));

        printRelations(parse, null);

    }
    catch (OWLOntologyChangeException ex)
    {
        Logger.getLogger(OWLView.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:SVoNt    文件:CEXDiffAlgorithm.java   
/**
 * Preparing an Ontology for the EL Description Logic Language used for OWLdiff.
 * It removes Individuals, DataProperties and ObjectProperties
 * 
 * @param man OntologyManager of the Ontology
 * @param ont The Ontology to Prepare
 * @throws OWLOntologyChangeException
 */
private void prepareOntologyForCEX(OWLOntologyManager man, OWLOntology ont) throws OWLOntologyChangeException {
    if (log.isDebugEnabled())
        log.debug("Preparing Ontology for CEX Diff");
    OWLEntityRemover remover = new OWLEntityRemover(man, Collections.singleton(ont));

    // TODO check if this means the same thing as ont.getReferencedIndividuals()
    Set<OWLNamedIndividual> individuals = ont.getIndividualsInSignature();
    if (log.isDebugEnabled())
        log.debug("Removing "+individuals.size()+" Individuals from Ontology");
    for(OWLIndividual ind : individuals) {
        if (ind.isNamed()) {
            ((OWLNamedIndividual)ind).accept(remover);
        } else {
            log.warn("Cannot remove anoynmous individual: " + ind);
        }
    }

    Set<OWLDataProperty> dataProperties = ont.getDataPropertiesInSignature();
    if (log.isDebugEnabled())
        log.debug("Removing "+dataProperties.size()+" DataProperties from Ontology");
    for (OWLDataProperty dp : dataProperties) {
        dp.accept(remover);
    }

    Set<OWLObjectProperty> objectProperties = ont.getObjectPropertiesInSignature();
    if (log.isDebugEnabled())
        log.debug("Removing "+objectProperties.size()+" ObjectProperties from Ontology");
    for (OWLObjectProperty op : objectProperties) {
        op.accept(remover);
    }

    man.applyChanges(remover.getChanges());

    log.debug("Ontology Prepared for CEX");
}
项目:ontocomplib    文件:IndividualContext.java   
private boolean implicationMakesOntologyInconsistent(FCAImplication<OWLClass> imp) {
    boolean retCode = false;
    // first create the GCI
    // OWLSubClassAxiom axiom = getFactory().getOWLSubClassAxiom(
    //      toOWLDescription(imp.getPremise()),
    //      toOWLDescription(imp.getConclusion()));
    OWLSubClassOfAxiom axiom = toOWLSubClassAxiom(imp);

    // create a new AddAxiom object
    AddAxiom addAxiom = new AddAxiom(getOntology(),axiom);
    RemoveAxiom removeAxiom = new RemoveAxiom(getOntology(),axiom);
    // apply the change
    try {
        getManager().applyChange(addAxiom);
        // getReasoner().unloadOntologies(ontologies);
        // getReasoner().loadOntologies(ontologies);
        // reClassifyOntology unloads/loads and classifies
        reClassifyOntology();
        if (getReasoner().isConsistent()) {
            retCode = false;
        }
        else {
            retCode = true;
        }
        getManager().applyChange(removeAxiom);
        // getReasoner().unloadOntologies(ontologies);
        // getReasoner().loadOntologies(ontologies);
        // reClassifyOntology unloads/loads and classifies
        reClassifyOntology();
    }
    catch (OWLOntologyChangeException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    // logger.debug("dnm2");
    // // if (!retCode) {
    //  try {
    //      getManager().applyChange(removeAxiom);
    //      getReasoner().unloadOntologies(ontologies);
    //      getReasoner().loadOntologies(ontologies);
    //  }
    //  catch (OWLOntologyChangeException x) {
    //      x.printStackTrace();
    //      System.exit(-1);
    //  }
    //  catch (OWLReasonerException x) {
    //      x.printStackTrace();
    //      logger.fatal("reasoner exception, exiting...");
    //      System.exit(-1);
    //  }
    //  
    // // }
    return retCode;
}