<commit_before>package it.unibz.inf.ontop.spec.mapping.transformer.impl;

import com.google.inject.Inject;
import it.unibz.inf.ontop.dbschema.DBMetadata;
import it.unibz.inf.ontop.injection.OntopMappingSettings;
import it.unibz.inf.ontop.injection.SpecificationFactory;
import it.unibz.inf.ontop.spec.mapping.Mapping;
import it.unibz.inf.ontop.spec.ontology.ClassifiedTBox;
import it.unibz.inf.ontop.spec.ontology.MappingVocabularyExtractor;
import it.unibz.inf.ontop.spec.ontology.Ontology;
import it.unibz.inf.ontop.spec.OBDASpecification;
import it.unibz.inf.ontop.spec.mapping.transformer.*;

public class DefaultMappingTransformer implements MappingTransformer {

    private final MappingCanonicalRewriter mappingCanonicalRewriter;
    private final MappingNormalizer mappingNormalizer;
    private final MappingSaturator mappingSaturator;
    private final ABoxFactIntoMappingConverter factConverter;
    private final MappingMerger mappingMerger;
    private final OntopMappingSettings settings;
    private final MappingSameAsInverseRewriter sameAsInverseRewriter;
    private final SpecificationFactory specificationFactory;
    private final MappingVocabularyExtractor vocabularyExtractor;

    @Inject
    private DefaultMappingTransformer(MappingCanonicalRewriter mappingCanonicalRewriter,
                                     MappingNormalizer mappingNormalizer,
                                     MappingSaturator mappingSaturator,
                                     ABoxFactIntoMappingConverter inserter,
                                     MappingMerger mappingMerger,
                                     OntopMappingSettings settings,
                                     MappingSameAsInverseRewriter sameAsInverseRewriter,
                                     SpecificationFactory specificationFactory,
                                     MappingVocabularyExtractor vocabularyExtractor) {
        this.mappingCanonicalRewriter = mappingCanonicalRewriter;
        this.mappingNormalizer = mappingNormalizer;
        this.mappingSaturator = mappingSaturator;
        this.factConverter = inserter;
        this.mappingMerger = mappingMerger;
        this.settings = settings;
        this.sameAsInverseRewriter = sameAsInverseRewriter;
        this.specificationFactory = specificationFactory;
        this.vocabularyExtractor = vocabularyExtractor;
    }

    @Override
    public OBDASpecification transform(Mapping mapping, DBMetadata dbMetadata, Ontology ontology) {

        Mapping factsAsMapping = factConverter.convert(ontology.abox(), mapping.getExecutorRegistry(),
                settings.isOntologyAnnotationQueryingEnabled(), mapping.getMetadata().getUriTemplateMatcher());
        Mapping mappingWithFacts = mappingMerger.merge(mapping, factsAsMapping);

        Mapping sameAsOptimizedMapping = sameAsInverseRewriter.rewrite(mappingWithFacts, dbMetadata);
        Mapping canonicalMapping = mappingCanonicalRewriter.rewrite(sameAsOptimizedMapping, dbMetadata);
        Mapping saturatedMapping = mappingSaturator.saturate(canonicalMapping, dbMetadata, ontology.tbox());
        Mapping normalizedMapping = mappingNormalizer.normalize(saturatedMapping);

        return specificationFactory.createSpecification(normalizedMapping, dbMetadata, ontology.tbox());
    }

    @Override
    public OBDASpecification transform(Mapping mapping, DBMetadata dbMetadata) {

        Mapping sameAsOptimizedMapping = sameAsInverseRewriter.rewrite(mapping, dbMetadata);
        Mapping canonicalMapping = mappingCanonicalRewriter.rewrite(sameAsOptimizedMapping, dbMetadata);
        Mapping saturatedMapping = mappingSaturator.saturate(canonicalMapping, dbMetadata);
        Mapping normalizedMapping = mappingNormalizer.normalize(saturatedMapping);

        // extract empty TBox (just the list of classes / properties)
        ClassifiedTBox tBox = vocabularyExtractor.extractOntology(mapping);

        return specificationFactory.createSpecification(normalizedMapping, dbMetadata, tBox);
    }
}
<commit_msg>localising MappingVocabularyExtractor<commit_after>package it.unibz.inf.ontop.spec.mapping.transformer.impl;

import com.google.inject.Inject;
import it.unibz.inf.ontop.dbschema.DBMetadata;
import it.unibz.inf.ontop.injection.OntopMappingSettings;
import it.unibz.inf.ontop.injection.SpecificationFactory;
import it.unibz.inf.ontop.spec.mapping.Mapping;
import it.unibz.inf.ontop.spec.ontology.ClassifiedTBox;
import it.unibz.inf.ontop.spec.ontology.MappingVocabularyExtractor;
import it.unibz.inf.ontop.spec.ontology.Ontology;
import it.unibz.inf.ontop.spec.OBDASpecification;
import it.unibz.inf.ontop.spec.mapping.transformer.*;
import it.unibz.inf.ontop.spec.ontology.impl.OntologyBuilderImpl;

public class DefaultMappingTransformer implements MappingTransformer {

    private final MappingCanonicalRewriter mappingCanonicalRewriter;
    private final MappingNormalizer mappingNormalizer;
    private final MappingSaturator mappingSaturator;
    private final ABoxFactIntoMappingConverter factConverter;
    private final MappingMerger mappingMerger;
    private final OntopMappingSettings settings;
    private final MappingSameAsInverseRewriter sameAsInverseRewriter;
    private final SpecificationFactory specificationFactory;
    private final MappingVocabularyExtractor vocabularyExtractor;

    @Inject
    private DefaultMappingTransformer(MappingCanonicalRewriter mappingCanonicalRewriter,
                                     MappingNormalizer mappingNormalizer,
                                     MappingSaturator mappingSaturator,
                                     ABoxFactIntoMappingConverter inserter,
                                     MappingMerger mappingMerger,
                                     OntopMappingSettings settings,
                                     MappingSameAsInverseRewriter sameAsInverseRewriter,
                                     SpecificationFactory specificationFactory,
                                     MappingVocabularyExtractor vocabularyExtractor) {
        this.mappingCanonicalRewriter = mappingCanonicalRewriter;
        this.mappingNormalizer = mappingNormalizer;
        this.mappingSaturator = mappingSaturator;
        this.factConverter = inserter;
        this.mappingMerger = mappingMerger;
        this.settings = settings;
        this.sameAsInverseRewriter = sameAsInverseRewriter;
        this.specificationFactory = specificationFactory;
        this.vocabularyExtractor = vocabularyExtractor;
    }

    @Override
    public OBDASpecification transform(Mapping mapping, DBMetadata dbMetadata, Ontology ontology) {

        Mapping factsAsMapping = factConverter.convert(ontology.abox(), mapping.getExecutorRegistry(),
                settings.isOntologyAnnotationQueryingEnabled(), mapping.getMetadata().getUriTemplateMatcher());
        Mapping mappingWithFacts = mappingMerger.merge(mapping, factsAsMapping);

        Mapping sameAsOptimizedMapping = sameAsInverseRewriter.rewrite(mappingWithFacts, dbMetadata);
        Mapping canonicalMapping = mappingCanonicalRewriter.rewrite(sameAsOptimizedMapping, dbMetadata);
        Mapping saturatedMapping = mappingSaturator.saturate(canonicalMapping, dbMetadata, ontology.tbox());
        Mapping normalizedMapping = mappingNormalizer.normalize(saturatedMapping);

        return specificationFactory.createSpecification(normalizedMapping, dbMetadata, ontology.tbox());
    }

    @Override
    public OBDASpecification transform(Mapping mapping, DBMetadata dbMetadata) {

        ClassifiedTBox emptyTBox = OntologyBuilderImpl.builder().build().tbox();

        Mapping sameAsOptimizedMapping = sameAsInverseRewriter.rewrite(mapping, dbMetadata);
        Mapping canonicalMapping = mappingCanonicalRewriter.rewrite(sameAsOptimizedMapping, dbMetadata);
        Mapping saturatedMapping = mappingSaturator.saturate(canonicalMapping, dbMetadata, emptyTBox);
        Mapping normalizedMapping = mappingNormalizer.normalize(saturatedMapping);

        return specificationFactory.createSpecification(normalizedMapping, dbMetadata, emptyTBox);
    }
}

{'fraction_non_alphanumeric': 0.06138296561074818, 'fraction_numerical': 0.0, 'mean_word_length': 3.6259977194982898, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1470142', 'n_tokens_mistral': 2147, 'n_tokens_neox': 2015, 'n_words': 351}