<commit_before>/**
 * 
 */
package com.github.podd.prototype;

import java.io.IOException;
import java.util.UUID;

import net.fortytwo.sesametools.URITranslator;

import org.junit.Assert;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.model.vocabulary.OWL;
import org.openrdf.model.vocabulary.RDF;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.util.RDFInserter;
import org.openrdf.rio.RDFFormat;
import org.semanticweb.owlapi.formats.RDFXMLOntologyFormatFactory;
import org.semanticweb.owlapi.io.StreamDocumentSource;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyChangeException;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.SetOntologyID;
import org.semanticweb.owlapi.profiles.OWLProfile;
import org.semanticweb.owlapi.profiles.OWLProfileRegistry;
import org.semanticweb.owlapi.profiles.OWLProfileReport;
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
import org.semanticweb.owlapi.reasoner.InferenceType;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException;
import org.semanticweb.owlapi.reasoner.TimeOutException;
import org.semanticweb.owlapi.rio.RioMemoryTripleSource;
import org.semanticweb.owlapi.rio.RioParserImpl;
import org.semanticweb.owlapi.rio.RioRenderer;
import org.semanticweb.owlapi.util.InferredOntologyGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A selection of utilities used to create the prototype.
 * 
 * @author <NAME> <EMAIL>
 * 
 */
public class PoddPrototypeUtils
{
    /**
     * This URI is not currently in the Sesame OWL namespace, so we create a constant here as it is
     * vital to our strategy.
     */
    public static final URI OWL_VERSION_IRI = ValueFactoryImpl.getInstance().createURI(OWL.NAMESPACE, "versionIRI");
    
    /**
     * The OMV vocabulary defines a property for the current version of an ontology, so we are
     * reusing it here.
     */
    public static final URI OMV_CURRENT_VERSION = ValueFactoryImpl.getInstance().createURI(
            "http://omv.ontoware.org/ontology#", "currentVersion");
    
    /**
     * Creating a property for PODD to track the currentInferredVersion for the inferred axioms
     * ontology when linking from the ontology IRI.
     */
    public static final URI PODD_BASE_CURRENT_INFERRED_VERSION = ValueFactoryImpl.getInstance().createURI(
            "http://purl.org/podd/ns/poddBase#", "currentInferredVersion");
    
    /**
     * Creating a property for PODD to track the inferredVersion for the inferred axioms ontology of
     * a particular versioned ontology.
     */
    public static final URI PODD_BASE_INFERRED_VERSION = ValueFactoryImpl.getInstance().createURI(
            "http://purl.org/podd/ns/poddBase#", "inferredVersion");
    
    /**
     * An arbitrary prefix to use for automatically assigning ontology IRIs to inferred ontologies.
     * There are no versions delegated to inferred ontologies, and the ontology IRI is generated
     * using the version IRI of the original ontology, which must be unique.
     */
    private static final String INFERRED_PREFIX = "urn:podd:inferred:ontologyiriprefix:";
    
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    
    /**
     * The manager that will be used to manage the Schema Ontologies.
     * 
     * TODO: Decide how to manage PODD Artifact ontologies that will typically have smaller
     * lifetimes than Schema Ontologies which will stay in the manager for the lifetime of the
     * manager, until the next shutdown or maintenance period when they may be changed. PODD
     * Artifact ontologies may import Schema Ontologies so their manager needs to be able to access
     * the list of Schema Ontologies. However, PODD Artifact ontologies must not stay in the manager
     * for long periods of time or they will cause unsustainable memory growth, particularly for
     * large ontologies with many versions.
     * 
     * TODO: How does an edit conflict resolution strategy work in relation to this manager.
     * Ideally, we should also only be storing the latest version of a PODD Artifact in the manager.
     * If we are performing edit conflict resolution based solely on RDF triples and not OWL Axioms,
     * then we may be able to perform the diff externally. See the Protege OWL Diff code for
     * examples of how to diff ontologies.<commit_msg>add note about moving the currentInferredVersion and inferredVersion URIs out to an external ontology<commit_after>/**
 * 
 */
package com.github.podd.prototype;

import java.io.IOException;
import java.util.UUID;

import net.fortytwo.sesametools.URITranslator;

import org.junit.Assert;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.model.vocabulary.OWL;
import org.openrdf.model.vocabulary.RDF;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.util.RDFInserter;
import org.openrdf.rio.RDFFormat;
import org.semanticweb.owlapi.formats.RDFXMLOntologyFormatFactory;
import org.semanticweb.owlapi.io.StreamDocumentSource;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyChangeException;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.SetOntologyID;
import org.semanticweb.owlapi.profiles.OWLProfile;
import org.semanticweb.owlapi.profiles.OWLProfileRegistry;
import org.semanticweb.owlapi.profiles.OWLProfileReport;
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
import org.semanticweb.owlapi.reasoner.InferenceType;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException;
import org.semanticweb.owlapi.reasoner.TimeOutException;
import org.semanticweb.owlapi.rio.RioMemoryTripleSource;
import org.semanticweb.owlapi.rio.RioParserImpl;
import org.semanticweb.owlapi.rio.RioRenderer;
import org.semanticweb.owlapi.util.InferredOntologyGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A selection of utilities used to create the prototype.
 * 
 * @author <NAME> <EMAIL>
 * 
 */
public class PoddPrototypeUtils
{
    /**
     * This URI is not currently in the Sesame OWL namespace, so we create a constant here as it is
     * vital to our strategy.
     */
    public static final URI OWL_VERSION_IRI = ValueFactoryImpl.getInstance().createURI(OWL.NAMESPACE, "versionIRI");
    
    /**
     * The OMV vocabulary defines a property for the current version of an ontology, so we are
     * reusing it here.
     */
    public static final URI OMV_CURRENT_VERSION = ValueFactoryImpl.getInstance().createURI(
            "http://omv.ontoware.org/ontology#", "currentVersion");
    
    /**
     * Creating a property for PODD to track the currentInferredVersion for the inferred axioms
     * ontology when linking from the ontology IRI.
     * 
     * TODO: Put this in an external ontology somewhere so it isn't dependent on PODD.
     */
    public static final URI PODD_BASE_CURRENT_INFERRED_VERSION = ValueFactoryImpl.getInstance().createURI(
            "http://purl.org/podd/ns/poddBase#", "currentInferredVersion");
    
    /**
     * Creating a property for PODD to track the inferredVersion for the inferred axioms ontology of
     * a particular versioned ontology.
     * 
     * TODO: Put this in an external ontology somewhere so it isn't dependent on PODD.
     */
    public static final URI PODD_BASE_INFERRED_VERSION = ValueFactoryImpl.getInstance().createURI(
            "http://purl.org/podd/ns/poddBase#", "inferredVersion");
    
    /**
     * An arbitrary prefix to use for automatically assigning ontology IRIs to inferred ontologies.
     * There are no versions delegated to inferred ontologies, and the ontology IRI is generated
     * using the version IRI of the original ontology, which must be unique.
     */
    private static final String INFERRED_PREFIX = "urn:podd:inferred:ontologyiriprefix:";
    
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    
    /**
     * The manager that will be used to manage the Schema Ontologies.
     * 
     * TODO: Decide how to manage PODD Artifact ontologies that will typically have smaller
     * lifetimes than Schema Ontologies which will stay in the manager for the lifetime of the
     * manager, until the next shutdown or maintenance period when they may be changed. PODD
     * Artifact ontologies may import Schema Ontologies so their manager needs to be able to access
     * the list of Schema Ontologies. However, PODD Artifact ontologies must not stay in the manager
     * for long periods of time or they will cause unsustainable memory growth, particularly for
     * large ontologies with many versions.
     * 
     * TODO: How does an edit conflict resolution strategy work in relation to this manager.
     * Ideally, we should also only be storing the latest version of a PODD Artifact in the manager.
     * If we are performing edit conflict resolution based solely on RDF triples and not OWL Axioms,
     * then we may be able to perform the diff externally. See the Protege OWL Diff code for
     * examples of how to diff ontologies.
{'fraction_non_alphanumeric': 0.07420706163973669, 'fraction_numerical': 0.00039896269698783165, 'mean_word_length': 4.064141414141414, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4156943', 'n_tokens_mistral': 3023, 'n_tokens_neox': 2916, 'n_words': 892}