<commit_before>package com.czbix.v2ex.parser;

import com.czbix.v2ex.model.Avatar;
import com.czbix.v2ex.model.Comment;
import com.czbix.v2ex.model.Member;
import com.czbix.v2ex.model.Topic;
import com.czbix.v2ex.model.TopicWithComments;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TopicParser extends Parser {
    private static final Pattern PATTERN_NUMBERS = Pattern.compile("\\d+");

    public static TopicWithComments parseDoc(Document doc, Topic topic) {
        final Topic.Builder topicBuilder = topic.toBuilder();

        parseContent(topicBuilder, doc.select(".topic_content"));
        parseTopicInfo(topicBuilder, doc);
        List<Comment> comments = parseComments(doc.select("#Main > div:nth-child(4) tr"));

        return new TopicWithComments(topicBuilder.createTopic(), comments);
    }

    private static void parseTopicInfo(Topic.Builder topicBuilder, Document doc) {
        final Elements elements = doc.select("#Main > div:nth-child(4) > .cell:nth-child(1) > span");
        if (elements.size() == 0) {
            // empty reply
            return;
        }
        final String text = elements.get(0).ownText();
        final Matcher matcher = PATTERN_NUMBERS.matcher(text);
        Preconditions.checkState(matcher.find());

        topicBuilder.setReplyCount(Integer.parseInt(matcher.group()));
    }

    private static List<Comment> parseComments(Elements elements) {
        List<Comment> list = Lists.newArrayListWithCapacity(elements.size());

        for (Element ele : elements) {
            list.add(parseComment(ele));<commit_msg>set reply count when reply is empty<commit_after>package com.czbix.v2ex.parser;

import com.czbix.v2ex.model.Avatar;
import com.czbix.v2ex.model.Comment;
import com.czbix.v2ex.model.Member;
import com.czbix.v2ex.model.Topic;
import com.czbix.v2ex.model.TopicWithComments;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TopicParser extends Parser {
    private static final Pattern PATTERN_NUMBERS = Pattern.compile("\\d+");

    public static TopicWithComments parseDoc(Document doc, Topic topic) {
        final Topic.Builder topicBuilder = topic.toBuilder();

        parseContent(topicBuilder, doc.select(".topic_content"));
        parseTopicInfo(topicBuilder, doc);
        List<Comment> comments = parseComments(doc.select("#Main > div:nth-child(4) tr"));

        return new TopicWithComments(topicBuilder.createTopic(), comments);
    }

    private static void parseTopicInfo(Topic.Builder topicBuilder, Document doc) {
        final Elements elements = doc.select("#Main > div:nth-child(4) > .cell:nth-child(1) > span");
        if (elements.size() == 0) {
            // empty reply
            topicBuilder.setReplyCount(0);
            return;
        }
        final String text = elements.get(0).ownText();
        final Matcher matcher = PATTERN_NUMBERS.matcher(text);
        Preconditions.checkState(matcher.find());

        topicBuilder.setReplyCount(Integer.parseInt(matcher.group()));
    }

    private static List<Comment> parseComments(Elements elements) {
        List<Comment> list = Lists.newArrayListWithCapacity(elements.size());

        for (Element ele : elements) {
            list.add(parseComment(ele));
{'fraction_non_alphanumeric': 0.11907983761840325, 'fraction_numerical': 0.0062246278755074425, 'mean_word_length': 3.6373902132998746, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '3015783', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1093, 'n_words': 218}