<commit_before>package latis.dm

import latis.data.Data
import latis.data.value.DoubleValue
import java.nio.Buffer
import latis.metadata.Metadata

/**
 * Binary blob.
 */
trait Binary extends Scalar {
  
  def length: Int = {
    getMetadata.get("length") match {
      case Some(l) => l.toInt
      case None => throw new Error("Must declare length of Binary Variable.")
    }
  }
  
}

object Binary {
  
//TODO: set length if not already set (see Text)
  
  def apply(buffer: Buffer) = new AbstractScalar(data = Data(buffer)) with Binary
  
  def apply(md: Metadata): Binary = new AbstractScalar(md) with Binary
  
  def apply(md: Metadata, buffer: Buffer): Binary = new AbstractScalar(md, Data(buffer)) with Binary
  
//  def apply(v: Any) = v match {
//    case d: Double => new Variable2(data = Data(Data(d).getByteBuffer)) with Binary
//  }
  
  def unapply(b: Binary): Option[Array[Byte]] = Some(b.getData.getByteBuffer.array)
}<commit_msg>add length property to Binary variable<commit_after>package latis.dm

import latis.data.Data
import latis.data.value.DoubleValue
import java.nio.Buffer
import latis.metadata.Metadata

/**
 * Binary blob.
 */
trait Binary extends Scalar {
  
  def length: Int = {
    getMetadata.get("length") match {
      case Some(l) => l.toInt
      case None => throw new Error("Must declare length of Binary Variable.")
    }
  }
  
}

object Binary {
  
//TODO: set length if not already set (see Text)
  
  def apply(buffer: Buffer) = {
    val size = buffer.limit
    val md = Metadata(Map("length" -> size.toString))
    new AbstractScalar(md, Data(buffer)) with Binary
  }
  
  def apply(md: Metadata): Binary = new AbstractScalar(md) with Binary
  
  def apply(md: Metadata, buffer: Buffer): Binary = {
    //add length if not already defined
    val md2 = md.get("length") match {
      case Some(_) => md
      case None => Metadata(md.getProperties ++ Map("length" -> buffer.limit.toString))
    }
    new AbstractScalar(md2, Data(buffer)) with Binary
  }
  
//  def apply(v: Any) = v match {
//    case d: Double => new Variable2(data = Data(Data(d).getByteBuffer)) with Binary
//  }
  
  def unapply(b: Binary): Option[Array[Byte]] = Some(b.getData.getByteBuffer.array)
}
{'fraction_non_alphanumeric': 0.12573231185218567, 'fraction_numerical': 0.0018026137899954935, 'mean_word_length': 3.2857142857142856, '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': '1671357', 'n_tokens_mistral': 731, 'n_tokens_neox': 706, 'n_words': 210}