001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.dllearner.algorithms.decisiontrees.utils; 020 021import java.util.SortedSet; 022import java.util.TreeSet; 023 024import org.dllearner.core.AbstractReasonerComponent; 025import org.semanticweb.owlapi.model.OWLClassExpression; 026import org.semanticweb.owlapi.model.OWLDataFactory; 027import org.semanticweb.owlapi.model.OWLIndividual; 028import org.semanticweb.owlapi.model.OWLObjectComplementOf; 029 030/** 031 * A class for splitting sets of individuals 032 * @author Giuseppe Rizzo 033 * 034 */ 035public class Split { 036 037 public static void split(OWLClassExpression concept, OWLDataFactory df, AbstractReasonerComponent reasoner, SortedSet<OWLIndividual> posExs, SortedSet<OWLIndividual> negExs, SortedSet<OWLIndividual> undExs, 038 SortedSet<OWLIndividual> posExsT, SortedSet<OWLIndividual> negExsT, SortedSet<OWLIndividual> undExsT, SortedSet<OWLIndividual> posExsF, SortedSet<OWLIndividual> negExsF, 039 SortedSet<OWLIndividual> undExsF) { 040 041 SortedSet<OWLIndividual> posExsU = new TreeSet<>(); 042 SortedSet<OWLIndividual> negExsU = new TreeSet<>(); 043 SortedSet<OWLIndividual> undExsU = new TreeSet<>(); 044 045 splitGroup(concept,df, reasoner, posExs,posExsT,posExsF,posExsU); 046 splitGroup(concept,df, reasoner, negExs,negExsT,negExsF,negExsU); 047 splitGroup(concept,df, reasoner, undExs,undExsT,undExsF,undExsU); 048 049 } 050 051 public static void splitGroup(OWLClassExpression concept, OWLDataFactory dataFactory, AbstractReasonerComponent reasoner, SortedSet<OWLIndividual> posExs, SortedSet<OWLIndividual> posExsT, 052 SortedSet<OWLIndividual> posExsF, SortedSet<OWLIndividual> posExsU) { 053 OWLClassExpression negConcept = dataFactory.getOWLObjectComplementOf(concept); 054 055 for ( OWLIndividual individual :posExs ){//int e=0; e<nodeExamples.size(); e++) { 056 057// int exIndex = nodeExamples.get(e); 058 if (reasoner.hasType(concept, individual)) 059 posExsT.add(individual); 060 else if (reasoner.hasType(negConcept, individual)) 061 posExsF.add(individual); 062 else 063 posExsU.add(individual); 064 } 065 066 } 067 068 public static void splitting(OWLDataFactory df, AbstractReasonerComponent reasoner, OWLIndividual[] trainingExs, SortedSet<OWLIndividual> posExs, 069 SortedSet<OWLIndividual> negExs, SortedSet<OWLIndividual> undExs, OWLClassExpression classToDescribe2, boolean binaryClassification) { 070 071 for (OWLIndividual trainingEx : trainingExs) { 072 073 if (reasoner.hasType(classToDescribe2, trainingEx)) 074 posExs.add(trainingEx); 075 else if (!binaryClassification) { 076 OWLObjectComplementOf owlObjectComplementOf = df.getOWLObjectComplementOf(classToDescribe2); 077 078 if (reasoner.hasType(owlObjectComplementOf, trainingEx)) 079 negExs.add(trainingEx); 080 else 081 undExs.add(trainingEx); 082 083 } else 084 negExs.add(trainingEx); 085 086 } 087 088 } 089 090 091 092 093 094 095 096 097 098 099 100}