001/** 002 * Copyright (C) 2007-2011, 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 */ 019 020package org.dllearner.algorithms.isle; 021 022import java.util.Map; 023import java.util.Set; 024 025import org.dllearner.algorithms.celoe.OENode; 026import org.dllearner.core.AbstractHeuristic; 027import org.dllearner.core.config.ConfigOption; 028import org.semanticweb.owlapi.model.OWLClassExpression; 029import org.semanticweb.owlapi.model.OWLEntity; 030 031/** 032 * 033 * TODO: NLP-Heuristiken in Statistik integrieren 034 * 035 * @author Jens Lehmann 036 * 037 */ 038public class NLPHeuristic extends AbstractHeuristic{ 039 040 // strong penalty for long descriptions 041 private double expansionPenaltyFactor = 0.1; 042 // bonus for being better than parent node 043 private double gainBonusFactor = 0.3; 044 // penalty if a node OWLClassExpression has very many refinements since exploring 045 // such a node is computationally very expensive 046 private double nodeRefinementPenalty = 0.0001; 047 048 @ConfigOption(defaultValue="0.1") 049 private double startNodeBonus = 0.1; 050 051 private double nlpBonusFactor = 1; 052 053 private Map<OWLEntity, Double> entityRelevance; 054 055 public NLPHeuristic() {} 056 057 public NLPHeuristic(Map<OWLEntity,Double> entityRelevance) { 058 this.entityRelevance = entityRelevance; 059 } 060 061 @Override 062 public double getNodeScore(OENode node) { 063 // accuracy as baseline 064 double score = node.getAccuracy(); 065 066 // being better than the parent gives a bonus; 067 if(!node.isRoot()) { 068 double accuracyGain = node.getAccuracy() - node.getParent().getAccuracy(); 069 score += accuracyGain * gainBonusFactor; 070 // the root node also gets a bonus to possibly spawn useful disjunctions 071 } else { 072 score += startNodeBonus; 073 } 074 075 // penalty for horizontal expansion 076 score -= node.getHorizontalExpansion() * expansionPenaltyFactor; 077 078 // penalty for having many child nodes (stuck prevention) 079 score -= node.getRefinementCount() * nodeRefinementPenalty; 080 081 082// the NLP based scoring 083 OWLClassExpression expression = node.getExpression();//System.out.println(expression); 084// OWLClassExpression owlapiDescription = OWLAPIConverter.getOWLAPIDescription(expression); 085// Set<OWLEntity> entities = OWLAPIConverter.getEntities(owlapiDescription.getSignature()); 086 Set<OWLEntity> entities = expression.getSignature(); 087// double sum = 0; 088// for (OWLEntity entity : entities) { 089// double relevance = entityRelevance.containsKey(entity) ? entityRelevance.get(entity) : 0;//System.out.println(entity + ":" + relevance); 090// if(!Double.isInfinite(relevance)){ 091// sum += relevance; 092// } 093// } 094// score += nlpBonusFactor * sum; 095 096 return score; 097 } 098 099 /** 100 * @param entityRelevance the entityRelevance to set 101 */ 102 public void setEntityRelevance(Map<OWLEntity, Double> entityRelevance) { 103 this.entityRelevance = entityRelevance; 104 } 105 106 /** 107 * @return the entityRelevance 108 */ 109 public Map<OWLEntity, Double> getEntityRelevance() { 110 return entityRelevance; 111 } 112 113}