<commit_before>class ActionNodeToSynonym < ActionCommand

  def precondition_do
    @destination_node = Node.find(destination_node_id) rescue nil
    !!(node && @destination_node && node.ancestry_ok? && @destination_node.ancestry_ok? && !node.has_children?)
  end

  def precondition_undo
    true
  end

  def do_action
    new_synonym_names = node.synonyms.map { |s| s.name }
    new_synonym_names = new_synonym_names - @destination_node.synonyms.map { |s| s.name }
    merged_node = Node.create!(:tree => master_tree, :parent => @destination_node.parent, :name => @destination_node.name)
    @destination_node.synonyms.each do |synonym|
      Synonym.create!(:node => merged_node, :name => synonym.name, :status => synonym.status)
    end

    new_synonyms.each do |name|
      Synonym.create!(:node => merged_node, :name => name, :status => nil)
    end
    new_json_message = JSON.parse(json_message, :symbolize_keys => true)
    new_json_message.merge({ :undo => { :node_id => merged_node.id } })
    #node.parent_id = 
  end

  def undo_action
  end

  def do_log
  end

  def undo_log
  end

end<commit_msg>WIP do_action for action_node_to_synonym<commit_after>class ActionNodeToSynonym < ActionCommand

  def precondition_do
    @destination_node = Node.find(destination_node_id) rescue nil
    !!(node && @destination_node && ancestry_ok?(node) && ancestry_ok?(@destination_node) && !node.has_children?)
  end

  def precondition_undo
    true
  end

  def do_action
    new_synonym_names = node.synonyms.map { |s| s.name }
    new_synonym_names = new_synonym_names - @destination_node.synonyms.map { |s| s.name }
    merged_node = Node.create!(:tree => master_tree, :parent => @destination_node.parent, :name => @destination_node.name)
    @destination_node.synonyms.each do |synonym|
      Synonym.create!(:node => merged_node, :name => synonym.name, :status => synonym.status)
    end
    new_synonym_names.each do |name|
      Synonym.create!(:node => merged_node, :name => name, :status => nil)
    end
    
    new_json_message = JSON.parse(json_message, :symbolize_keys => true)
    new_json_message.merge({ :undo => { :node_id => merged_node.id } })
    
    self.json_message = new_json_message
    save!
    
    @destination_node.delete_softly
  end

  def undo_action
    merged_node_id = JSON.parse(json_message, :symbolize_names => true)[:undo][:node_id]
    merged_node = Node.find(merged_node_id) rescue nil
    merged_node.destroy
    @destination_node.restore
  end

  def do_log
  end

  def undo_log
  end

end
{'fraction_non_alphanumeric': 0.11456692913385827, 'fraction_numerical': 0.0, 'mean_word_length': 3.9054054054054053, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '5919509', 'n_tokens_mistral': 886, 'n_tokens_neox': 861, 'n_words': 169}