<commit_before>package ldp

import (
	"fmt"
	"ldpserver/textstore"
	"log"
)

func CreateRoot(settings Settings) {
	if textstore.Exists(settings.dataPath) {
		// nothing to do
		return
	}

	store := textstore.CreateStore(settings.dataPath)
	if store.Error() != nil {
		errorMsg := fmt.Sprintf("Could not create root store: %s", store.Error())
		panic(errorMsg)
	}

	if err := store.SaveFile("meta.rdf.id", "0"); err != nil {
		errorMsg := fmt.Sprintf("Could not create root ID file: %s", err.Error())
		panic(errorMsg)
	}

	graph := DefaultGraph(settings.rootUri)
	content := graph.String()
	if err := store.SaveFile("meta.rdf", content); err != nil {
		errorMsg := fmt.Sprintf("Could not create root file at %s.", err.Error())
		panic(errorMsg)
	}

	log.Printf("Root node created on disk at : %s\n", settings.dataPath)
}<commit_msg>Create root node via the node class<commit_after>package ldp

import (
	"fmt"
	"ldpserver/textstore"
	"log"
)

func CreateRoot(settings Settings) {
	_, err := GetHead(settings, "/")
	if err == nil {
		return
	}

	if err != NodeNotFoundError {
		panic(fmt.Sprintf("Error reading root node: %s", err.Error()))
	}

	_, err = NewRdfNode(settings, "", "/")
	if err != nil {
		panic(fmt.Sprintf("Could not create root node: %s", err.Error()))
	}

	log.Printf("Root node created on disk at : %s\n", settings.dataPath)
	createRootIdFile(settings.dataPath)
}

func createRootIdFile(path string) {
	// TODO: This code should not depend on the textstore
	store := textstore.NewStore(path)
	if err := store.SaveFile("meta.rdf.id", "0"); err != nil {
		panic(fmt.Sprintf("Could not create root ID file: %s", err.Error()))
	}
}
{'fraction_non_alphanumeric': 0.15927051671732523, 'fraction_numerical': 0.0012158054711246201, 'mean_word_length': 4.192429022082019, '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': '2297098', 'n_tokens_mistral': 587, 'n_tokens_neox': 568, 'n_words': 152}