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.core; 020 021import org.dllearner.utilities.owl.OWLAPIRenderers; 022import org.dllearner.utilities.owl.OWLClassExpressionUtils; 023import org.json.JSONException; 024import org.json.JSONObject; 025import org.semanticweb.owlapi.model.OWLClassExpression; 026 027/** 028 * An evaluated class expression is a class expression and its score (with some 029 * convenience method and serialisation formats). 030 * 031 * @author Jens Lehmann 032 * 033 */ 034public class EvaluatedDescription<S extends Score> extends EvaluatedHypothesis<OWLClassExpression, S>{ 035 036 /** 037 * Constructs an evaluated class expression using its score. 038 * @param description The class expression, which was evaluated. 039 * @param score The score of the class expression. 040 */ 041 public EvaluatedDescription(OWLClassExpression description, S score) { 042 super(description, score); 043 } 044 045 /** 046 * @see OWLClassExpressionUtils#getLength(OWLClassExpression) 047 * @return Length of the description. 048 */ 049 public int getDescriptionLength() { 050 return OWLClassExpressionUtils.getLength(hypothesis); 051 } 052 053 /** 054 * @see OWLClassExpressionUtils#getDepth(OWLClassExpression) 055 * @return Depth of the description. 056 */ 057 public int getDescriptionDepth() { 058 return OWLClassExpressionUtils.getDepth(hypothesis); 059 } 060 061 /** 062 * This convenience method can be used to store and exchange evaluated 063 * descriptions by transforming them to a JSON string. 064 * @return A JSON representation of an evaluated description. 065 */ 066 public String asJSON() { 067 JSONObject object = new JSONObject(); 068 try { 069 object.put("descriptionManchesterSyntax", OWLAPIRenderers.toManchesterOWLSyntax(hypothesis)); 070 object.put("descriptionOWLXML", OWLAPIRenderers.toOWLXMLSyntax(hypothesis)); 071 object.put("scoreValue", score.getAccuracy()); 072 return object.toString(3); 073 } catch (JSONException e) { 074 e.printStackTrace(); 075 return null; 076 } 077 } 078}