<commit_before>package it.unibz.krdb.obda.LUBM;


import it.unibz.krdb.obda.io.DataManager;
import it.unibz.krdb.obda.model.DataSource;
import it.unibz.krdb.obda.model.OBDADataFactory;
import it.unibz.krdb.obda.model.OBDAModel;
import it.unibz.krdb.obda.model.Statement;
import it.unibz.krdb.obda.model.impl.OBDADataFactoryImpl;
import it.unibz.krdb.obda.owlrefplatform.core.DummyOBDAPlatformFactoryImpl;
import it.unibz.krdb.obda.owlrefplatform.core.OBDAOWLReformulationPlatform;
import it.unibz.krdb.obda.owlrefplatform.core.OBDAOWLReformulationPlatformFactory;
import it.unibz.krdb.obda.queryanswering.QueryControllerEntity;
import it.unibz.krdb.obda.queryanswering.QueryControllerQuery;
import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class LUBMDLLiteQueryExecutionToolSemanticIndex {

    public static Logger log = LoggerFactory.getLogger(LUBMDLLiteQueryExecutionToolSemanticIndex.class);


    public static void main(String[] args) {
        String owlfile = "src/test/resources/test/ontologies/scenarios/lubm/univ-bench-dllitea.owl";
        String obdafile = "src/test/resources/test/ontologies/scenarios/lubm/univ-bench-dllitea.obda";

        // Loading the OWL file
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology;
        try {
            ontology = manager.loadOntologyFromPhysicalURI((new File(owlfile)).toURI());

            // Loading the OBDA data (note, the obda file must be in the same
            // folder as the owl file
            OBDADataFactory obdafac = OBDADataFactoryImpl.getInstance();
            OBDAModel obdamodel = obdafac.getOBDAModel();


            DataManager ioManager = new DataManager(obdamodel);
            ioManager.loadOBDADataFromURI(new File(obdafile).toURI(), ontology.getURI(), obdamodel.getPrefixManager());

            DataSource ds = obdafac.getJDBCDataSource(CSVLoader.url, CSVLoader.username, CSVLoader.password, CSVLoader.driver);
            obdamodel.getDatasourcesController().addDataSource(ds);

            OBDAOWLReformulationPlatformFactory factory = new DummyOBDAPlatformFactoryImpl();

            factory.setOBDAController(obdamodel);

            OBDAOWLReformulationPlatform reasoner = (OBDAOWLReformulationPlatform) factory.createReasoner(manager);

            reasoner.loadOntologies(manager.getOntologies());

            // Loading a set of configurations for the reasoner and giving them
            // to quonto
            // Properties properties = new Properties();
            // properties.load(new FileInputStream(configFile));
            // QuontoConfiguration config = new QuontoConfiguration(properties);
            // reasoner.setConfiguration(config);

            // One time classification call.
            reasoner.classify();

            // Now we are ready for querying

            for (QueryControllerEntity entity : obdamodel.getQueryController().getElements()) {
                if (!(entity instanceof QueryControllerQuery)) {
                    continue;
                }
                QueryControllerQuery query = (QueryControllerQuery) entity;
                String sparqlquery = query.getQuery();
                String id = query.getID();
                log.info("##################  Executing query: {}", id);


                Statement st = reasoner.getStatement();

                long start = System.currentTimeMillis();
                String rewriting = st.getRewriting(sparqlquery);
                long end = System.currentTimeMillis();
                log.info("Total time for rewriting: {}", end - start);

<commit_msg>Testing unfolding<commit_after>package it.unibz.krdb.obda.LUBM;


import it.unibz.krdb.obda.io.DataManager;
import it.unibz.krdb.obda.model.DataSource;
import it.unibz.krdb.obda.model.OBDADataFactory;
import it.unibz.krdb.obda.model.OBDAModel;
import it.unibz.krdb.obda.model.Statement;
import it.unibz.krdb.obda.model.impl.OBDADataFactoryImpl;
import it.unibz.krdb.obda.owlrefplatform.core.DummyOBDAPlatformFactoryImpl;
import it.unibz.krdb.obda.owlrefplatform.core.OBDAOWLReformulationPlatform;
import it.unibz.krdb.obda.owlrefplatform.core.OBDAOWLReformulationPlatformFactory;
import it.unibz.krdb.obda.queryanswering.QueryControllerEntity;
import it.unibz.krdb.obda.queryanswering.QueryControllerQuery;
import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class LUBMDLLiteQueryExecutionToolSemanticIndex {

    public static Logger log = LoggerFactory.getLogger(LUBMDLLiteQueryExecutionToolSemanticIndex.class);


    public static void main(String[] args) {
        String owlfile = "src/test/resources/test/ontologies/scenarios/lubm/univ-bench-dllitea.owl";
        String obdafile = "src/test/resources/test/ontologies/scenarios/lubm/univ-bench-dllitea.obda";

        // Loading the OWL file
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology;
        try {
            ontology = manager.loadOntologyFromPhysicalURI((new File(owlfile)).toURI());

            // Loading the OBDA data (note, the obda file must be in the same
            // folder as the owl file
            OBDADataFactory obdafac = OBDADataFactoryImpl.getInstance();
            OBDAModel obdamodel = obdafac.getOBDAModel();


            DataManager ioManager = new DataManager(obdamodel);
            ioManager.loadOBDADataFromURI(new File(obdafile).toURI(), ontology.getURI(), obdamodel.getPrefixManager());

            DataSource ds = obdafac.getJDBCDataSource(CSVLoader.url, CSVLoader.username, CSVLoader.password, CSVLoader.driver);
            obdamodel.getDatasourcesController().addDataSource(ds);

            OBDAOWLReformulationPlatformFactory factory = new DummyOBDAPlatformFactoryImpl();

            factory.setOBDAController(obdamodel);

            OBDAOWLReformulationPlatform reasoner = (OBDAOWLReformulationPlatform) factory.createReasoner(manager);

            reasoner.loadOntologies(manager.getOntologies());

            // Loading a set of configurations for the reasoner and giving them
            // to quonto
            // Properties properties = new Properties();
            // properties.load(new FileInputStream(configFile));
            // QuontoConfiguration config = new QuontoConfiguration(properties);
            // reasoner.setConfiguration(config);

            // One time classification call.
            reasoner.classify();

            // Now we are ready for querying

            for (QueryControllerEntity entity : obdamodel.getQueryController().getElements()) {
                if (!(entity instanceof QueryControllerQuery)) {
                    continue;
                }
                QueryControllerQuery query = (QueryControllerQuery) entity;
                String sparqlquery = query.getQuery();
                String id = query.getID();
                log.info("##################  Executing query: {}", id);


                Statement st = reasoner.getStatement();

                long start = System.currentTimeMillis();
                String rewriting = st.getRewriting(sparqlquery);
                long end = System.currentTimeMillis();
                log.info("Total time for rewriting: {}", end - start);

                start = System.currentTimeMillis();
                String unfolding = st.getUnfolding(sparqlquery, false);
                end = System.currentTimeMillis();
                log.info("Total time for unfolding: {}", end - start);


{'fraction_non_alphanumeric': 0.09811176320489921, 'fraction_numerical': 0.0005103342689461597, 'mean_word_length': 2.9491183879093197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6822284', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2240, 'n_words': 401}