<commit_before>module CourseEditorModule
  export tagCourse,unTagCourse,changeCourseAttribute

  using CourseModule

  # Tags a course
  function tagCourse(course::Course,tag::ASCIIString)
    (course.attributes)["tags"] = string((course.attributes)["tags"],",",tag)
  end

  # Untags course
  function unTagCourse(course::Course,tag::ASCIIString)
    tagMatch = match(Regex(tag),(course.attributes)["tags"])
    if tagMatch == nothing # if there's no match
      return false
    end
    if tagMatch.offset + length(tag) == length((course.attributes)["tags"]) # if it's the last tag
      (course.attributes)["tags"] = ((course.attributes)["tags"])[1:tagMatch.offset]
    else
      (course.attributes)["tags"] = string(((course.attributes)["tags"])[1:tagMatch.offset-1],((course.attributes)["tags"])[tagMatch.offset+length(tag)+1:end])   # otherwhise we'll cut the tag from the rest without forgetting the comma
    end
    return true
  end

  # Change name
  function changeCourseAttribute(course::Course,attribute,newValue)
     (course.attributes)[attribute] = newValue
  end

end
<commit_msg>Added saveCourse function<commit_after>module CourseEditorModule
  export tagCourse,unTagCourse,changeCourseAttribute

  using CourseModule

# Saving to database

  # Creating a new course
  function saveCourse(course::Course)
    return SapphireORM.insert(conn,Dict("table" => "courses",
                                        "values" => Dict("name" => "'$(course.name)'",
                                                         "logo" => "'$(course.logo)'",
                                                         "category" => "'$(course.category)'",
                                                         "tags" => "'$(course.tags)'",
                                                         "level" => "'$(course.level)'",
                                                         "introduction" => "'$(course.introduction)'",
                                                         "conclusion" => "'$(course.conclusion)'")))
  end

  # Updating an existing course
  function updateCourse(course::Course)
  end

#Changing attributes

  # Tags a course
  function tagCourse(course::Course,tag::ASCIIString)
    (course.attributes)["tags"] = string((course.attributes)["tags"],",",tag)
  end

  # Untags course
  function unTagCourse(course::Course,tag::ASCIIString)
    tagMatch = match(Regex(tag),(course.attributes)["tags"])
    if tagMatch == nothing # if there's no match
      return false
    end
    if tagMatch.offset + length(tag) == length((course.attributes)["tags"]) # if it's the last tag
      (course.attributes)["tags"] = ((course.attributes)["tags"])[1:tagMatch.offset]
    else
      (course.attributes)["tags"] = string(((course.attributes)["tags"])[1:tagMatch.offset-1],((course.attributes)["tags"])[tagMatch.offset+length(tag)+1:end])   # otherwhise we'll cut the tag from the rest without forgetting the comma
    end
    return true
  end

  # Change name
  function changeCourseAttribute(course::Course,attribute,newValue)
     (course.attributes)[attribute] = newValue
  end

end

{'fraction_non_alphanumeric': 0.13836276083467094, 'fraction_numerical': 0.002568218298555377, 'mean_word_length': 2.7815533980582523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1182994', 'n_tokens_mistral': 861, 'n_tokens_neox': 811, 'n_words': 175}