<commit_before>package scalanlp.parser

import scalanlp.serialization.{SerializationFormat, DataSerialization}
import java.io.DataOutput

/*
 Copyright 2010 <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/



sealed trait Rule[@specialized(Int) +L] {
  def parent: L;
  def children: Seq[L];
  def symbols = parent +: children
  def map[A](f: L=>A):Rule[A]
}

final case class BinaryRule[@specialized(Int) +L](parent: L, left: L, right: L) extends Rule[L] {
  def children = Seq(left,right);
  def map[A](f: L=>A) = BinaryRule(f(parent),f(left),f(right))
}
final case class UnaryRule[@specialized(Int) +L](parent: L, child: L) extends Rule[L] {
  def children = Seq(child);
  def map[A](f: L=>A) = UnaryRule(f(parent),f(child))
}


object Rule {
  implicit def ruleReadWritable[L:DataSerialization.ReadWritable] = new DataSerialization.ReadWritable[Rule[L]] {
    def write(sink: DataOutput, r: Rule[L]) = r match {
      case r@UnaryRule(_,_) =>
        sink.writeBoolean(false)
        DataSerialization.write(sink, r.parent)
        DataSerialization.write(sink, r.child)
      case r@BinaryRule(_,_,_) =>
        sink.writeBoolean(true)
        DataSerialization.write(sink, r.parent)
        DataSerialization.write(sink, r.left)
        DataSerialization.write(sink, r.right)
    }

    def read(source: DataSerialization.Input) = {
      if(source.readBoolean()) {
        val p = DataSerialization.read[L](source)
        val c = DataSerialization.read[L](source)
        UnaryRule(p,c)
      } else {
        val p = DataSerialization.read[L](source)<commit_msg>mapChildren for rule<commit_after>package scalanlp.parser

import scalanlp.serialization.{SerializationFormat, DataSerialization}
import java.io.DataOutput

/*
 Copyright 2010 <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/



sealed trait Rule[@specialized(Int) +L] {
  def parent: L;
  def children: Seq[L];
  def symbols = parent +: children
  def map[A](f: L=>A):Rule[A]
  def mapChildren[A>:L](f: L=>A):Rule[A]
}

final case class BinaryRule[@specialized(Int) +L](parent: L, left: L, right: L) extends Rule[L] {
  def children = Seq(left,right);
  def map[A](f: L=>A) = BinaryRule(f(parent),f(left),f(right))
  def mapChildren[A>:L](f: L=>A) = BinaryRule(parent,f(left),f(right))
}
final case class UnaryRule[@specialized(Int) +L](parent: L, child: L) extends Rule[L] {
  def children = Seq(child);
  def map[A](f: L=>A) = UnaryRule(f(parent),f(child))
  def mapChildren[A>:L](f: L=>A) = UnaryRule(parent,f(child))
}


object Rule {
  implicit def ruleReadWritable[L:DataSerialization.ReadWritable] = new DataSerialization.ReadWritable[Rule[L]] {
    def write(sink: DataOutput, r: Rule[L]) = r match {
      case r@UnaryRule(_,_) =>
        sink.writeBoolean(false)
        DataSerialization.write(sink, r.parent)
        DataSerialization.write(sink, r.child)
      case r@BinaryRule(_,_,_) =>
        sink.writeBoolean(true)
        DataSerialization.write(sink, r.parent)
        DataSerialization.write(sink, r.left)
        DataSerialization.write(sink, r.right)
    }

    def read(source: DataSerialization.Input) = {
      if(source.readBoolean()) {
        val p = DataSerialization.read[L](source)
        val c = DataSerialization.read[L](source)
        UnaryRule(p,c)
      } else {
        val p = DataSerialization.read[L](source)
{'fraction_non_alphanumeric': 0.12334494773519164, 'fraction_numerical': 0.003716608594657375, 'mean_word_length': 4.030373831775701, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7379691', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1361, 'n_words': 384}