001package conexp.fx.core.dl; 002 003/*- 004 * #%L 005 * Concept Explorer FX 006 * %% 007 * Copyright (C) 2010 - 2019 Francesco Kriegel 008 * %% 009 * This program is free software: you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as 011 * published by the Free Software Foundation, either version 3 of the 012 * License, or (at your option) any later version. 013 * 014 * This program is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public 020 * License along with this program. If not, see 021 * <http://www.gnu.org/licenses/gpl-3.0.html>. 022 * #L% 023 */ 024 025import java.util.HashSet; 026import java.util.Set; 027 028import com.google.common.collect.Sets; 029 030public class ELCanModTest { 031 032 public static void main(String[] args) { 033// foo(); 034// bar(); 035// baz2(); 036 System.out.println(ELConceptDescription.parse("∃r.(B⊓∃r.⊤⊓∃r.C)⊓∃r.(C⊓∃r.B⊓∃r.⊤)").reduce()); 037 } 038 039 private static void foo() { 040 // This is the example in my DAM 2019 paper. 041 final ELTBox tBox = new ELTBox(); 042// tBox 043// .getConceptInclusions() 044// .add( 045// new ELConceptInclusion( 046// ELConceptDescription.conceptName(IRI.create("A")), 047// ELConceptDescription 048// .existentialRestriction( 049// IRI.create("r"), 050// ELConceptDescription.existentialRestriction(IRI.create("r"), ELConceptDescription.top())))); 051// tBox 052// .getConceptInclusions() 053// .add( 054// new ELConceptInclusion( 055// ELConceptDescription.existentialRestriction(IRI.create("r"), ELConceptDescription.top()), 056// ELConceptDescription 057// .existentialRestriction(IRI.create("s"), ELConceptDescription.conceptName(IRI.create("A"))))); 058 tBox.getConceptInclusions().add(new ELConceptInclusion(ELParser.read("A"), ELParser.read("exists r.exists r.Top"))); 059 tBox.getConceptInclusions().add(new ELConceptInclusion(ELParser.read("exists r.Top"), ELParser.read("exists s.A"))); 060// final ELConceptDescription C = new ELConceptDescription(); 061// C.getConceptNames().add(IRI.create("A")); 062// C.getConceptNames().add(IRI.create("B")); 063 final ELConceptDescription C = ELParser.read("A and B"); 064 System.out.println(tBox); 065 System.out.println(C); 066 System.out.println(tBox.getCanonicalModel(C)); 067 for (int d = 0; d < 5; d++) { 068 System.out.println(tBox.getMostSpecificConsequence(C, d)); 069 } 070 } 071 072 private static void bar() { 073 final Set<Set<Integer>> hypergraph = new HashSet<>(); 074 hypergraph.add(Sets.newHashSet(1, 2, 3)); 075 hypergraph.add(Sets.newHashSet(2, 3, 4)); 076 hypergraph.add(Sets.newHashSet(2, 5, 8)); 077 hypergraph.add(Sets.newHashSet(7, 8, 9)); 078// hypergraph.add(Sets.newHashSet()); 079// hypergraph.add(Sets.newHashSet()); 080 final Set<Set<Integer>> mhs = ELInterpretation2.getMinimalHittingSets(hypergraph); 081 System.out.println(hypergraph); 082 System.out.println(mhs); 083 } 084 085 private static ELConceptInclusion parseCI(String subsumee, String subsumer) { 086 return new ELConceptInclusion(ELParser.read(subsumee), ELParser.read(subsumer)); 087 } 088 089 private static void baz0() { 090 final ELTBox tBox = new ELTBox(); 091 tBox.getConceptInclusions().add(parseCI("Elefant", "Mammal")); 092 tBox.getConceptInclusions().add(parseCI("Mammal", "exists hasParent. Mammal")); 093 tBox.getConceptInclusions().add(parseCI("Elefant", "exists hasParent. Elefant")); 094 final ELConceptDescription C = ELParser.read("Elefant"); 095 System.out.println(tBox); 096 System.out.println(C); 097 System.out.println(tBox.getCanonicalModel(C)); 098 for (int d = 0; d < 5; d++) { 099 System.out.println(tBox.getMostSpecificConsequence(C, d)); 100 } 101 } 102 103 private static void baz1() { 104 final ELTBox tBox = new ELTBox(); 105 tBox.getConceptInclusions().add(parseCI("exists hasChild. Top", "Parent")); 106 tBox.getConceptInclusions().add(parseCI("exists hasChild. exists hasChild. Top", "Grandparent")); 107 final ELConceptDescription C = ELParser.read("exists hasChild. exists hasChild. Top"); 108 System.out.println(tBox); 109 System.out.println(C); 110 System.out.println(tBox.getCanonicalModel(C)); 111 for (int d = 0; d < 5; d++) { 112 System.out.println(tBox.getMostSpecificConsequence(C, d)); 113 } 114 } 115 116 private static void baz2() { 117 final ELTBox tBox = new ELTBox(); 118 tBox.getConceptInclusions().add(parseCI("A", "exists r.B")); 119 tBox.getConceptInclusions().add(parseCI("B", "C")); 120 tBox.getConceptInclusions().add(parseCI("exists r. C", "exists s. exists r.B")); 121 tBox.getConceptInclusions().add(parseCI("exists s. Top", "C")); 122 tBox.getConceptInclusions().add(parseCI("A and B", "exists r. C")); 123 final ELConceptDescription C = ELParser.read("A"); 124 System.out.println(tBox); 125 System.out.println(C); 126 System.out.println(tBox.getCanonicalModel(C)); 127 System.out.println(tBox.getCanonicalModelLutz(C)); 128 for (int d = 0; d < 5; d++) { 129 final ELConceptDescription mss = tBox.getMostSpecificConsequence(C, d); 130 System.out.println(mss); 131 final ELConceptDescription mssL = tBox.getMostSpecificConsequenceLutz(C, d); 132 System.out.println(mssL); 133 System.out.println(mss.isEquivalentTo(mssL)); 134 } 135 } 136 137}