<commit_before>package percolation

import (
	"os"
	"fmt"
)

const EnvironmentValidateError = "Environment input parameters are invalid"

// Physical parameters
type Environment struct {
	Beta  float64 // inverse thermal energy 1 / (k_B * T)
	Delta float64 // energy cost of exciting an atom
	V     float64 // energy gained from exciting a dimer
	// hopping energies:
	t_alpha      float64 // dimer direction, a_1g orbital
	t_beta_dimer float64 // dimer direction, e_pi orbital
	t_beta_diag  float64 // diagonal direction, e_pi orbital
}

// Build an Environment from the JSON file at filePath.
func EnvironmentFromFile(filePath string) (*Environment, os.Error) {
	env := new(Environment)
	err := CopyFromFile(filePath, env)
	if err != nil {
		return nil, err
	}
	if !env.validate() {
		return nil, fmt.Errorf(EnvironmentValidateError)
	}
	return env, nil
}

// Build an Environment from the given JSON string.
func EnvironmentFromString(jsonData string) (*Environment, os.Error) {
	env := new(Environment)
	err := CopyFromString(jsonData, env)
	if err != nil {
		return nil, err
	}
	if !env.validate() {
		return nil, fmt.Errorf(EnvironmentValidateError)
	}
	return env, nil
}

// Do the fields of env have acceptable values?
func (env *Environment) validate() bool {
	return env.Delta > 0 && env.V > 0 && env.Beta > 0
}
<commit_msg>unified building code for Environment<commit_after>package percolation

import (
	"os"
	"fmt"
)

const EnvironmentValidateError = "Environment input parameters are invalid"

// Physical parameters
type Environment struct {
	Beta  float64 // inverse thermal energy 1 / (k_B * T)
	Delta float64 // energy cost of exciting an atom
	V     float64 // energy gained from exciting a dimer
	// hopping energies:
	t_alpha      float64 // dimer direction, a_1g orbital
	t_beta_dimer float64 // dimer direction, e_pi orbital
	t_beta_diag  float64 // diagonal direction, e_pi orbital
}

// Build an Environment from the JSON file at filePath.
func EnvironmentFromFile(filePath string) (*Environment, os.Error) {
	return buildEnvironment(func(env *Environment) os.Error {
		return CopyFromFile(filePath, env)
	})
}

// Build an Environment from the given JSON string.
func EnvironmentFromString(jsonData string) (*Environment, os.Error) {
	return buildEnvironment(func(env *Environment) os.Error {
		return CopyFromString(jsonData, env)
	})
}

// Build an environment using the given copy function.
func buildEnvironment(copier func(*Environment) os.Error) (*Environment, os.Error) {
	env := new(Environment)
	err := copier(env)
	if err != nil {
		return nil, err
	}
	if !env.validate() {
		return nil, fmt.Errorf(EnvironmentValidateError)
	}
	return env, nil
}

// Do the fields of env have acceptable values?
func (env *Environment) validate() bool {
	return env.Delta > 0 && env.V > 0 && env.Beta > 0
}

{'fraction_non_alphanumeric': 0.09762999646268129, 'fraction_numerical': 0.012026883622214362, 'mean_word_length': 4.05, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4396234', 'n_tokens_mistral': 889, 'n_tokens_neox': 845, 'n_words': 304}