001package conexp.fx.core.dl; 002 003import java.util.stream.Collectors; 004 005import org.semanticweb.owlapi.apibinding.OWLManager; 006import org.semanticweb.owlapi.model.IRI; 007import org.semanticweb.owlapi.model.OWLDataFactory; 008import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; 009 010/* 011 * #%L 012 * Concept Explorer FX 013 * %% 014 * Copyright (C) 2010 - 2019 Francesco Kriegel 015 * %% 016 * This program is free software: you can redistribute it and/or modify 017 * it under the terms of the GNU General Public License as 018 * published by the Free Software Foundation, either version 3 of the 019 * License, or (at your option) any later version. 020 * 021 * This program is distributed in the hope that it will be useful, 022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 024 * GNU General Public License for more details. 025 * 026 * You should have received a copy of the GNU General Public 027 * License along with this program. If not, see 028 * <http://www.gnu.org/licenses/gpl-3.0.html>. 029 * #L% 030 */ 031 032import conexp.fx.core.util.UnicodeSymbols; 033 034public class ELConceptInclusion { 035 036 private static final OWLDataFactory df = OWLManager.getOWLDataFactory(); 037 038 public static final ELConceptInclusion parse(final String subsumeeExpression, final String subsumerExpression) { 039 return new ELConceptInclusion( 040 ELConceptDescription.parse(subsumeeExpression), 041 ELConceptDescription.parse(subsumerExpression)); 042 } 043 044 private final ELConceptDescription subsumee; 045 private final ELConceptDescription subsumer; 046 047 public ELConceptInclusion(final ELConceptDescription subsumee, final ELConceptDescription subsumer) { 048 super(); 049 this.subsumee = subsumee; 050 this.subsumer = subsumer; 051 } 052 053 public final Signature getSignature() { 054 final Signature sigma = new Signature(IRI.generateDocumentIRI()); 055 sigma.getConceptNames().addAll(subsumee.getConceptNamesInSignature().collect(Collectors.toSet())); 056 sigma.getConceptNames().addAll(subsumer.getConceptNamesInSignature().collect(Collectors.toSet())); 057 sigma.getRoleNames().addAll(subsumee.getRoleNamesInSignature().collect(Collectors.toSet())); 058 sigma.getRoleNames().addAll(subsumer.getRoleNamesInSignature().collect(Collectors.toSet())); 059 return sigma; 060 } 061 062 public final ELConceptDescription getSubsumee() { 063 return subsumee; 064 } 065 066 public final ELConceptDescription getSubsumer() { 067 return subsumer; 068 } 069 070 public final boolean isTautological() { 071 return subsumee.isSubsumedBy(subsumer); 072 } 073 074 @Override 075 public boolean equals(Object obj) { 076 if (obj == null) 077 return false; 078 if (!(obj instanceof ELConceptInclusion)) 079 return false; 080 final ELConceptInclusion other = (ELConceptInclusion) obj; 081 return this.subsumee.equals(other.subsumee) && this.subsumer.equals(other.subsumee); 082 } 083 084 @Override 085 public int hashCode() { 086 return 5 * subsumee.hashCode() + 7 * subsumer.hashCode(); 087 } 088 089 @Override 090 public String toString() { 091 return subsumee.toString() + " " + UnicodeSymbols.SQSUBSETEQ + " " + subsumer.toString(); 092 } 093 094 public OWLSubClassOfAxiom toOWLSubClassOfAxiom() { 095 return df.getOWLSubClassOfAxiom(subsumee.toOWLClassExpression(), subsumer.toOWLClassExpression()); 096 } 097 098}