<commit_before>package com.kodcu.service.convert;

import com.kodcu.other.Current;
import com.kodcu.other.IOHelper;
import com.kodcu.service.MarkdownService;
import org.joox.Match;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.xml.sax.InputSource;

import java.io.StringReader;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.joox.JOOX.$;

/**
 * Created by usta on 19.07.2014.
 */
@Component
public class DocBookService {

    private static final Logger logger = LoggerFactory.getLogger(DocBookService.class);

    private Pattern ascIncludeRegex = Pattern.compile("(?<=include::)(?<path>.*?)(?=\\[(.*?)\\])");
    private Pattern mdIncludeRegex = Pattern.compile("\\[.*?\\]\\((?<path>.*?)\\)");

    @Autowired
    private RenderService docConverter;

    @Autowired
    private Current current;
    @Autowired
    private MarkdownService markdownService;

    public void generateDocbook(Consumer<String> step) {

        StringBuilder builder = new StringBuilder();

            Path currentTabPath = current.currentPath().get();
            Path currentTabPathDir = currentTabPath.getParent();
            String tabText = current.getCurrentTabText().replace("*", "").trim();

            List<String> bookAscLines = Arrays.asList(current.currentEditorValue().split("\\r?\\n"));
            for (int i = 0; i < bookAscLines.size(); i++) {
                String bookAscLine = bookAscLines.get(i);

                Matcher matcher = ascIncludeRegex.matcher(bookAscLine);

                if (matcher.find()) {
                    String chapterPath = matcher.group("path");
                    String chapterContent = IOHelper.readFile(currentTabPathDir.resolve(chapterPath));
                    bookAscLines.set(i, "\n\n" + chapterContent + "\n\n");
                }

                if(tabText.contains("SUMMARY")){
                    matcher = mdIncludeRegex.matcher(bookAscLine);

                    if (matcher.find()) {
                        String chapterPath = matcher.group("path");
                        String chapterContent = IOHelper.readFile(currentTabPathDir.resolve(chapterPath));
                        bookAscLines.set(i, "\n\n" + chapterContent + "\n\n");
                    }<commit_msg>Constructor injection and cleanup in DocBookService<commit_after>package com.kodcu.service.convert;

import com.kodcu.other.Current;
import com.kodcu.other.IOHelper;
import org.joox.Match;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.xml.sax.InputSource;

import java.io.StringReader;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.joox.JOOX.$;

/**
 * Created by usta on 19.07.2014.
 */
@Component
public class DocBookService {

    private final Pattern ascIncludeRegex = Pattern.compile("(?<=include::)(?<path>.*?)(?=\\[(.*?)\\])");
    private final Pattern mdIncludeRegex = Pattern.compile("\\[.*?\\]\\((?<path>.*?)\\)");

    private final RenderService docConverter;
    private final Current current;

    @Autowired
    public DocBookService(final RenderService docConverter, final Current current) {
        this.docConverter = docConverter;
        this.current = current;
    }

    public void generateDocbook(Consumer<String> step) {

        StringBuilder builder = new StringBuilder();

            Path currentTabPath = current.currentPath().get();
            Path currentTabPathDir = currentTabPath.getParent();
            String tabText = current.getCurrentTabText().replace("*", "").trim();

            List<String> bookAscLines = Arrays.asList(current.currentEditorValue().split("\\r?\\n"));
            for (int i = 0; i < bookAscLines.size(); i++) {
                String bookAscLine = bookAscLines.get(i);

                Matcher matcher = ascIncludeRegex.matcher(bookAscLine);

                if (matcher.find()) {
                    String chapterPath = matcher.group("path");
                    String chapterContent = IOHelper.readFile(currentTabPathDir.resolve(chapterPath));
                    bookAscLines.set(i, "\n\n" + chapterContent + "\n\n");
                }

                if(tabText.contains("SUMMARY")){
                    matcher = mdIncludeRegex.matcher(bookAscLine);

                    if (matcher.find()) {
                        String chapterPath = matcher.group("path");
                        String chapterContent = IOHelper.readFile(currentTabPathDir.resolve(chapterPath));
                        bookAscLines.set(i, "\n\n" + chapterContent + "\n\n");
                    }
{'fraction_non_alphanumeric': 0.13123993558776167, 'fraction_numerical': 0.004025764895330112, 'mean_word_length': 2.678016284233901, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1887728', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1365, 'n_words': 269}