<commit_before>package com.sedsoftware.yaptalker.data.remote.converters

import com.sedsoftware.yaptalker.commons.extensions.chopEdges
import com.sedsoftware.yaptalker.commons.extensions.getLastDigits
import com.sedsoftware.yaptalker.data.NewsItem
import com.sedsoftware.yaptalker.data.TopicItem
import com.sedsoftware.yaptalker.data.UserProfileShort
import okhttp3.ResponseBody
import org.jsoup.Jsoup
import retrofit2.Converter

class NewsResponseBodyConverter : Converter<ResponseBody, List<NewsItem>> {

  companion object {
    val NEWS_SELECTOR = "td.newshead"
    val NEWS_HEADER_SELECTOR = "div.rating-short-value > a"
    val NEWS_TITLE_SELECTOR = "a.subtitle"
    val LINK_BY_ATTRIBUTE_SELECTOR = "href"
    val CONTENT_SELECTOR = "td.news-content"
    val TOPIC_INFO_SELECTOR = "td.holder"
    val TOPIC_DATE_SELECTOR = "b.icon-date"
    val PROFILE_INFO_SELECTOR = "b > a"
    val COMMENTS_COUNT_SELECTOR = "span"
  }

  override fun convert(value: ResponseBody): List<NewsItem> {

    val html = value.string()

    val htmlDocument = Jsoup.parse(html)

    val news = htmlDocument.select(NEWS_SELECTOR)
    val content = htmlDocument.select(CONTENT_SELECTOR)
    val topics = htmlDocument.select(TOPIC_INFO_SELECTOR)

    val newsCount = news.size

    assert(newsCount == content.size)
    assert(newsCount == topics.size)

    val result = ArrayList<NewsItem>(newsCount)

    // Iterate through all elements and create NewsItem objects

    for (index in 0..newsCount - 1) {

      // Parse header block

      val newsItem = news[index]
      val title = newsItem.select(NEWS_TITLE_SELECTOR).first().text()
      val header = newsItem.select(NEWS_HEADER_SELECTOR).first()

      // Skip advertisement blocks (when header == null)
      val rating = header?.text() ?: continue

      val topicLink = header.attr(LINK_BY_ATTRIBUTE_SELECTOR)
      val topicId = topicLink.getLastDigits()

      // Parse content block
      val contentItem = content[index]
      val contentBody = contentItem.html()

      // Parse topic info block
      val topicInfo = topics[index]
      val topicDate = topicInfo.select(TOPIC_DATE_SELECTOR).first().text()
      val profileInfo = topicInfo.select(PROFILE_INFO_SELECTOR)
      val nickname = profileInfo[0].text()
      val profileLink = profileInfo[0].attr(LINK_BY_ATTRIBUTE_SELECTOR)
      val userId = profileLink.getLastDigits()
      val comments = topicInfo.select(COMMENTS_COUNT_SELECTOR).text()

      // Build NewsItem
      val userInfo = UserProfileShort(id = userId, name = nickname)

      val topicItem = TopicItem(
          id = topicId,
          title = title,
          answers = Integer.parseInt(comments.chopEdges()),
          uq = Integer.parseInt(rating),
          views = 0,
          author = userInfo,
          date = topicDate)

      val singleNewsItem = NewsItem(summary = contentBody, topic = topicItem)

      result.add(singleNewsItem)
    }

    return result
  }
}
<commit_msg>Replace parceInt with toInt<commit_after>package com.sedsoftware.yaptalker.data.remote.converters

import com.sedsoftware.yaptalker.commons.extensions.chopEdges
import com.sedsoftware.yaptalker.commons.extensions.getLastDigits
import com.sedsoftware.yaptalker.data.NewsItem
import com.sedsoftware.yaptalker.data.TopicItem
import com.sedsoftware.yaptalker.data.UserProfileShort
import okhttp3.ResponseBody
import org.jsoup.Jsoup
import retrofit2.Converter

class NewsResponseBodyConverter : Converter<ResponseBody, List<NewsItem>> {

  companion object {
    val NEWS_SELECTOR = "td.newshead"
    val NEWS_HEADER_SELECTOR = "div.rating-short-value > a"
    val NEWS_TITLE_SELECTOR = "a.subtitle"
    val LINK_BY_ATTRIBUTE_SELECTOR = "href"
    val CONTENT_SELECTOR = "td.news-content"
    val TOPIC_INFO_SELECTOR = "td.holder"
    val TOPIC_DATE_SELECTOR = "b.icon-date"
    val PROFILE_INFO_SELECTOR = "b > a"
    val COMMENTS_COUNT_SELECTOR = "span"
  }

  override fun convert(value: ResponseBody): List<NewsItem> {

    val html = value.string()

    val htmlDocument = Jsoup.parse(html)

    val news = htmlDocument.select(NEWS_SELECTOR)
    val content = htmlDocument.select(CONTENT_SELECTOR)
    val topics = htmlDocument.select(TOPIC_INFO_SELECTOR)

    val newsCount = news.size

    assert(newsCount == content.size)
    assert(newsCount == topics.size)

    val result = ArrayList<NewsItem>(newsCount)

    // Iterate through all elements and create NewsItem objects

    for (index in 0..newsCount - 1) {

      // Parse header block
      val newsItem = news[index]
      val title = newsItem.select(NEWS_TITLE_SELECTOR).first().text()
      val header = newsItem.select(NEWS_HEADER_SELECTOR).first()

      // Skip advertisement blocks (when header == null)
      val rating = header?.text() ?: continue

      val topicLink = header.attr(LINK_BY_ATTRIBUTE_SELECTOR)
      val topicId = topicLink.getLastDigits()

      // Parse content block
      val contentItem = content[index]
      val contentBody = contentItem.html()

      // Parse topic info block
      val topicInfo = topics[index]
      val topicDate = topicInfo.select(TOPIC_DATE_SELECTOR).first().text()
      val profileInfo = topicInfo.select(PROFILE_INFO_SELECTOR)
      val nickname = profileInfo[0].text()
      val profileLink = profileInfo[0].attr(LINK_BY_ATTRIBUTE_SELECTOR)
      val userId = profileLink.getLastDigits()
      val comments = topicInfo.select(COMMENTS_COUNT_SELECTOR).text()

      // Build NewsItem
      val userInfo = UserProfileShort(id = userId, name = nickname)

      val topicItem = TopicItem(
          id = topicId,
          title = title,
          answers = comments.chopEdges().toInt(),
          uq = rating.toInt(),
          author = userInfo,
          date = topicDate)

      val singleNewsItem = NewsItem(summary = contentBody, topic = topicItem)

      result.add(singleNewsItem)
    }

    return result
  }
}

{'fraction_non_alphanumeric': 0.09220338983050848, 'fraction_numerical': 0.0022033898305084745, 'mean_word_length': 3.3841010401188707, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '7594898', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1783, 'n_words': 385}