<commit_before>package org.refinery_platform.owl2neo4j;

/** OWL API */
import org.json.JSONTokener;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.util.AutoIRIMapper;
import org.semanticweb.owlapi.util.OWLClassExpressionVisitorAdapter;

/** Reasoner */
import org.semanticweb.HermiT.Reasoner;

/** Apache commons */
import org.apache.commons.cli.*;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;

/** Jersey RESTful client */
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.Headers;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.HttpResponse;

/** JSON **/
import org.json.JSONObject;
import org.json.JSONArray;
import javax.json.Json;
import javax.json.JsonObject;

import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.io.FileReader;

import org.apache.commons.io.FilenameUtils;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Owl2Neo4J {

    private static String REST_ENDPOINT = "/db/data";
    private static String TRANSACTION_ENDPOINT = "/db/data/transaction";

    public static String ROOT_ONTOLOGY = "OWL";
    public static String ROOT_CLASS = "Thing";
    public static String ROOT_CLASS_ONT_ID = ROOT_ONTOLOGY + ":" + ROOT_CLASS;
    public static String ROOT_CLASS_URI = "http://www.w3.org/2002/07/owl#" + ROOT_CLASS;

    // Graph related nodes
    private static String CLASS_NODE_LABEL = "Class";
    private static String INDIVIDUAL_NODE_LABEL = "Individual";
    // Meta data related nodes
    private static String ONTOLOGY_NODE_LABEL = "Ontology";
    private static String RELATIONSHIP_NODE_LABEL = "Relationship";
    private static String PROPERTY_NODE_LABEL = "Property";

    private String path_to_batch;
    private String path_to_owl;
    private String ontology_name;
    private String ontology_acronym;
    private String server_root_url;
    private String neo4j_authentication_header;
    private String transaction;
    private Set<String> eqps = new HashSet<>();  // Existential quantification property strings
    private Set<OWLObjectPropertyExpression> eqp = new HashSet<>();  // Existential quantification properties
    private Boolean include_import_closure = false;
    private Boolean no_local_owl_files = false;

    private OWLOntologyManager manager;
    private OWLOntology ontology;
    private IRI documentIRI;
    private OWLDataFactory dataFactory;
    private String ontUri;
    private String versionIri;

    private Logger cqlLogger;
    private FileHandler fh;
    private Boolean verbose_output = false;

    public static final String ANSI_RESET = "\u001B[0m";
    public static final String ANSI_RED = "\u001B[31m";
    public static final String ANSI_GREEN = "\u001B[32m";
    public static final String ANSI_DIM = "\u001B[2m";
    public static final String ANSI_RESET_DIM = "\u001B[22m";

    public static final String VERSION = "0.5.0";

    public static List<String> fileList (String directory, String fileExt) {
        List<String> fileNames = new ArrayList<>();
        try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(directory))) {
            for (Path path : directoryStream) {
                if (FilenameUtils.isExtension(path.getFileName().toString(), fileExt)) {
                    fileNames.add(path.toString());
                }
            }
        } catch (IOException ex) {}
        return fileNames;
    }

    // Inline class handling labels
    public class Label {
        private String text;
        private String lang;

        public Label (String text, String lang) {
            this.text = text;
            this.lang = lang;
        }

        public String getLang () {
            return this.lang;
        }

        public String getText () {
            return this.text;
        }

        public void setLang (String lang) {
            this.lang = lang;
        }

        public void setText (String text) {
            this.text = text;
        }
    }

    /**
     * Tiny class for storing pairs
     * @param <X>
     * @param <Y>
     */
    public static class Tuple<X, Y> {
        public final X x;
        public final Y y;
        public Tuple(X x, Y y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "(" + x + ", " + y + ")";
        }
    }

    /**
     * Visits existential restrictions and collects the properties which are
     * restricted.
     */
    private static class RestrictionVisitor extends OWLClassExpressionVisitorAdapter {

        private final Set<Tuple> restrictions;

        public RestrictionVisitor() {
            restrictions = new HashSet<>();
        }

        public Set<Tuple> getRestrictions () {
            return restrictions;
        }

        @Override
        public void visit(OWLObjectSomeValuesFrom clazz) {
            // This method gets called when a class expression is an existential
            // (someValuesFrom) restriction and it asks us to visit it
            if (! clazz.getFiller().isAnonymous()) {
                restrictions.add(new Tuple(clazz.getProperty(), clazz.getFiller().asOWLClass()));
            }
        }
    }

    public static void main(String[] args) {
        Owl2Neo4J ontParser = new Owl2Neo4J(args);

        long startImport = System.nanoTime();
        long endImport = System.nanoTime();

        if (StringUtils.isBlank(ontParser.path_to_batch)) {
            ontParser.checkServer();
            ontParser.importOntologies();
        } else {
            JSONArray ontologies = new JSONArray();
            JSONObject jsonObject = new JSONObject();
            String basePath = FilenameUtils.getFullPath(ontParser.path_to_batch);

            // Read JSON file
            try {
                FileReader reader = new FileReader(ontParser.path_to_batch);

                JSONTokener jsonTokener = new JSONTokener(reader);
                jsonObject = new JSONObject(jsonTokener);

                ontologies = jsonObject.getJSONArray("ontologies");

            } catch (Exception e) {
                print_error("Error loading JSON file.");
                print_error(e.getMessage());
                System.exit(1);
            }

            // Read global properties
            try {
                if (jsonObject.has("server")) {
                    ontParser.server_root_url = jsonObject.getString("server");
                }
            } catch (Exception e) {
                print_error("Error extracting global settings.");
            }

            ontParser.checkServer();

            // Loop over ontologies to be imported and import them
            try {
                for (int i = 0; i < ontologies.length(); i++) {
                    ontParser.path_to_owl = new File(basePath, ontologies.getJSONObject(i).getString("o")).getPath();
                    ontParser.ontology_name = ontologies.getJSONObject(i).getString("n");
                    ontParser.ontology_acronym = ontologies.getJSONObject(i).getString("a").toUpperCase();
                    if (ontologies.getJSONObject(i).has("i")) {
                        ontParser.include_import_closure = ontologies.getJSONObject(i).getBoolean("i");
                    } else {
                        ontParser.include_import_closure = false;
                    }
                    ontParser.importOntologies();
                }
            }  catch (Exception e) {
                print_error("Error during batch import");
                print_error(e.getMessage());
                System.exit(1);
            }
        }

        long totalImportSec = TimeUnit.NANOSECONDS.toMinutes(endImport - startImport);
        long totalImportMin = TimeUnit.NANOSECONDS.toSeconds(endImport - startImport);

        // Unirest has be closed explicitly
        try {
            Unirest.shutdown();
        } catch (Exception e) {
            print_error("Error shutting down Unirest");
            print_error(e.getMessage());
            System.exit(1);
        }

        // Print some performance related numbers
        if (ontParser.verbose_output) {
            System.out.println("---");
            System.out.println(
                "Total import time:   " +
                    totalImportMin +
                    " min and" +
                    totalImportSec +
                    " sec"
            );
        }
    }

    public Owl2Neo4J(String[] args) {
        parseCommandLineArguments(args);
    }

    public void checkServer() {
        if (StringUtils.isBlank(this.server_root_url)) {
            this.server_root_url = "http://localhost:7474";
        }

        Unirest.setDefaultHeader("Content-type", "application/json");
        Unirest.setDefaultHeader("Accept", "application/json; charset=UTF-8");
        // Yields better performance and reduces memory load on the Neo4J server
        // http://neo4j.com/docs/stable/rest-api-streaming.html
        Unirest.setDefaultHeader("X-Stream", "true");
        Unirest.setDefaultHeader(
            "Authorization", this.neo4j_authentication_header
        );

        // Test if server is available
        try {
            if (this.verbose_output) {
                System.out.println("Checking Neo4J at " + this.server_root_url + "... " + ANSI_DIM);
            } else {
                System.out.print("Checking Neo4J at " + this.server_root_url + "... ");
            }

            Unirest.get(
                this.server_root_url
            ).asJson();

            if (this.verbose_output) {
                System.out.println(ANSI_RESET + "Checking Neo4J at " + this.server_root_url + "... " + ANSI_GREEN + "\u2713" + ANSI_RESET);
            } else {
                System.out.println(ANSI_GREEN + "\u2713" + ANSI_RESET);
            }
        } catch (Exception e) {
            print_error("Error querying Neo4J server root URL");
            print_error(e.getMessage());
            System.exit(1);
        }

        // Try authentication
        try {
            if (this.verbose_output) {
                System.out.println("Checking credentials for Neo4J... " + ANSI_DIM);
            } else {
                System.out.print("Checking credentials for Neo4J... ");
            }

            Unirest.get(
                this.server_root_url + REST_ENDPOINT
            ).asJson();

            if (this.verbose_output) {
                System.out.println(ANSI_RESET + "Checking credentials for Neo4J... " + ANSI_GREEN + "\u2713" + ANSI_RESET);
            } else {
                System.out.println(ANSI_GREEN + "\u2713" + ANSI_RESET);
            }
        } catch (Exception e) {
            print_error("Error querying Neo4J REST endpoint");
            print_error(e.getMessage());
            System.exit(1);
        }
    }

    public void importOntologies() {
        long loadTimeSec;
        long loadTimeMin;

        try {
            if (this.verbose_output) {
                System.out.println("Loading " + this.ontology_acronym + "... " + ANSI_DIM);
            } else {
                System.out.print("Loading " + this.ontology_acronym + "... ");
            }

            long start = System.nanoTime();
            this.loadOntology();
            long end = System.nanoTime();
            loadTimeMin = TimeUnit.NANOSECONDS.toMinutes(end - start);
            loadTimeSec = TimeUnit.NANOSECONDS.toSeconds(end - start) - (60 * loadTimeMin);

            if (this.verbose_output) {
                System.out.println(ANSI_RESET + "Loading " + this.ontology_acronym + "... " + ANSI_GREEN + "\u2713" + ANSI_RESET);
            } else {
                System.out.println(
                    ANSI_GREEN + "\u2713 " + ANSI_RESET +
                        ANSI_DIM + "  ("  + loadTimeMin + " min and " + loadTimeSec + " sec)" + ANSI_RESET_DIM
                );
            }
        } catch (Exception e) {
            print_error("Error loading the ontology");
            print_error(e.getMessage());
            System.exit(1);
        }

        long importTimeSec;
        long importTimeMin;
        try {
            if (this.verbose_output) {
                System.out.println("Importing " + this.ontology_acronym + "... " + ANSI_DIM);
            } else {
                System.out.print("Importing " + this.ontology_acronym + "... ");
            }

            long start = System.nanoTime();
            this.importOntology();
            long end = System.nanoTime();
            importTimeMin = TimeUnit.NANOSECONDS.toMinutes(end - start);
            importTimeSec = TimeUnit.NANOSECONDS.toSeconds(end - start) - (60 * importTimeMin);

            if (this.verbose_output) {
                System.out.println(ANSI_RESET + "Importing " + this.ontology_acronym + "... " + ANSI_GREEN + "\u2713" + ANSI_RESET);
            } else {
                System.out.println(
                    ANSI_GREEN + "\u2713" + ANSI_RESET +
                        ANSI_DIM + "  (" + importTimeMin + " min and " + importTimeSec + " sec)" + ANSI_RESET_DIM
                );
            }
        } catch (Exception e) {
            print_error("Error importing the ontology");
            print_error(e.getMessage());
            System.exit(1);
        }
    }

    public void loadOntology() throws Exception {
        this.manager = OWLManager.createOWLOntologyManager();

        Path ontFilePath = Paths.get(this.path_to_owl);
        if (Files.notExists(ontFilePath)) {
            throw new Exception("The option `-o` doesn't point to a file.");
        }

        if (!this.no_local_owl_files) {
            this.manager.addIRIMapper(
                new AutoIRIMapper(
                    ontFilePath.getParent().toFile(), true
                )
            );
        }<commit_msg>Current directories, i.e. ".", doesn't seem to work but absolute paths do for including local ontologies.<commit_after>package org.refinery_platform.owl2neo4j;

/** OWL API */
import org.json.JSONTokener;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.util.AutoIRIMapper;
import org.semanticweb.owlapi.util.OWLClassExpressionVisitorAdapter;

/** Reasoner */
import org.semanticweb.HermiT.Reasoner;

/** Apache commons */
import org.apache.commons.cli.*;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;

/** Jersey RESTful client */
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.Headers;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.HttpResponse;

/** JSON **/
import org.json.JSONObject;
import org.json.JSONArray;
import javax.json.Json;
import javax.json.JsonObject;

import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.io.FileReader;

import org.apache.commons.io.FilenameUtils;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Owl2Neo4J {

    private static String REST_ENDPOINT = "/db/data";
    private static String TRANSACTION_ENDPOINT = "/db/data/transaction";

    public static String ROOT_ONTOLOGY = "OWL";
    public static String ROOT_CLASS = "Thing";
    public static String ROOT_CLASS_ONT_ID = ROOT_ONTOLOGY + ":" + ROOT_CLASS;
    public static String ROOT_CLASS_URI = "http://www.w3.org/2002/07/owl#" + ROOT_CLASS;

    // Graph related nodes
    private static String CLASS_NODE_LABEL = "Class";
    private static String INDIVIDUAL_NODE_LABEL = "Individual";
    // Meta data related nodes
    private static String ONTOLOGY_NODE_LABEL = "Ontology";
    private static String RELATIONSHIP_NODE_LABEL = "Relationship";
    private static String PROPERTY_NODE_LABEL = "Property";

    private String path_to_batch;
    private String path_to_owl;
    private String ontology_name;
    private String ontology_acronym;
    private String server_root_url;
    private String neo4j_authentication_header;
    private String transaction;
    private Set<String> eqps = new HashSet<>();  // Existential quantification property strings
    private Set<OWLObjectPropertyExpression> eqp = new HashSet<>();  // Existential quantification properties
    private Boolean include_import_closure = false;
    private Boolean no_local_owl_files = false;

    private OWLOntologyManager manager;
    private OWLOntology ontology;
    private IRI documentIRI;
    private OWLDataFactory dataFactory;
    private String ontUri;
    private String versionIri;

    private Logger cqlLogger;
    private FileHandler fh;
    private Boolean verbose_output = false;

    public static final String ANSI_RESET = "\u001B[0m";
    public static final String ANSI_RED = "\u001B[31m";
    public static final String ANSI_GREEN = "\u001B[32m";
    public static final String ANSI_DIM = "\u001B[2m";
    public static final String ANSI_RESET_DIM = "\u001B[22m";

    public static final String VERSION = "0.5.0";

    public static List<String> fileList (String directory, String fileExt) {
        List<String> fileNames = new ArrayList<>();
        try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(directory))) {
            for (Path path : directoryStream) {
                if (FilenameUtils.isExtension(path.getFileName().toString(), fileExt)) {
                    fileNames.add(path.toString());
                }
            }
        } catch (IOException ex) {}
        return fileNames;
    }

    // Inline class handling labels
    public class Label {
        private String text;
        private String lang;

        public Label (String text, String lang) {
            this.text = text;
            this.lang = lang;
        }

        public String getLang () {
            return this.lang;
        }

        public String getText () {
            return this.text;
        }

        public void setLang (String lang) {
            this.lang = lang;
        }

        public void setText (String text) {
            this.text = text;
        }
    }

    /**
     * Tiny class for storing pairs
     * @param <X>
     * @param <Y>
     */
    public static class Tuple<X, Y> {
        public final X x;
        public final Y y;
        public Tuple(X x, Y y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "(" + x + ", " + y + ")";
        }
    }

    /**
     * Visits existential restrictions and collects the properties which are
     * restricted.
     */
    private static class RestrictionVisitor extends OWLClassExpressionVisitorAdapter {

        private final Set<Tuple> restrictions;

        public RestrictionVisitor() {
            restrictions = new HashSet<>();
        }

        public Set<Tuple> getRestrictions () {
            return restrictions;
        }

        @Override
        public void visit(OWLObjectSomeValuesFrom clazz) {
            // This method gets called when a class expression is an existential
            // (someValuesFrom) restriction and it asks us to visit it
            if (! clazz.getFiller().isAnonymous()) {
                restrictions.add(new Tuple(clazz.getProperty(), clazz.getFiller().asOWLClass()));
            }
        }
    }

    public static void main(String[] args) {
        Owl2Neo4J ontParser = new Owl2Neo4J(args);

        long startImport = System.nanoTime();
        long endImport = System.nanoTime();

        if (StringUtils.isBlank(ontParser.path_to_batch)) {
            ontParser.checkServer();
            ontParser.importOntologies();
        } else {
            JSONArray ontologies = new JSONArray();
            JSONObject jsonObject = new JSONObject();
            String basePath = FilenameUtils.getFullPath(ontParser.path_to_batch);

            // Read JSON file
            try {
                FileReader reader = new FileReader(ontParser.path_to_batch);

                JSONTokener jsonTokener = new JSONTokener(reader);
                jsonObject = new JSONObject(jsonTokener);

                ontologies = jsonObject.getJSONArray("ontologies");

            } catch (Exception e) {
                print_error("Error loading JSON file.");
                print_error(e.getMessage());
                System.exit(1);
            }

            // Read global properties
            try {
                if (jsonObject.has("server")) {
                    ontParser.server_root_url = jsonObject.getString("server");
                }
            } catch (Exception e) {
                print_error("Error extracting global settings.");
            }

            ontParser.checkServer();

            // Loop over ontologies to be imported and import them
            try {
                for (int i = 0; i < ontologies.length(); i++) {
                    ontParser.path_to_owl = new File(basePath, ontologies.getJSONObject(i).getString("o")).getPath();
                    ontParser.ontology_name = ontologies.getJSONObject(i).getString("n");
                    ontParser.ontology_acronym = ontologies.getJSONObject(i).getString("a").toUpperCase();
                    if (ontologies.getJSONObject(i).has("i")) {
                        ontParser.include_import_closure = ontologies.getJSONObject(i).getBoolean("i");
                    } else {
                        ontParser.include_import_closure = false;
                    }
                    ontParser.importOntologies();
                }
            }  catch (Exception e) {
                print_error("Error during batch import");
                print_error(e.getMessage());
                System.exit(1);
            }
        }

        long totalImportSec = TimeUnit.NANOSECONDS.toMinutes(endImport - startImport);
        long totalImportMin = TimeUnit.NANOSECONDS.toSeconds(endImport - startImport);

        // Unirest has be closed explicitly
        try {
            Unirest.shutdown();
        } catch (Exception e) {
            print_error("Error shutting down Unirest");
            print_error(e.getMessage());
            System.exit(1);
        }

        // Print some performance related numbers
        if (ontParser.verbose_output) {
            System.out.println("---");
            System.out.println(
                "Total import time:   " +
                    totalImportMin +
                    " min and" +
                    totalImportSec +
                    " sec"
            );
        }
    }

    public Owl2Neo4J(String[] args) {
        parseCommandLineArguments(args);
    }

    public void checkServer() {
        if (StringUtils.isBlank(this.server_root_url)) {
            this.server_root_url = "http://localhost:7474";
        }

        Unirest.setDefaultHeader("Content-type", "application/json");
        Unirest.setDefaultHeader("Accept", "application/json; charset=UTF-8");
        // Yields better performance and reduces memory load on the Neo4J server
        // http://neo4j.com/docs/stable/rest-api-streaming.html
        Unirest.setDefaultHeader("X-Stream", "true");
        Unirest.setDefaultHeader(
            "Authorization", this.neo4j_authentication_header
        );

        // Test if server is available
        try {
            if (this.verbose_output) {
                System.out.println("Checking Neo4J at " + this.server_root_url + "... " + ANSI_DIM);
            } else {
                System.out.print("Checking Neo4J at " + this.server_root_url + "... ");
            }

            Unirest.get(
                this.server_root_url
            ).asJson();

            if (this.verbose_output) {
                System.out.println(ANSI_RESET + "Checking Neo4J at " + this.server_root_url + "... " + ANSI_GREEN + "\u2713" + ANSI_RESET);
            } else {
                System.out.println(ANSI_GREEN + "\u2713" + ANSI_RESET);
            }
        } catch (Exception e) {
            print_error("Error querying Neo4J server root URL");
            print_error(e.getMessage());
            System.exit(1);
        }

        // Try authentication
        try {
            if (this.verbose_output) {
                System.out.println("Checking credentials for Neo4J... " + ANSI_DIM);
            } else {
                System.out.print("Checking credentials for Neo4J... ");
            }

            Unirest.get(
                this.server_root_url + REST_ENDPOINT
            ).asJson();

            if (this.verbose_output) {
                System.out.println(ANSI_RESET + "Checking credentials for Neo4J... " + ANSI_GREEN + "\u2713" + ANSI_RESET);
            } else {
                System.out.println(ANSI_GREEN + "\u2713" + ANSI_RESET);
            }
        } catch (Exception e) {
            print_error("Error querying Neo4J REST endpoint");
            print_error(e.getMessage());
            System.exit(1);
        }
    }

    public void importOntologies() {
        long loadTimeSec;
        long loadTimeMin;

        try {
            if (this.verbose_output) {
                System.out.println("Loading " + this.ontology_acronym + "... " + ANSI_DIM);
            } else {
                System.out.print("Loading " + this.ontology_acronym + "... ");
            }

            long start = System.nanoTime();
            this.loadOntology();
            long end = System.nanoTime();
            loadTimeMin = TimeUnit.NANOSECONDS.toMinutes(end - start);
            loadTimeSec = TimeUnit.NANOSECONDS.toSeconds(end - start) - (60 * loadTimeMin);

            if (this.verbose_output) {
                System.out.println(ANSI_RESET + "Loading " + this.ontology_acronym + "... " + ANSI_GREEN + "\u2713" + ANSI_RESET);
            } else {
                System.out.println(
                    ANSI_GREEN + "\u2713 " + ANSI_RESET +
                        ANSI_DIM + "  ("  + loadTimeMin + " min and " + loadTimeSec + " sec)" + ANSI_RESET_DIM
                );
            }
        } catch (Exception e) {
            print_error("Error loading the ontology");
            print_error(e.getMessage());
            System.exit(1);
        }

        long importTimeSec;
        long importTimeMin;
        try {
            if (this.verbose_output) {
                System.out.println("Importing " + this.ontology_acronym + "... " + ANSI_DIM);
            } else {
                System.out.print("Importing " + this.ontology_acronym + "... ");
            }

            long start = System.nanoTime();
            this.importOntology();
            long end = System.nanoTime();
            importTimeMin = TimeUnit.NANOSECONDS.toMinutes(end - start);
            importTimeSec = TimeUnit.NANOSECONDS.toSeconds(end - start) - (60 * importTimeMin);

            if (this.verbose_output) {
                System.out.println(ANSI_RESET + "Importing " + this.ontology_acronym + "... " + ANSI_GREEN + "\u2713" + ANSI_RESET);
            } else {
                System.out.println(
                    ANSI_GREEN + "\u2713" + ANSI_RESET +
                        ANSI_DIM + "  (" + importTimeMin + " min and " + importTimeSec + " sec)" + ANSI_RESET_DIM
                );
            }
        } catch (Exception e) {
            print_error("Error importing the ontology");
            print_error(e.getMessage());
            System.exit(1);
        }
    }

    public void loadOntology() throws Exception {
        this.manager = OWLManager.createOWLOntologyManager();

        Path ontFilePath = Paths.get(this.path_to_owl);
        if (Files.notExists(ontFilePath)) {
            throw new Exception("The option `-o` doesn't point to a file.");
        }

        if (!this.no_local_owl_files) {
            this.manager.addIRIMapper(
                new AutoIRIMapper(
                    ontFilePath.getParent().toAbsolutePath().normalize().toFile(), true
                )
            );
        }
{'fraction_non_alphanumeric': 0.10457814418523066, 'fraction_numerical': 0.007507454832485529, 'mean_word_length': 1.9375515251442703, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2367907', 'n_tokens_mistral': 8276, 'n_tokens_neox': 7862, 'n_words': 1710}