All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clarkparsia.pellint.lintpattern.ontology.EquivalentAndSubclassAxiomPattern Maven / Gradle / Ivy

The newest version!
// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. 
// This source code is available under the terms of the Affero General Public License v3.
//
// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions.
// Questions, comments, or requests for clarification: [email protected]

package com.clarkparsia.pellint.lintpattern.ontology;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;

import com.clarkparsia.owlapiv3.OWL;
import com.clarkparsia.pellint.format.CompactClassLintFormat;
import com.clarkparsia.pellint.format.LintFormat;
import com.clarkparsia.pellint.model.Lint;
import com.clarkparsia.pellint.model.LintFixer;
import com.clarkparsia.pellint.util.OWLUtil;

/**
 * 

* Title: *

*

* Description: *

*

* Copyright: Copyright (c) 2008 *

*

* Company: Clark & Parsia, LLC. *

* * @author Harris Lin */ public class EquivalentAndSubclassAxiomPattern implements OntologyLintPattern { private static final LintFormat DEFAULT_LINT_FORMAT = new CompactClassLintFormat(); public String getName() { return getClass().getSimpleName(); } public String getDescription() { return "A named concept appears in equivalent axiom(s) and on the left-hand side of a subclass axiom"; } public boolean isFixable() { return true; } public LintFormat getDefaultLintFormat() { return DEFAULT_LINT_FORMAT; } public List match(OWLOntology ontology) { List allLints = new ArrayList(); for (OWLClass owlClass : ontology.getClassesInSignature()) { Set equivalents = ontology.getEquivalentClassesAxioms(owlClass); Set subclasses = ontology.getSubClassAxiomsForSubClass(owlClass); Set badEquivalents = new HashSet(); for (OWLEquivalentClassesAxiom equivalent : equivalents) { for (OWLClassExpression desc : equivalent.getClassExpressions()) { if (OWLUtil.isComplex(desc)) { badEquivalents.add(equivalent); break; } } } if (badEquivalents.isEmpty()) continue; if (badEquivalents.size() == 1 && subclasses.isEmpty()) continue; Lint lint = new Lint(this, ontology); lint.addParticipatingClass(owlClass); lint.addAllParticipatingAxioms(badEquivalents); lint.addAllParticipatingAxioms(subclasses); Set fixedAxioms = fixEquivalentAxioms(owlClass, badEquivalents); LintFixer fixer = new LintFixer(badEquivalents, fixedAxioms); lint.setLintFixer(fixer); allLints.add(lint); } return allLints; } private static Set fixEquivalentAxioms(OWLClass classToFix, Set axioms) { Set fixes = new HashSet(); for (OWLEquivalentClassesAxiom axiom : axioms) { Set descs = new HashSet(axiom.getClassExpressions()); descs.remove(classToFix); if (descs.size() == 1) { fixes.add(OWL.subClassOf(classToFix, descs.iterator().next())); } else { fixes.add(OWL.equivalentClasses(descs)); fixes.add(OWL.subClassOf(classToFix, OWL.and(descs))); } } return fixes; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy