<commit_before>package gu

import java.util.Base64
import models.{UserId, TopicType, Topic}

package object msnotifications {

  private def encode(string: String): String =
    Base64.getUrlEncoder.encodeToString(string.getBytes("UTF-8"))

  private def decode(string: String): String =
    new String(Base64.getUrlDecoder.decode(string), "UTF-8")

  case class WNSTopic(uri: String)

  object WNSTopic {
    def fromUri(uri: String): Option[Topic] = {
      val regex = s"""topic:(.*):(.*)""".r
      PartialFunction.condOpt(uri) {
        case regex(tpe, name) if TopicType.fromString(decode(tpe)).isDefined =>
          Topic(`type` = TopicType.fromString(decode(tpe)).get, name = decode(name))
      }
    }

    def fromTopic(t: Topic): WNSTopic = {
      WNSTopic(s"topic:${encode(t.`type`.toString)}:${encode(t.name)}")
    }

    def fromUserId(u: UserId): WNSTopic = {
      WNSTopic(s"user:${u.userId}")
    }
  }

  case class Tags(tags: Set[String] = Set.empty) {
    import Tags._

    def asSet = tags

    def findUserId: Option[UserId] = tags
      .find(_.startsWith(UserTagPrefix))
      .map { s => UserId(s.split(':')(1)) }

    def addUserId(userId: UserId) = copy(tags + s"${UserTagPrefix}${userId.userId}")

    def addTopics(topics: Set[Topic]) = copy(tags ++ topics.map(_.name))
  }

  object Tags {
    val UserTagPrefix = "user:"
  }
}<commit_msg>Tags builder methods renamed.<commit_after>package gu

import java.util.Base64
import models.{UserId, TopicType, Topic}

package object msnotifications {

  private def encode(string: String): String =
    Base64.getUrlEncoder.encodeToString(string.getBytes("UTF-8"))

  private def decode(string: String): String =
    new String(Base64.getUrlDecoder.decode(string), "UTF-8")

  case class WNSTopic(uri: String)

  object WNSTopic {
    def fromUri(uri: String): Option[Topic] = {
      val regex = s"""topic:(.*):(.*)""".r
      PartialFunction.condOpt(uri) {
        case regex(tpe, name) if TopicType.fromString(decode(tpe)).isDefined =>
          Topic(`type` = TopicType.fromString(decode(tpe)).get, name = decode(name))
      }
    }

    def fromTopic(t: Topic): WNSTopic = {
      WNSTopic(s"topic:${encode(t.`type`.toString)}:${encode(t.name)}")
    }

    def fromUserId(u: UserId): WNSTopic = {
      WNSTopic(s"user:${u.userId}")
    }
  }

  case class Tags(tags: Set[String] = Set.empty) {
    import Tags._

    def asSet = tags

    def findUserId: Option[UserId] = tags
      .find(_.startsWith(UserTagPrefix))
      .map { s => UserId(s.split(':')(1)) }

    def withUserId(userId: UserId) = copy(tags + s"${UserTagPrefix}${userId.userId}")

    def withTopics(topics: Set[Topic]) = copy(tags ++ topics.map(_.name))
  }

  object Tags {
    val UserTagPrefix = "user:"
  }
}
{'fraction_non_alphanumeric': 0.16004335260115607, 'fraction_numerical': 0.006502890173410405, 'mean_word_length': 3.502439024390244, 'pattern_counts': {'":': 0, '<': 3, '<?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': '931918', 'n_tokens_mistral': 990, 'n_tokens_neox': 970, 'n_words': 185}