<commit_before>package main

import (
	"github.com/crabmusket/gosunspec/smdx"
	"io/ioutil"
	"log"
	"os"
	"strings"
	"text/template"
)

const preamble = `// NOTICE
// This file was automatically generated by ../generators/core.go. Do not edit it!
// You can regenerate it by running 'go generate ./core' from the directory above.

package core
`

const model = `
type {{.Name}} struct {
}
`

func main() {
	outputFilename := "../core/models.go.tmp"
	outputFile, err := os.OpenFile(outputFilename, os.O_WRONLY|os.O_CREATE, 0644)
	if err != nil {
		log.Fatal(err)
	}
	defer outputFile.Close()

	smdxDir := "../models/smdx/"
	files, err := ioutil.ReadDir(smdxDir)
	if err != nil {
		log.Fatal(err)
	}

	_, err = outputFile.WriteString(preamble)
	if err != nil {
		log.Fatal(err)
	}

	modelTemplate := template.Must(template.New("model").Parse(model))

	for _, file := range files {
		if strings.HasPrefix(file.Name(), "smdx_") {
			smdxFile, err := os.OpenFile(smdxDir+file.Name(), os.O_RDONLY, 0644)
			if err != nil {
				log.Fatal(err)
			}

			def, err := smdx.FromXML(smdxFile)
			if err != nil {
				smdxFile.Close()
				log.Fatal(err)
			}

			if len(def.Models) < 1 {
				smdxFile.Close()
				continue
			}

			for _, model := range def.Models {
				modelId := "Model" + model.Id

				modelTemplate.Execute(outputFile, map[string]string{
					"Name": modelId,
				})
			}

			smdxFile.Close()
		}
	}
}
<commit_msg>Truncate file first, just in case new file is shorter.<commit_after>package main

import (
	"github.com/crabmusket/gosunspec/smdx"
	"io/ioutil"
	"log"
	"os"
	"strings"
	"text/template"
)

const preamble = `// NOTICE
// This file was automatically generated by ../generators/core.go. Do not edit it!
// You can regenerate it by running 'go generate ./core' from the directory above.

package core
`

const model = `
type {{.Name}} struct {
}
`

func main() {
	outputFilename := "../core/models.go.tmp"
	outputFile, err := os.OpenFile(outputFilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		log.Fatal(err)
	}
	defer outputFile.Close()

	smdxDir := "../models/smdx/"
	files, err := ioutil.ReadDir(smdxDir)
	if err != nil {
		log.Fatal(err)
	}

	_, err = outputFile.WriteString(preamble)
	if err != nil {
		log.Fatal(err)
	}

	modelTemplate := template.Must(template.New("model").Parse(model))

	for _, file := range files {
		if strings.HasPrefix(file.Name(), "smdx_") {
			smdxFile, err := os.OpenFile(smdxDir+file.Name(), os.O_RDONLY, 0644)
			if err != nil {
				log.Fatal(err)
			}

			def, err := smdx.FromXML(smdxFile)
			if err != nil {
				smdxFile.Close()
				log.Fatal(err)
			}

			if len(def.Models) < 1 {
				smdxFile.Close()
				continue
			}

			for _, model := range def.Models {
				modelId := "Model" + model.Id

				modelTemplate.Execute(outputFile, map[string]string{
					"Name": modelId,
				})
			}

			smdxFile.Close()
		}
	}
}

{'fraction_non_alphanumeric': 0.15650969529085873, 'fraction_numerical': 0.006232686980609419, 'mean_word_length': 3.1153846153846154, 'pattern_counts': {'":': 2, '<': 5, '<?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': '3696915', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1079, 'n_words': 241}