<commit_before>package uk.ac.ebi.spot.ols; /**
 * Created by catherineleroy on 09/06/2015.
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import uk.ac.ebi.spot.ols.config.OntologyResourceConfig;
import uk.ac.ebi.spot.ols.config.YamlBasedLoadingService;
import uk.ac.ebi.spot.ols.config.YamlConfigParser;
import uk.ac.ebi.spot.ols.exception.ConfigParsingException;
import uk.ac.ebi.spot.ols.model.OntologyDocument;
import uk.ac.ebi.spot.ols.model.Status;
import uk.ac.ebi.spot.ols.service.OntologyRepositoryService;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;


@SpringBootApplication
@EnableAutoConfiguration
@Configuration
public class YamlLoader implements CommandLineRunner {

    private Logger log = LoggerFactory.getLogger(getClass());

    public Logger getLog() {
        return log;
    }

    @Autowired
    private OntologyRepositoryService ontologyRepositoryService;

    @Value("${ols.ontology.config:}")
    public String yamlPath = "";

    @Value("${ols.obofoundry.ontology.config:}")
    public String oboYamlPath = "";

    @Value("${ols.obofoundry.dontclassify:}")
    public String dontClassify = "";

    public Set<String> dontClassifySet = new HashSet<>();

    @Override
    public void run(String... args) throws Exception {

        if (!dontClassify.equals("")) {
            for (String dontClassifyName : dontClassify.split(",")) {
                dontClassifySet.add(dontClassifyName);
            }
        }

        Collection<String> configs = new HashSet<>();
        if (!yamlPath.equals("")) {
            for (String configPath : yamlPath.split(",")) {
                configs.add(configPath);
            }
        } else if (getClass().getClassLoader().getResource("ols-config.yaml") != null) {
            File olsYamlFile = new File(getClass().getClassLoader().getResource("ols-config.yaml").getPath());
            if (Files.exists(olsYamlFile.toPath())) {
                configs.add(olsYamlFile.getAbsolutePath());
            }
        }

        for (String path : configs) {
            YamlConfigParser yamlConfigParser = new YamlConfigParser(getResourceFromPath(path));
            updateDocument(yamlConfigParser);
        }

        if (!oboYamlPath.equals("")) {
            Resource resource = getResourceFromPath(oboYamlPath);
            YamlConfigParser yamlConfigParser = new YamlConfigParser(resource, true);
            updateDocument(yamlConfigParser);
        }
        else if (getClass().getClassLoader().getResource("obo-config.yaml") != null) {
            File oboYaml = new File(getClass().getClassLoader().getResource("obo-config.yaml").getPath());
            if (Files.exists(oboYaml.toPath())) {
                Resource resource = new FileSystemResource(oboYaml);
                YamlConfigParser yamlConfigParser = new YamlConfigParser(resource, true);
                updateDocument(yamlConfigParser);
            }
        }

    }

    private Resource getResourceFromPath (String path) throws MalformedURLException {
        if (path.startsWith("http") || path.startsWith("ftp")) {
            return new UrlResource(path);
        }
        else {
            return new FileSystemResource(path);
        }
    }<commit_msg>updating yaml loader to use spring's built in resource loader instead of trying to resolve path syntax manually<commit_after>package uk.ac.ebi.spot.ols; /**
 * Created by catherineleroy on 09/06/2015.
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.*;
import uk.ac.ebi.spot.ols.config.OntologyResourceConfig;
import uk.ac.ebi.spot.ols.config.YamlBasedLoadingService;
import uk.ac.ebi.spot.ols.config.YamlConfigParser;
import uk.ac.ebi.spot.ols.exception.ConfigParsingException;
import uk.ac.ebi.spot.ols.model.OntologyDocument;
import uk.ac.ebi.spot.ols.model.Status;
import uk.ac.ebi.spot.ols.service.OntologyRepositoryService;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;


@SpringBootApplication
@EnableAutoConfiguration
@Configuration
public class YamlLoader implements CommandLineRunner {

    private Logger log = LoggerFactory.getLogger(getClass());

    public Logger getLog() {
        return log;
    }

    @Autowired
    private OntologyRepositoryService ontologyRepositoryService;

    @Value("${ols.ontology.config:ols-config.yaml}")
    public String yamlPath;

    @Value("${ols.obofoundry.ontology.config:obo-config.yaml}")
    public String oboYamlPath;

    @Value("${ols.obofoundry.dontclassify:}")
    public String dontClassify;

    @Autowired
    ResourceLoader resourceLoader;

    public Set<String> dontClassifySet = new HashSet<>();

    @Override
    public void run(String... args) throws Exception {
        if (!dontClassify.equals("")) {
            for (String dontClassifyName : dontClassify.split(",")) {
                dontClassifySet.add(dontClassifyName);
            }
        }

        for (String configPath : yamlPath.split(",")) {
            getLog().info("Ontologies will be imported using config at '" + configPath + "'");
            Resource olsResource = resourceLoader.getResource(configPath);
            if (olsResource.exists()) {
                YamlConfigParser yamlConfigParser = new YamlConfigParser(olsResource);
                updateDocument(yamlConfigParser);
            }
            else {
                getLog().warn("Resource '" + olsResource + "' could not be found and will not be loaded");
            }
        }

        getLog().info("OBO Ontologies will be imported using config at '" + oboYamlPath + "'");
        Resource oboResource = resourceLoader.getResource(oboYamlPath);
        if (oboResource.exists()) {
            YamlConfigParser yamlConfigParser = new YamlConfigParser(oboResource, true);
            updateDocument(yamlConfigParser);
        }
        else {
            getLog().warn("Resource '" + oboResource + "' could not be found and will therefore not be loaded");
        }
    }

{'fraction_non_alphanumeric': 0.11137179133314933, 'fraction_numerical': 0.002760143527463428, 'mean_word_length': 3.3604091456077017, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5046682', 'n_tokens_mistral': 2047, 'n_tokens_neox': 2006, 'n_words': 384}