<commit_before>package main

import (
  "fmt"
  "strings"
  "github.com/Jeffail/gabs"
)

func (p Person) not_my_json(trait_name string) {
  current_json := p.Json

  path := create_path("person.traits", trait_name)
  if current_json.ExistsP(path) {
    fmt.Println("we here")
  } else {
    fmt.Println("Nothing to delete")
    return
  }

  err := current_json.DeleteP(path)
  if err == nil {
    fmt.Println("It has been done.")
  }

  path_elements := strings.Split(path, ".")

  path = strings.Join(path_elements[:len(path_elements) - 1], ".")

  // path = create_path("person.traits", trait_name)
  my_data := current_json.Path(path)
  fmt.Println(my_data.String())

  children, err := my_data.Children()
  check_err(err)

  for _, child := range children {
    kiddos, err := child.Children()
    check_err(err)
    fmt.Println(child)
    for _, kiddo := range kiddos {
      kidling, err := kiddo.Children()
      check_err(err)
      fmt.Println(kidling)



      // jsonObj := gabs.New()
      // jsonObj.Set("10", "foo")
      // sub_ob := jsonObj.Path("foo").Data()
      //
      // fmt.Println(jsonObj.String())

      // TODO: test our ability to for loop the below
      val, err := current_json.Path(path).Index(0).Index(0).SetIndex("dude", 0)
      check_err(err)
      fmt.Println(val)
      //current_json.SetP("hello", path)
    }
  }
  fmt.Println(path)
  fmt.Println(current_json)


  // fmt.Println(children)

}

func (p Person) true_delete(trait_name string) {
  current_json := p.Json

  path := create_path("person.traits", trait_name)
  if current_json.ExistsP(path) {
    fmt.Println("we here")
  } else {
    fmt.Println("Nothing to delete")
    return
  }

  err := current_json.DeleteP(path)
  if err == nil {
    fmt.Println("It has been done.")
  }

  path_elements := strings.Split(path, ".")

  path = strings.Join(path_elements[:len(path_elements) - 1], ".")
  element_to_delete := path_elements[len(path_elements) - 1]
  fmt.Println("To Delete:", element_to_delete)

  my_data := current_json.Path(path)

  element_depth := obtain_array_count(my_data.String())

  children, err := my_data.Children()
  check_err(err)
  for i := 0; i < element_depth - 1; i++ {
    for _, child := range children {
      children, err = child.Children()
      check_err(err)
    }
  }

  jsonObj := gabs.New()
  jsonObj.Array("foo", "array")

  for _, child := range children {
    potential_target := child.String()
    target_split := strings.Split(potential_target, ":")
    if clean_text(target_split[0]) == element_to_delete {

    } else {
      jsonObj.ArrayAppend(child.Data(), "foo", "array")
    }
  }

  new_arr := jsonObj.Path("foo.array")
  fmt.Println(new_arr)

  _, err = current_json.Path(path).Index(0).Index(0).SetIndex(new_arr, 0)
  check_err(err)

  // fmt.Println(my_data)
}

// This may have some bad consequences down the line, warrents further investigation
func (p Person) clean_json() Person {
  current_json_text := p.Json.String()
  if current_json_text == "{}" { return p }<commit_msg>Should now allow for changing arrays at arbitrary depths.<commit_after>package main

import (
  "fmt"
  "strings"
  "github.com/Jeffail/gabs"
)

func (p Person) not_my_json(trait_name string) {
  current_json := p.Json

  path := create_path("person.traits", trait_name)
  if current_json.ExistsP(path) {
    fmt.Println("we here")
  } else {
    fmt.Println("Nothing to delete")
    return
  }

  err := current_json.DeleteP(path)
  if err == nil {
    fmt.Println("It has been done.")
  }

  path_elements := strings.Split(path, ".")

  path = strings.Join(path_elements[:len(path_elements) - 1], ".")

  // path = create_path("person.traits", trait_name)
  my_data := current_json.Path(path)
  fmt.Println(my_data.String())

  children, err := my_data.Children()
  check_err(err)

  for _, child := range children {
    kiddos, err := child.Children()
    check_err(err)
    fmt.Println(child)
    for _, kiddo := range kiddos {
      kidling, err := kiddo.Children()
      check_err(err)
      fmt.Println(kidling)



      // jsonObj := gabs.New()
      // jsonObj.Set("10", "foo")
      // sub_ob := jsonObj.Path("foo").Data()
      //
      // fmt.Println(jsonObj.String())

      // TODO: test our ability to for loop the below
      val, err := current_json.Path(path).Index(0).Index(0).SetIndex("dude", 0)
      check_err(err)
      fmt.Println(val)
      //current_json.SetP("hello", path)
    }
  }
  fmt.Println(path)
  fmt.Println(current_json)


  // fmt.Println(children)

}

func (p Person) true_delete(trait_name string) {
  current_json := p.Json

  path := create_path("person.traits", trait_name)
  if current_json.ExistsP(path) {
    fmt.Println("we here")
  } else {
    fmt.Println("Nothing to delete")
    return
  }

  err := current_json.DeleteP(path)
  if err == nil {
    fmt.Println("It has been done.")
  }

  path_elements := strings.Split(path, ".")

  path = strings.Join(path_elements[:len(path_elements) - 1], ".")
  element_to_delete := path_elements[len(path_elements) - 1]
  fmt.Println("To Delete:", element_to_delete)

  my_data := current_json.Path(path)

  element_depth := obtain_array_count(my_data.String())

  children, err := my_data.Children()
  check_err(err)
  for i := 0; i < element_depth - 1; i++ {
    for _, child := range children {
      children, err = child.Children()
      check_err(err)
    }
  }

  jsonObj := gabs.New()
  jsonObj.Array("foo", "array")

  for _, child := range children {
    potential_target := child.String()
    target_split := strings.Split(potential_target, ":")
    if clean_text(target_split[0]) == element_to_delete {

    } else {
      jsonObj.ArrayAppend(child.Data(), "foo", "array")
    }
  }

  new_arr := jsonObj.Path("foo.array")
  fmt.Println(new_arr)

  current_val := current_json.Path(path)
  check_err(err)
  for i := 0; i < element_depth - 1; i++ {
    current_val = current_val.Index(0)
  }
  _, err = current_val.SetIndex(new_arr, 0)
  check_err(err)

  // fmt.Println(my_data)
}

// This may have some bad consequences down the line, warrents further investigation
func (p Person) clean_json() Person {
  current_json_text := p.Json.String()
  if current_json_text == "{}" { return p }
{'fraction_non_alphanumeric': 0.15215295629820053, 'fraction_numerical': 0.004659383033419023, 'mean_word_length': 3.243353783231084, 'pattern_counts': {'":': 2, '<': 6, '<?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': '7351190', 'n_tokens_mistral': 2249, 'n_tokens_neox': 2171, 'n_words': 432}