<commit_before>package lila.common

import chess.Color
import chess.opening.{ FullOpening, FullOpeningDB, OpeningFamily, OpeningVariation }

case class LilaOpeningFamily(ref: OpeningFamily, full: FullOpening) {
  import LilaOpeningFamily._
  val name             = Name(ref.name)
  val key              = Key(LilaOpening nameToKey name.value)
  def as(color: Color) = LilaOpeningFamily.AsColor(this, color)
}

object LilaOpeningFamily {

  case class Key(value: String)  extends AnyVal with StringValue
  case class Name(value: String) extends AnyVal with StringValue
  case class AsColor(family: LilaOpeningFamily, color: Color)

  def apply(key: Key): Option[LilaOpeningFamily]   = families get key
  def find(key: String): Option[LilaOpeningFamily] = apply(Key(key))

  lazy val families: Map[Key, LilaOpeningFamily] = FullOpeningDB.all
    .foldLeft(Map.empty[Key, LilaOpeningFamily]) { case (acc, fullOp) =>
      val fam = LilaOpeningFamily(fullOp.family, fullOp)
      if (acc.contains(fam.key)) acc else acc.updated(fam.key, fam)
    }

  lazy val familyList = families.values.toList.sortBy(_.name.value)

  implicit val keyIso = Iso.string[Key](Key.apply, _.value)
}

case class LilaOpening(ref: FullOpening, name: LilaOpening.Name, family: LilaOpeningFamily) {
  import LilaOpening._
  val key       = Key(nameToKey(name.value))
  def variation = ref.variation | otherVariations
}
<commit_msg>fix opening families by selecting shortest opening move sequences<commit_after>package lila.common

import chess.Color
import chess.opening.{ FullOpening, FullOpeningDB, OpeningFamily, OpeningVariation }

case class LilaOpeningFamily(ref: OpeningFamily, full: FullOpening) {
  import LilaOpeningFamily._
  val name             = Name(ref.name)
  val key              = Key(LilaOpening nameToKey name.value)
  def as(color: Color) = LilaOpeningFamily.AsColor(this, color)
}

object LilaOpeningFamily {

  case class Key(value: String)  extends AnyVal with StringValue
  case class Name(value: String) extends AnyVal with StringValue
  case class AsColor(family: LilaOpeningFamily, color: Color)

  def apply(key: Key): Option[LilaOpeningFamily]   = families get key
  def find(key: String): Option[LilaOpeningFamily] = apply(Key(key))

  lazy val families: Map[Key, LilaOpeningFamily] = FullOpeningDB.all
    .foldLeft(Map.empty[Key, LilaOpeningFamily]) { case (acc, fullOp) =>
      val fam = LilaOpeningFamily(fullOp.family, fullOp)
      acc.get(fam.key) match {
        case Some(existing) if fullOp.uci.size < existing.full.uci.size =>
          acc.updated(fam.key, fam)
        case Some(_) => acc
        case None    => acc.updated(fam.key, fam)
      }
    }

  lazy val familyList = families.values.toList.sortBy(_.name.value)

  implicit val keyIso = Iso.string[Key](Key.apply, _.value)
}

case class LilaOpening(ref: FullOpening, name: LilaOpening.Name, family: LilaOpeningFamily) {
  import LilaOpening._
  val key       = Key(nameToKey(name.value))
  def variation = ref.variation | otherVariations
}

{'fraction_non_alphanumeric': 0.09973492379058979, 'fraction_numerical': 0.0, 'mean_word_length': 4.125636672325976, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '661253', 'n_tokens_mistral': 991, 'n_tokens_neox': 975, 'n_words': 246}