<commit_before>package epic.parser
/*
 Copyright 2012 <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.
*/

import java.util.Arrays
import epic.parser.projections.{ChartProjector, AnchoredPCFGProjector, AnchoredRuleMarginalProjector}
import epic.trees._
import breeze.collection.mutable.TriangularArray
import breeze.util._
import breeze.numerics._
import epic.lexicon.Lexicon
import breeze.numerics
import com.typesafe.scalalogging.slf4j.Logging
import epic.util.SafeLogging

trait ParserException extends Exception
case class ParseExtractionException(msg: String, sentence: IndexedSeq[Any]) extends RuntimeException with ParserException
case class NoParseException(msg: String, sentence: IndexedSeq[Any], cause: Throwable = null) extends RuntimeException(s"No parse for $sentence: $msg") with ParserException

/**
 * A ChartDecoder converts marginals into a binarized tree. Post-processing
 * to debinarize and strip useless annotations is still necessary.
 *
 * @author dlwh
 */
trait ChartDecoder[L, W] extends Serializable{
  def extractBestParse(marginal: ChartMarginal[L, W]):BinarizedTree[L]
  def wantsMaxMarginal: Boolean = false
}

object ChartDecoder {
  def apply[L,W]():ChartDecoder[L, W] = {
    new MaxRuleProductDecoder()
  }
}

/**
 * Tries to extract a tree that maximizes log score.
 *<commit_msg>pass the message into the exception hierarchy<commit_after>package epic.parser
/*
 Copyright 2012 <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.
*/

import java.util.Arrays
import epic.parser.projections.{ChartProjector, AnchoredPCFGProjector, AnchoredRuleMarginalProjector}
import epic.trees._
import breeze.collection.mutable.TriangularArray
import breeze.util._
import breeze.numerics._
import epic.lexicon.Lexicon
import breeze.numerics
import com.typesafe.scalalogging.slf4j.Logging
import epic.util.SafeLogging

trait ParserException extends Exception
case class ParseExtractionException(msg: String, sentence: IndexedSeq[Any]) extends RuntimeException(msg) with ParserException
case class NoParseException(msg: String, sentence: IndexedSeq[Any], cause: Throwable = null) extends RuntimeException(s"No parse for $sentence: $msg") with ParserException

/**
 * A ChartDecoder converts marginals into a binarized tree. Post-processing
 * to debinarize and strip useless annotations is still necessary.
 *
 * @author dlwh
 */
trait ChartDecoder[L, W] extends Serializable{
  def extractBestParse(marginal: ChartMarginal[L, W]):BinarizedTree[L]
  def wantsMaxMarginal: Boolean = false
}

object ChartDecoder {
  def apply[L,W]():ChartDecoder[L, W] = {
    new MaxRuleProductDecoder()
  }
}

/**
 * Tries to extract a tree that maximizes log score.
 *
{'fraction_non_alphanumeric': 0.07466373867691463, 'fraction_numerical': 0.004940982706560527, 'mean_word_length': 5.315424610051993, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4730858', 'n_tokens_mistral': 1016, 'n_tokens_neox': 983, 'n_words': 376}