glluch.com.ontotaxoseeker.IO.java Source code

Java tutorial

Introduction

Here is the source code for glluch.com.ontotaxoseeker.IO.java

Source

/*
 * The MIT License
 *
 * Copyright 2016 Guillem LLuch Moll <guillem72@gmail.com>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package glluch.com.ontotaxoseeker;

import com.glluch.utils.Out;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.util.FileManager;

/**
 * A class for some inputs and outputs.
 * @author Guillem LLuch Moll
 */
public class IO {

    protected String filename = null;

    /**
     * Builds a the OntModel for <a href="https://jena.apache.org/">apache jena</a>
     * @return The OntModel form the filename.
     * @throws IOException Reading files
     */
    public OntModel read() throws IOException {
        OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
        if (StringUtils.isNotEmpty(filename)) {

            InputStream in = FileManager.get().open(this.filename);
            if (in == null) {
                throw new IllegalArgumentException("File: " + this.filename + " not found");
            }

            m.read(in, null);
        }
        return m;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    protected transient boolean verbose = true;

    public boolean isVerbose() {
        return verbose;
    }

    public void setVerbose(boolean verbose) {
        this.verbose = verbose;
    }

    protected transient boolean debug = true;

    public boolean isDebug() {
        return debug;
    }

    public void setDebug(boolean debug) {
        this.debug = debug;
    }

    /**
        * Sent a message to the console depens on the parametre verbose. If it is
        * true (on), the text is shown.
        *
        * @param text The text to be shown
        */

    protected void show(String text) {
        if (this.verbose) {
            Out.p(text);
        }
    }

    /**
       * Sent a message to the console depens on the parametre debug. If it is
       * true (on), the text is shown.
       *
       * @param text The text to be shown
       */
    protected void debug(String text) {
        if (this.debug) {
            Out.p(text);
        }
    }

}