<commit_before>package org.globalnames.resolver.model

import java.util.UUID

import slick.driver.PostgresDriver.api._
import slick.lifted.ProvenShape

case class Name(id: UUID, value: String)
case class NameString(name: Name, canonicalName: Option[Name])

class NameStrings(tag: Tag) extends Table[NameString](tag, "name_strings") {
  def id: Rep[UUID] = column[UUID]("id", O.PrimaryKey)

  def name: Rep[String] = column[String]("name")

  def canonicalUuid: Rep[Option[UUID]] = column[Option[UUID]]("canonical_uuid")

  def canonical: Rep[Option[String]] = column[Option[String]]("canonical")

  def * : ProvenShape[NameString] = ((id, name), (canonicalUuid, canonical)).shaped <> (
      { case (name, (canonicalNameUuid, canonicalNameValue)) =>
        val canonicalName = for (uuid <- canonicalNameUuid; value <- canonicalNameValue)
                            yield Name(uuid, value)
        NameString(Name.tupled.apply(name), canonicalName)
      },
      { ns: NameString =>
        Some(((ns.name.id, ns.name.value),
              (ns.canonicalName.map { _.id }, ns.canonicalName.map { _.value })))
      }
    )
}<commit_msg>= Add support of None canonicals to NameStrings<commit_after>package org.globalnames.resolver.model

import java.util.UUID

import slick.driver.PostgresDriver.api._
import slick.lifted.ProvenShape

case class Name(id: UUID, value: String)
case class NameString(name: Name, canonicalName: Option[Name])

class NameStrings(tag: Tag) extends Table[NameString](tag, "name_strings") {
  import NameStrings.emptyCanonicalUuid

  def id: Rep[UUID] = column[UUID]("id", O.PrimaryKey)

  def name: Rep[String] = column[String]("name")

  def canonicalUuid: Rep[Option[UUID]] = column[Option[UUID]]("canonical_uuid")

  def canonical: Rep[Option[String]] = column[Option[String]]("canonical")

  def * : ProvenShape[NameString] = ((id, name), (canonicalUuid, canonical)).shaped <> (
      { case (name, (canonicalNameUuid, canonicalNameValue)) =>
        val canonicalName =
          for {
            uuid <- canonicalNameUuid
            if uuid != emptyCanonicalUuid
            value <- canonicalNameValue
          } yield Name(uuid, value)
        NameString(Name.tupled.apply(name), canonicalName)
      },
      { ns: NameString =>
        Some(((ns.name.id, ns.name.value),
              (ns.canonicalName.map { _.id }, ns.canonicalName.map { _.value })))
      }
    )
}

object NameStrings {
  private[NameStrings] val emptyCanonicalUuid =
    UUID.fromString("a9456e61-bd30-53bc-8588-accb913cc64a")
}
{'fraction_non_alphanumeric': 0.1374015748031496, 'fraction_numerical': 0.007480314960629921, 'mean_word_length': 3.6968576709796674, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6962688', 'n_tokens_mistral': 815, 'n_tokens_neox': 786, 'n_words': 164}