<commit_before>/*
 * MindmapsDB - A Distributed Semantic Database
 * Copyright (C) 2016  Mindmaps Research Ltd
 *
 * MindmapsDB is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MindmapsDB is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MindmapsDB. If not, see <http://www.gnu.org/licenses/gpl.txt>.
 */
package io.mindmaps.migration.owl;

import io.mindmaps.MindmapsGraph;
import io.mindmaps.concept.RelationType;
import io.mindmaps.Mindmaps;
import org.semanticweb.owlapi.apibinding.OWLManager;

import java.io.File;

/**
 * <p>
 * Main program to migrate an OWL knowledge base into a Mindmaps knowledge graph. Expected 
 * arguments are an OWL file and a Mindmaps Engine URL. At a minimum an OWL file must be provided. 
 * Note that the OWLAPI is not very good at intelligently resolving imports, such as looking in the
 * same folder etc. To import a large ontology made up of multiple imports scattered around in files, 
 * the easiest thing is to use protege to "merge" them into a single ontology file with all axioms 
 * inside it.
 * </p>
 * 
 * @author borislav
 *
 */
public class Main {
    
    static void die(String errorMsg) {
        System.out.println(errorMsg);
        System.out.println("\nSyntax: ./migration.sh owl -file <owl filename> [-graph <graph name>] [-engine <Mindmaps engine URL>]");
        System.exit(-1);
    }
        
    public static void main(String[] argv) {
        String owlFilename = null;
        String engineUrl = null;
        String graphName = null;
        
        for (int i = 0; i < argv.length; i++) {
            if ("-file".equals(argv[i]))
                owlFilename = argv[++i];
            else if ("-graph".equals(argv[i]))
                graphName = argv[++i];
            else if ("-engine".equals(argv[i]))
                engineUrl = argv[++i];
            else if("owl".equals(argv[0]))
                continue;
            else
                die("Unknown option " + argv[i]);
        }       
        
        if (owlFilename == null)
            die("Please specify owl file with the -owl option.");
        File owlfile = new File(owlFilename);
        if (!owlfile.exists())
            die("Cannot find file: " + owlFilename);
        if (graphName == null)
            graphName = owlfile.getName().replace(".", "_");
        
        System.out.println("Migrating " + owlFilename + " using MM Engine " + 
                            (engineUrl == null ? "local" : engineUrl ) + " into graph " + graphName);
        
        OWLMigrator migrator = new OWLMigrator();
        
        try {
            MindmapsGraph graph = engineUrl == null ? Mindmaps.factory(Mindmaps.DEFAULT_URI, graphName).getGraph()
                                                    : Mindmaps.factory(engineUrl, graphName).getGraph();
            migrator.graph(graph)
                    .ontology(OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(owlfile))
                    .migrate();
            System.out.println("Migration successfully completed!");
        }
        catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
        finally {
            if (migrator.graph() != null)
                migrator.graph().close();
        }
    }

    // stub to test and throw away stuff
    static void test() {
        try {
            MindmapsGraph graph = Mindmaps.factory(Mindmaps.DEFAULT_URI, "onco").getGraph();
            graph.putRelationType("authorship");
            RelationType reltype = (RelationType)graph.getType("relation-type").instances().stream().findFirst().get();
            reltype.hasRoles().forEach(System.out::println);
            reltype.hasRole(graph.putRoleType("authro1")).hasRole(graph.putRoleType("author2"));
            graph.commit();
        }
        catch (Throwable t) {
            t.printStackTrace(System.err);
        }
        System.exit(0);
    }
}<commit_msg>Removing unused method in OWL migrator (#427)<commit_after>/*
 * MindmapsDB - A Distributed Semantic Database
 * Copyright (C) 2016  Mindmaps Research Ltd
 *
 * MindmapsDB is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MindmapsDB is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MindmapsDB. If not, see <http://www.gnu.org/licenses/gpl.txt>.
 */
package io.mindmaps.migration.owl;

import io.mindmaps.MindmapsGraph;
import io.mindmaps.concept.RelationType;
import io.mindmaps.Mindmaps;
import org.semanticweb.owlapi.apibinding.OWLManager;

import java.io.File;

/**
 * <p>
 * Main program to migrate an OWL knowledge base into a Mindmaps knowledge graph. Expected 
 * arguments are an OWL file and a Mindmaps Engine URL. At a minimum an OWL file must be provided. 
 * Note that the OWLAPI is not very good at intelligently resolving imports, such as looking in the
 * same folder etc. To import a large ontology made up of multiple imports scattered around in files, 
 * the easiest thing is to use protege to "merge" them into a single ontology file with all axioms 
 * inside it.
 * </p>
 * 
 * @author borislav
 *
 */
public class Main {
    
    static void die(String errorMsg) {
        System.out.println(errorMsg);
        System.out.println("\nSyntax: ./migration.sh owl -file <owl filename> [-graph <graph name>] [-engine <Mindmaps engine URL>]");
        System.exit(-1);
    }

    public static void main(String[] argv) {
        String owlFilename = null;
        String engineUrl = null;
        String graphName = null;

        for (int i = 0; i < argv.length; i++) {
            if ("-file".equals(argv[i]))
                owlFilename = argv[++i];
            else if ("-graph".equals(argv[i]))
                graphName = argv[++i];
            else if ("-engine".equals(argv[i]))
                engineUrl = argv[++i];
            else if("owl".equals(argv[0]))
                continue;
            else
                die("Unknown option " + argv[i]);
        }

        if (owlFilename == null)
            die("Please specify owl file with the -owl option.");
        File owlfile = new File(owlFilename);
        if (!owlfile.exists())
            die("Cannot find file: " + owlFilename);
        if (graphName == null)
            graphName = owlfile.getName().replace(".", "_");

        System.out.println("Migrating " + owlFilename + " using MM Engine " +
                            (engineUrl == null ? "local" : engineUrl ) + " into graph " + graphName);

        OWLMigrator migrator = new OWLMigrator();

        try {
            MindmapsGraph graph = engineUrl == null ? Mindmaps.factory(Mindmaps.DEFAULT_URI, graphName).getGraph()
                                                    : Mindmaps.factory(engineUrl, graphName).getGraph();
            migrator.graph(graph)
                    .ontology(OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(owlfile))
                    .migrate();
            System.out.println("Migration successfully completed!");
        }
        catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
        finally {
            if (migrator.graph() != null)
                migrator.graph().close();
        }
    }
}
{'fraction_non_alphanumeric': 0.10598227474150665, 'fraction_numerical': 0.0029542097488921715, 'mean_word_length': 2.2539046856227474, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6080408', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2163, 'n_words': 717}