<commit_before>package com.altamiracorp.lumify.core.cmdline;

import com.altamiracorp.lumify.core.exception.LumifyException;
import com.altamiracorp.lumify.core.model.ontology.*;
import com.altamiracorp.lumify.core.model.properties.LumifyProperties;
import com.altamiracorp.lumify.core.user.User;
import com.altamiracorp.securegraph.Graph;
import com.altamiracorp.securegraph.property.StreamingPropertyValue;
import com.google.inject.Inject;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.OWLOntologyDocumentSource;
import org.semanticweb.owlapi.io.ReaderDocumentSource;
import org.semanticweb.owlapi.model.*;

import java.io.*;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

public class OwlImport extends CommandLineBase {
    public static final String NS_XML_URI = "http://www.w3.org/XML/1998/namespace";

    private OntologyRepository ontologyRepository;
    private Graph graph;
    private String inFileName;
    private File inDir;
    private String documentIRIString;

    public static void main(String[] args) throws Exception {
        int res = new OwlImport().run(args);
        if (res != 0) {
            System.exit(res);
        }
    }

    @Override
    protected Options getOptions() {
        Options options = super.getOptions();

        options.addOption(
                OptionBuilder
                        .withLongOpt("in")
                        .withDescription("The input OWL file")
                        .isRequired()
                        .hasArg(true)
                        .withArgName("fileName")
                        .create("i")
        );

        options.addOption(
                OptionBuilder
                        .withLongOpt("iri")
                        .withDescription("The document IRI (URI used for prefixing concepts)")
                        .hasArg(true)
                        .withArgName("uri")
                        .create()
        );

        return options;
    }

    @Override
    protected void processOptions(CommandLine cmd) throws Exception {
        super.processOptions(cmd);
        this.inFileName = cmd.getOptionValue("in");
        if (cmd.hasOption("iri")) {
            this.documentIRIString = cmd.getOptionValue("iri");
        } else {
            this.documentIRIString = new File(this.inFileName).toURI().toString();
        }
    }

    @Override
    protected int run(CommandLine cmd) throws Exception {
        File inFile = new File(this.inFileName);
        IRI documentIRI = IRI.create(this.documentIRIString);
        importFile(inFile, documentIRI, getUser());
        return 0;
    }

    public void importFile(File inFile, IRI documentIRI, User user) throws OWLOntologyCreationException, IOException {
        inDir = inFile.getParentFile();

        OWLOntologyManager m = OWLManager.createOWLOntologyManager();
        Reader inFileReader = new FileReader(inFile);
        OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration();

        loadBaseOntology(m, config);

        OWLOntologyDocumentSource documentSource = new ReaderDocumentSource(inFileReader, documentIRI);
        OWLOntology o = m.loadOntologyFromOntologyDocument(documentSource, config);<commit_msg>wikipedia owl file working<commit_after>package com.altamiracorp.lumify.core.cmdline;

import com.altamiracorp.lumify.core.exception.LumifyException;
import com.altamiracorp.lumify.core.model.ontology.*;
import com.altamiracorp.lumify.core.model.properties.LumifyProperties;
import com.altamiracorp.lumify.core.user.User;
import com.altamiracorp.securegraph.Graph;
import com.altamiracorp.securegraph.property.StreamingPropertyValue;
import com.google.inject.Inject;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.OWLOntologyDocumentSource;
import org.semanticweb.owlapi.io.ReaderDocumentSource;
import org.semanticweb.owlapi.model.*;

import java.io.*;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

public class OwlImport extends CommandLineBase {
    public static final String NS_XML_URI = "http://www.w3.org/XML/1998/namespace";

    private OntologyRepository ontologyRepository;
    private Graph graph;
    private String inFileName;
    private File inDir;
    private String documentIRIString;

    public static void main(String[] args) throws Exception {
        int res = new OwlImport().run(args);
        if (res != 0) {
            System.exit(res);
        }
    }

    @Override
    protected Options getOptions() {
        Options options = super.getOptions();

        options.addOption(
                OptionBuilder
                        .withLongOpt("in")
                        .withDescription("The input OWL file")
                        .isRequired()
                        .hasArg(true)
                        .withArgName("fileName")
                        .create("i")
        );

        options.addOption(
                OptionBuilder
                        .withLongOpt("iri")
                        .withDescription("The document IRI (URI used for prefixing concepts)")
                        .hasArg(true)
                        .withArgName("uri")
                        .create()
        );

        return options;
    }

    @Override
    protected void processOptions(CommandLine cmd) throws Exception {
        super.processOptions(cmd);
        this.inFileName = cmd.getOptionValue("in");
        if (cmd.hasOption("iri")) {
            this.documentIRIString = cmd.getOptionValue("iri");
        } else {
            this.documentIRIString = new File(this.inFileName).toURI().toString();
        }
    }

    @Override
    protected int run(CommandLine cmd) throws Exception {
        File inFile = new File(this.inFileName);
        IRI documentIRI = IRI.create(this.documentIRIString);
        importFile(inFile, documentIRI, getUser());
        return 0;
    }

    public void importFile(File inFile, IRI documentIRI, User user) throws OWLOntologyCreationException, IOException {
        inDir = inFile.getParentFile();

        OWLOntologyManager m = OWLManager.createOWLOntologyManager();
        Reader inFileReader = new FileReader(inFile);
        OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration();
        config.setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT);

        loadBaseOntology(m, config);

        OWLOntologyDocumentSource documentSource = new ReaderDocumentSource(inFileReader, documentIRI);
        OWLOntology o = m.loadOntologyFromOntologyDocument(documentSource, config);
{'fraction_non_alphanumeric': 0.09228769497400346, 'fraction_numerical': 0.002021952628538417, 'mean_word_length': 2.6237571951857666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3405725', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1889, 'n_words': 371}