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.semanticweb.owlapi.model.AxiomType; 022import org.semanticweb.owlapi.model.OWLAxiom; 023 024import java.text.DecimalFormat; 025import java.text.NumberFormat; 026import java.util.Locale; 027 028/** 029 * A progress monitor for axiom learning algorithms which prints to the console. 030 * 031 * @see org.dllearner.core.AxiomLearningProgressMonitor 032 * @author Lorenz Buehmann 033 * 034 */ 035public class ConsoleAxiomLearningProgressMonitor implements AxiomLearningProgressMonitor{ 036 037 final char[] animationChars = new char[] {'|', '/', '-', '\\'}; 038 039 private static final NumberFormat format = DecimalFormat.getPercentInstance(Locale.ROOT); 040 041 private int lastPercentage; 042 043 /* (non-Javadoc) 044 * @see org.dllearner.core.AxiomLearningProgressMonitor#learningStarted(java.lang.String) 045 */ 046 @Override 047 public void learningStarted(AxiomType<? extends OWLAxiom> axiomType) { 048 System.out.print("Learning"); 049 if(axiomType != null){ 050 System.out.print(" of " + axiomType.getName() + " axioms"); 051 } 052 System.out.println(" ..."); 053 } 054 055 /* (non-Javadoc) 056 * @see org.dllearner.core.AxiomLearningProgressMonitor#learningStopped() 057 */ 058 @Override 059 public void learningStopped(AxiomType<? extends OWLAxiom> axiomType) { 060 System.out.print(" ... "); 061 if(axiomType != null){ 062 System.out.print(axiomType.getName() + " axioms "); 063 } 064 System.out.println("finished"); 065 } 066 067 /* (non-Javadoc) 068 * @see org.dllearner.core.AxiomLearningProgressMonitor#learningProgressChanged(int, int) 069 */ 070 @Override 071 public void learningProgressChanged(AxiomType<? extends OWLAxiom> axiomType, int value, int max) { 072 if (max > 0) { 073 int percent = value * 100 / max; 074 if (lastPercentage != percent) { 075 System.out.print(" " + percent + "%" + "\r"); 076// System.out.println(); 077 lastPercentage = percent; 078 } 079 } 080 } 081 082 /* (non-Javadoc) 083 * @see org.dllearner.core.AxiomLearningProgressMonitor#learningTaskBusy() 084 */ 085 @Override 086 public void learningTaskBusy(AxiomType<? extends OWLAxiom> axiomType) { 087 System.out.println(axiomType.getName() + " ..."); 088 } 089 090 @Override 091 public void learningFailed(AxiomType<? extends OWLAxiom> axiomType) { 092 System.err.println("Learning "); 093 if(axiomType != null){ 094 System.err.println("of " + axiomType.getName() + " axioms "); 095 } 096 System.err.println("failed."); 097 } 098 099}