<commit_before>package epic.parser

import epic.parser.projections.GrammarRefinements
import epic.trees.{BinaryRule, UnaryRule}

/**
 * TODO
 *
 * @author dlwh
 **/
trait ProjectionsRefinedAnchoring[L, L2, W] extends RefinedAnchoring[L, W] {
  def refinements: GrammarRefinements[L, L2]
  def refinedGrammar: BaseGrammar[L2]


  final def validLabelRefinements(begin: Int, end: Int, label: Int) = {
    refinements.labels.localRefinements(label)
  }

  final def validRuleRefinementsGivenParent(begin: Int, end: Int, rule: Int, parentRef: Int) = {
    refinements.ruleRefinementsCompatibleWithParentRef(rule, parentRef)
  }

  final def validRuleRefinementsGivenLeftChild(begin: Int, split: Int, completionBegin: Int, completionEnd: Int, rule: Int, childRef: Int): Array[Int] = {
    refinements.ruleRefinementsCompatibleWithLeftRef(rule, childRef)
  }

  final def validRuleRefinementsGivenRightChild(completionBegin: Int, completionEnd: Int, split: Int, end: Int, rule: Int, childRef: Int): Array[Int] = {
    refinements.ruleRefinementsCompatibleWithRightRef(rule, childRef)
  }

  final def validUnaryRuleRefinementsGivenChild(begin: Int, end: Int, rule: Int, childRef: Int) = {
    refinements.ruleRefinementsCompatibleWithChildRef(rule, childRef)
  }

  final def leftChildRefinement(rule: Int, ruleRef: Int) = {
    val refinedRuleId = refinements.rules.globalize(rule, ruleRef)
    refinements.labels.localize(refinedGrammar.leftChild(refinedRuleId))
  }

  final def rightChildRefinement(rule: Int, ruleRef: Int) = {
    val refinedRuleId = refinements.rules.globalize(rule, ruleRef)
    refinements.labels.localize(refinedGrammar.rightChild(refinedRuleId))
  }

  final def parentRefinement(rule: Int, ruleRef: Int) = {
    val refinedRuleId = refinements.rules.globalize(rule, ruleRef)
    refinements.labels.localize(refinedGrammar.parent(refinedRuleId))
  }

  final def childRefinement(rule: Int, ruleRef: Int) = {
    val refinedRuleId = refinements.rules.globalize(rule, ruleRef)
    refinements.labels.localize(refinedGrammar.child(refinedRuleId))
  }

  // TODO: make this not terminally slow!
  final def ruleRefinementFromRefinements(r: Int, refA: Int, refB: Int) = {
    val a = grammar.parent(r)<commit_msg>actually use the new parent refinement stuff.<commit_after>package epic.parser

import epic.parser.projections.GrammarRefinements
import epic.trees.{BinaryRule, UnaryRule}

/**
 * TODO
 *
 * @author dlwh
 **/
trait ProjectionsRefinedAnchoring[L, L2, W] extends RefinedAnchoring[L, W] {
  def refinements: GrammarRefinements[L, L2]
  def refinedGrammar: BaseGrammar[L2]


  final def validLabelRefinements(begin: Int, end: Int, label: Int) = {
    refinements.labels.localRefinements(label)
  }

  final def validRuleRefinementsGivenParent(begin: Int, end: Int, rule: Int, parentRef: Int) = {
    refinements.ruleRefinementsCompatibleWithParentRef(rule, parentRef)
  }

  final def validRuleRefinementsGivenLeftChild(begin: Int, split: Int, completionBegin: Int, completionEnd: Int, rule: Int, childRef: Int): Array[Int] = {
    refinements.ruleRefinementsCompatibleWithLeftRef(rule, childRef)
  }

  final def validRuleRefinementsGivenRightChild(completionBegin: Int, completionEnd: Int, split: Int, end: Int, rule: Int, childRef: Int): Array[Int] = {
    refinements.ruleRefinementsCompatibleWithRightRef(rule, childRef)
  }

  final def validUnaryRuleRefinementsGivenChild(begin: Int, end: Int, rule: Int, childRef: Int) = {
    refinements.ruleRefinementsCompatibleWithChildRef(rule, childRef)
  }

  final def leftChildRefinement(rule: Int, ruleRef: Int) = {
    val refinedRuleId = refinements.rules.globalize(rule, ruleRef)
    refinements.labels.localize(refinedGrammar.leftChild(refinedRuleId))
  }

  final def rightChildRefinement(rule: Int, ruleRef: Int) = {
    val refinedRuleId = refinements.rules.globalize(rule, ruleRef)
    refinements.labels.localize(refinedGrammar.rightChild(refinedRuleId))
  }

  final def parentRefinement(rule: Int, ruleRef: Int) = {
    refinements.parentRefinement(rule, ruleRef)
  }

  final def childRefinement(rule: Int, ruleRef: Int) = {
    val refinedRuleId = refinements.rules.globalize(rule, ruleRef)
    refinements.labels.localize(refinedGrammar.child(refinedRuleId))
  }

  // TODO: make this not terminally slow!
  final def ruleRefinementFromRefinements(r: Int, refA: Int, refB: Int) = {
    val a = grammar.parent(r)
{'fraction_non_alphanumeric': 0.10270393092478983, 'fraction_numerical': 0.0013633265167007499, 'mean_word_length': 5.398255813953488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1216441', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1446, 'n_words': 306}