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.utilities.owl; 020 021import org.semanticweb.owlapi.io.OWLObjectRenderer; 022import org.semanticweb.owlapi.model.*; 023 024import javax.annotation.Nonnull; 025import java.util.Iterator; 026 027import static org.semanticweb.owlapi.dlsyntax.renderer.DLSyntax.*; 028 029/** 030 * Extended version of the DLSyntaxObjectRenderer class in OWL API. Extension is 031 * done for data range facets, e.g. double[<=1.5]. 032 * 033 * Renders objects in unicode DL syntax. 034 * 035 * @author Lorenz Buehmann 036 */ 037public class DLSyntaxObjectRendererExt extends org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer 038implements OWLObjectRenderer, OWLObjectVisitor { 039 /////////////////////////////////////////////////////////////////////////////////////////////// 040 // 041 // Data stuff 042 // 043 /////////////////////////////////////////////////////////////////////////////////////////////// 044 045 @Override 046 public void visit(@Nonnull OWLDataIntersectionOf node) { 047 write("("); 048 write(node.getOperands(), AND, false); 049 write(")"); 050 } 051 052 @Override 053 public void visit(@Nonnull OWLDataUnionOf node) { 054 write("("); 055 write(node.getOperands(), OR, false); 056 write(")"); 057 } 058 059 @Override 060 public void visit(@Nonnull OWLDatatypeRestriction node) { 061 node.getDatatype().accept(this); 062 write("["); 063 Iterator<OWLFacetRestriction> iterator = node.getFacetRestrictions().iterator(); 064 065 while(iterator.hasNext()) { 066 OWLFacetRestriction facetRestriction = iterator.next(); 067 facetRestriction.accept(this); 068 if(iterator.hasNext()) { 069 write(" " + COMMA + " "); 070 } 071 } 072 write("]"); 073 } 074 075 @Override 076 public void visit(OWLObjectHasSelf ce) { 077 write(EXISTS); 078 writeSpace(); 079 ce.getProperty().accept(this); 080 write("."); 081 write(SELF); 082 } 083 084 @Override 085 public void visit(@Nonnull OWLFacetRestriction node) { 086 switch (node.getFacet()) { 087 case MIN_INCLUSIVE: write("\u2265"); /* >= */ break; 088 case MIN_EXCLUSIVE: write("\u003e"); /* > */ break; 089 case MAX_INCLUSIVE: write("\u2264"); /* <= */ break; 090 case MAX_EXCLUSIVE: write("\u003c"); /* < */ break; 091 default: 092 write(node.getFacet().getSymbolicForm()); 093 } 094 writeSpace(); 095 node.getFacetValue().accept(this); 096 } 097 098 /* private :-( */ 099 protected void writeSpace() { 100 write(" "); 101 } 102}