<commit_before>package com.dua3.meja.text;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.function.BiFunction;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.dua3.meja.model.Cell;
import com.dua3.meja.model.RefOption;
import com.dua3.meja.model.Workbook;
import com.dua3.meja.util.MejaHelper;
import com.dua3.utility.io.FileSystemView;

public class FormatTest {

    private Workbook workbook;

    @Before
    public void initialize() throws Exception {
        Class<? extends FormatTest> clazz = getClass();
        String fileName = clazz.getSimpleName()+".xlsx";

        // the FileSystemView is needed in case the test is run from a jar file
        try (FileSystemView fsv = FileSystemView.create(clazz)) {
            Path wbPath = fsv.resolve(fileName);
            workbook = MejaHelper.openWorkbook(wbPath);
        } catch (IOException e) {
            // WORKAROUND - If anyone knows a less hackish solution for this, please send a pull request!
            
            // When tests are run from within gradle, resources are placed in another location (outside of classpath).
            // In that case, we try to guess the correct location of the resource files to be able to perform the tests.
            System.err.println("Resource not found! "+e.getMessage());
            String pathStr = clazz.getResource(".").getPath();
            
            // When started from within Bash on windows, a slash is prepended to the path returned by getResource.
            // We have to remove it again. 
            if (pathStr.matches("^/[a-zA-Z]:/")) {
                pathStr = pathStr.replaceFirst("^/", "");
            }
            
            // Change the path so that it points to the probable resource dir.
            String s = pathStr.replaceAll("/build/classes/java/test/", "/build/resources/test/");
            
            // Then try to load the workbook from there.
            Path path = Paths.get(s);
            try (FileSystemView fsv = FileSystemView.create(path)) {
                Path wbPath = fsv.resolve(fileName);
                workbook = MejaHelper.openWorkbook(wbPath);<commit_msg>fix regex for path<commit_after>package com.dua3.meja.text;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.function.BiFunction;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.dua3.meja.model.Cell;
import com.dua3.meja.model.RefOption;
import com.dua3.meja.model.Workbook;
import com.dua3.meja.util.MejaHelper;
import com.dua3.utility.io.FileSystemView;

public class FormatTest {

    private Workbook workbook;

    @Before
    public void initialize() throws Exception {
        Class<? extends FormatTest> clazz = getClass();
        String fileName = clazz.getSimpleName()+".xlsx";

        // the FileSystemView is needed in case the test is run from a jar file
        try (FileSystemView fsv = FileSystemView.create(clazz)) {
            Path wbPath = fsv.resolve(fileName);
            workbook = MejaHelper.openWorkbook(wbPath);
        } catch (IOException e) {
            System.out.format("--- WORKAROUND --- caught IOException, trying to fix path%n");
            // WORKAROUND - If anyone knows a less hackish solution for this, please send a pull request!

            // When tests are run from within gradle, resources are placed in another location (outside of classpath).
            // In that case, we try to guess the correct location of the resource files to be able to perform the tests.
            System.err.println("Resource not found! "+e.getMessage());
            String pathStr = clazz.getResource(".").getPath();

            System.out.format("--- WORKAROUND --- current path is %s%n", pathStr);

            // When started from within Bash on windows, a slash is prepended to the path returned by getResource.
            // We have to remove it again.
            if (pathStr.matches("^/[a-zA-Z]:/.*")) {
                System.out.format("FIXING PATH%n");
                pathStr = pathStr.replaceFirst("^/", "");
                System.out.format("--- WORKAROUND --- fix windows bash path to %s%n", pathStr);
            }

            // Change the path so that it points to the probable resource dir.
            String s = pathStr.replaceAll("/build/classes/java/test/", "/build/resources/test/");
            System.out.format("--- WORKAROUND --- path to resources is now %s%n", pathStr);

            // Then try to load the workbook from there.
            Path path = Paths.get(s);
            try (FileSystemView fsv = FileSystemView.create(path)) {
                Path wbPath = fsv.resolve(fileName);
                workbook = MejaHelper.openWorkbook(wbPath);
{'fraction_non_alphanumeric': 0.10734577922077922, 'fraction_numerical': 0.002435064935064935, 'mean_word_length': 2.389958734525447, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2763539', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1369, 'n_words': 433}