<commit_before>package viscel.scribe.database

import org.neo4j.graphdb.Node
import viscel.scribe.database.Implicits.NodeOps
import viscel.scribe.narration.{Asset, Blob, Page}

final case class Book(self: Node) extends AnyVal {

	def id(implicit ntx: Ntx): String = self.prop[String]("id")
	def name(implicit ntx: Ntx): String = self.get[String]("name").getOrElse(id)
	def name_=(value: String)(implicit neo: Ntx) = self.setProperty("name", value)
	def size(implicit ntx: Ntx): Int = {
		val sopt = self.get[Int]("size")
		sopt.getOrElse {
			val size = calcSize()
			self.setProperty("size", size)
			size
		}
	}

	private def calcSize()(implicit ntx: Ntx): Int =
		self.fold(0)(s => {
			case n if n.hasLabel(label.Asset) => s + 1
			case _ => s
		})

	def pages()(implicit ntx: Ntx): List[Page] =
		self.fold(List[Page]())(s => n => {
			if (!n.hasLabel(label.Asset)) s.reverse
			else {
				val asset = Codec.load[Asset](n)
				val blob = Option(n.to(rel.blob)).map(Codec.load[Blob])
				Page(asset, blob) :: s
			}
		})

}
<commit_msg>do not randomly reverse pages<commit_after>package viscel.scribe.database

import org.neo4j.graphdb.Node
import viscel.scribe.database.Implicits.NodeOps
import viscel.scribe.narration.{Asset, Blob, Page}

final case class Book(self: Node) extends AnyVal {

	def id(implicit ntx: Ntx): String = self.prop[String]("id")
	def name(implicit ntx: Ntx): String = self.get[String]("name").getOrElse(id)
	def name_=(value: String)(implicit neo: Ntx) = self.setProperty("name", value)
	def size(implicit ntx: Ntx): Int = {
		val sopt = self.get[Int]("size")
		sopt.getOrElse {
			val size = calcSize()
			self.setProperty("size", size)
			size
		}
	}

	private def calcSize()(implicit ntx: Ntx): Int =
		self.fold(0)(s => {
			case n if n.hasLabel(label.Asset) => s + 1
			case _ => s
		})

	def pages()(implicit ntx: Ntx): List[Page] =
		self.fold(List[Page]())(s => n => {
			if (!n.hasLabel(label.Asset)) s
			else {
				val asset = Codec.load[Asset](n)
				val blob = Option(n.to(rel.blob)).map(Codec.load[Blob])
				Page(asset, blob) :: s
			}
		})

}

{'fraction_non_alphanumeric': 0.1671455938697318, 'fraction_numerical': 0.0028735632183908046, 'mean_word_length': 3.92688679245283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3219233', 'n_tokens_mistral': 871, 'n_tokens_neox': 792, 'n_words': 176}