<commit_before>package cz.voho.wiki.parser;

import com.vladsch.flexmark.ast.Link;
import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.ast.NodeVisitor;
import com.vladsch.flexmark.ast.VisitHandler;
import com.vladsch.flexmark.util.sequence.PrefixedSubSequence;
import cz.voho.common.utility.WikiLinkUtility;
import cz.voho.wiki.model.ParsedWikiPage;

public class WikiLinkPreprocessor implements Preprocessor {
    @Override
    public void preprocessNodes(ParsedWikiPage context, Node root) {
        NodeVisitor visitor = new NodeVisitor(new VisitHandler<>(Link.class, link -> {
            String linkUrl = link.getUrl().toString();

            if (linkUrl.startsWith("wiki/")) {
                String targetId = WikiLinkUtility.stripWikiPrefixSuffix(WikiLinkUtility.stripSlashes(linkUrl));
                link.setUrl(PrefixedSubSequence.of("/wiki/" + targetId + "/"));
                context.addLinkTo(targetId);
            }
        }));
<commit_msg>cosmetics<commit_after>package cz.voho.wiki.parser;

import com.vladsch.flexmark.ast.Link;
import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.ast.NodeVisitor;
import com.vladsch.flexmark.ast.VisitHandler;
import com.vladsch.flexmark.util.sequence.PrefixedSubSequence;
import cz.voho.common.utility.WikiLinkUtility;
import cz.voho.wiki.model.ParsedWikiPage;

public class WikiLinkPreprocessor implements Preprocessor {
    @Override
    public void preprocessNodes(final ParsedWikiPage context, final Node root) {
        final NodeVisitor visitor = new NodeVisitor(new VisitHandler<>(Link.class, link -> {
            final String linkUrl = link.getUrl().toString();

            if (linkUrl.startsWith("wiki/")) {
                final String targetId = WikiLinkUtility.stripWikiPrefixSuffix(WikiLinkUtility.stripSlashes(linkUrl));
                link.setUrl(PrefixedSubSequence.of("/wiki/" + targetId + "/"));
                context.addLinkTo(targetId);
            }
        }));

{'fraction_non_alphanumeric': 0.11043566362715299, 'fraction_numerical': 0.0, 'mean_word_length': 3.529816513761468, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2653863', 'n_tokens_mistral': 602, 'n_tokens_neox': 594, 'n_words': 95}