001package org.dllearner.cli.unife;
002
003import java.io.IOException;
004import java.util.Map;
005import org.apache.log4j.Level;
006import org.apache.log4j.Logger;
007import org.dllearner.cli.CLI;
008import org.dllearner.configuration.IConfiguration;
009//import org.dllearner.configuration.util.SpringConfigurationXMLBeanConverter;
010import org.dllearner.confparser.ParseException;
011import org.dllearner.core.ReasoningMethodUnsupportedException;
012import org.dllearner.core.probabilistic.unife.AbstractPSLA;
013import org.dllearner.core.probabilistic.unife.ProbabilisticStructureLearningAlgorithm;
014import org.semanticweb.owlapi.model.OWLOntologyCreationException;
015import org.semanticweb.owlapi.model.OWLOntologyStorageException;
016import unife.bundle.logging.BundleLoggerFactory;
017
018/*
019 * To change this license header, choose License Headers in Project Properties.
020 * To change this template file, choose Tools | Templates
021 * and open the template in the editor.
022 */
023/**
024 *
025 * @author Giuseppe Cota <giuseppe.cota@unife.it>, Riccardo Zese
026 * <riccardo.zese@unife.it>
027 */
028public class CLILEAP extends CLI {
029
030    private IConfiguration configuration;
031    private AbstractPSLA psla;
032
033    @Override
034    public void init() throws IOException {
035        super.init();
036        psla = getContext().getBean(AbstractPSLA.class);
037    }
038
039    @Override
040    public void run(){
041        System.out.println("CLI LEAP");
042        Logger logger = Logger.getLogger(CLILEAP.class.getName(), new BundleLoggerFactory());
043        logger.info("CLI LEAP");
044        try {
045            org.apache.log4j.Logger.getLogger("org.dllearner").setLevel(Level.toLevel(getLogLevel().toUpperCase()));
046        } catch (Exception e) {
047            logger.warn("Error setting log level to " + getLogLevel());
048        }
049
050//        init();
051
052        if (isPerformCrossValidation()) {
053//            PosNegLP lp = context.getBean(PosNegLP.class);
054//            if (la instanceof QTL2) {
055//                new SPARQLCrossValidation((QTL2) la, lp, rs, nrOfFolds, false);
056//            } else {
057            try {
058                new LEAPCrossValidation(psla, getNrOfFolds(), false, false);
059            } catch (OWLOntologyCreationException | OWLOntologyStorageException e) {
060                logger.error(e.getMessage(), e);
061                e.printStackTrace();
062            }
063//            }
064            throw new UnsupportedOperationException("Not supported yet.");
065        } else {
066            ProbabilisticStructureLearningAlgorithm algorithm;
067            for (Map.Entry<String, ProbabilisticStructureLearningAlgorithm> entry : getContext().getBeansOfType(ProbabilisticStructureLearningAlgorithm.class).entrySet()) {
068                algorithm = entry.getValue();
069                logger.info("Running algorithm instance \"" + entry.getKey() + "\" (" + algorithm.getClass().getSimpleName() + ")");
070                algorithm.start();
071            }
072        }
073
074    }
075
076    public static void main(String[] args) throws ParseException, IOException,
077            ReasoningMethodUnsupportedException {
078        CLI.main(args);
079    }
080}