<commit_before>require File.dirname(__FILE__) + "/shake_grammar/lexer"
require File.dirname(__FILE__) + "/shake_grammar/catcher"
class Tracksperanto::Import::ShakeScript < Tracksperanto::Import::Base
  
  def self.human_name
    "Shake .shk script file"
  end
  
  def self.distinct_file_ext
    ".shk"
  end
  
  # Extractor. The injection should be an array of two elements: the array collecting
  # trackers and the progress proc
  class Traxtractor < Tracksperanto::ShakeGrammar::Catcher
    include Tracksperanto::ZipTuples
    
    # Normally, we wouldn't need to look for the variable name from inside of the funcall. However,
    # in this case we DO want to take this shortcut so we know how the tracker node is called
    def push(atom)
      return super unless (atom.is_a?(Array)) && 
           (atom[0] == :assign) &&
           (atom[2][0] == :retval) &&
           (atom[2][1][0] == :trk)
      node_name = atom[1][-1]
      trackers = atom[2][1][1..-1]
      trackers.map do | tracker |
       tracker.name = [node_name, tracker.name].join("_")
       sentinel[0].push(tracker)
      end
    end
    
    # For Linear() curve calls. If someone selected JSpline or Hermite it's his problem.
    # We put the frame number at the beginning since it works witih oru tuple zipper
    def linear(first_arg, *keyframes)
      report_progress("Translating Linear animation")
      keyframes.map { |kf| [kf.at, kf.value] }
    end
    alias_method :nspline, :linear
    alias_method :jspline, :linear
    
    # Hermite interpolation looks like this
    # Hermite(0,[1379.04,-0.02,-0.02]@1,[1379.04,-0.03,-0.03]@2)
    # The first value in the array is the keyframe value, the other two are
    # tangent positions (which we discard)
    def hermite(initial_value, *keyframes)
      report_progress("Translating Hermite curve, removing tangents")
      keyframes.map{ |kf| [kf.at, kf.value[0]] }
    end
    
    # image Tracker( 
    #   image In,
    #   const char * trackRange,
    #   const char * subPixelRes,
    #   const char * matchSpace,
    #   float referenceTolerance,
    #   const char * referenceBehavior,
    #   float failureTolerance,
    #   const char * failureBehavior,
    #   int limitProcessing,
    #   float referencFrame 
    #   ...
    #  );  
    def tracker(input, trackRange, subPixelRes, matchSpace,
        referenceTolerance, referenceBehavior, failureTolerance, failureBehavior, limitProcessing, referencFrame, s1, s2,
        s3, s4, s5, s6, *trackers)
      
      report_progress("Parsing Tracker node")
      collect_trackers_from(trackers).unshift(:trk)<commit_msg>This is Shake's extrapolation type<commit_after>require File.dirname(__FILE__) + "/shake_grammar/lexer"
require File.dirname(__FILE__) + "/shake_grammar/catcher"
class Tracksperanto::Import::ShakeScript < Tracksperanto::Import::Base
  
  def self.human_name
    "Shake .shk script file"
  end
  
  def self.distinct_file_ext
    ".shk"
  end
  
  # Extractor. The injection should be an array of two elements: the array collecting
  # trackers and the progress proc
  class Traxtractor < Tracksperanto::ShakeGrammar::Catcher
    include Tracksperanto::ZipTuples
    
    # Normally, we wouldn't need to look for the variable name from inside of the funcall. However,
    # in this case we DO want to take this shortcut so we know how the tracker node is called
    def push(atom)
      return super unless (atom.is_a?(Array)) && 
           (atom[0] == :assign) &&
           (atom[2][0] == :retval) &&
           (atom[2][1][0] == :trk)
      node_name = atom[1][-1]
      trackers = atom[2][1][1..-1]
      trackers.map do | tracker |
       tracker.name = [node_name, tracker.name].join("_")
       sentinel[0].push(tracker)
      end
    end
    
    # For Linear() curve calls. If someone selected JSpline or Hermite it's his problem.
    # We put the frame number at the beginning since it works witih oru tuple zipper
    def linear(extrapolation_type, *keyframes)
      report_progress("Translating Linear animation")
      keyframes.map { |kf| [kf.at, kf.value] }
    end
    alias_method :nspline, :linear
    alias_method :jspline, :linear
    
    # Hermite interpolation looks like this
    # Hermite(0,[1379.04,-0.02,-0.02]@1,[1379.04,-0.03,-0.03]@2)
    # The first value in the array is the keyframe value, the other two are
    # tangent positions (which we discard)
    def hermite(extrapolation_type, *keyframes)
      report_progress("Translating Hermite curve, removing tangents")
      keyframes.map{ |kf| [kf.at, kf.value[0]] }
    end
    
    # image Tracker( 
    #   image In,
    #   const char * trackRange,
    #   const char * subPixelRes,
    #   const char * matchSpace,
    #   float referenceTolerance,
    #   const char * referenceBehavior,
    #   float failureTolerance,
    #   const char * failureBehavior,
    #   int limitProcessing,
    #   float referencFrame 
    #   ...
    #  );  
    def tracker(input, trackRange, subPixelRes, matchSpace,
        referenceTolerance, referenceBehavior, failureTolerance, failureBehavior, limitProcessing, referencFrame, s1, s2,
        s3, s4, s5, s6, *trackers)
      
      report_progress("Parsing Tracker node")
      collect_trackers_from(trackers).unshift(:trk)
{'fraction_non_alphanumeric': 0.10423390924625024, 'fraction_numerical': 0.017846971710651225, 'mean_word_length': 2.946067415730337, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6929074', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1670, 'n_words': 473}