<commit_before>package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"strings"
	"time"

	"github.com/codeafix/orgnetsim/sim"
)

//OptionsFile is the format of the optional file to configure the parse and construction of a network
type OptionsFile struct {
	Network *sim.NetworkOptions `json:"network"`
	Parse   *sim.ParseOptions   `json:"parse"`
}

//Parse provides the functionality for the orgnetsim parse command utility
func Parse() {
	success, of, opt, seed := parseCommandLineOptions()
	if !success {
		return
	}

	infile := os.Args[2]
	data := readFileIntoArray(infile)

	suffix := infile[strings.LastIndex(infile, "."):len(infile)]
	of.Parse.Delimiter = ","
	if suffix == ".txt" {
		of.Parse.Delimiter = "\t"
	}

	rand.Seed(int64(seed))

	rm, err := of.Parse.ParseDelim(data)
	check(err)

	crm, err := of.Network.CloneModify(rm)
	check(err)

	n := crm.(*sim.Network)

	outfile := ""
	i := strings.LastIndex(infile, ".")
	if i > 0 {
		outfile = infile[:i] + opt + ".json"
	} else {
		outfile = infile + opt + ".json"
	}

	fo, err := os.Create(outfile)
	check(err)
	defer fo.Close()
	json := n.Serialise()
	_, err = fo.Write([]byte(json))
	check(err)
}

func parseCommandLineOptions() (success bool, of OptionsFile, opt string, seed int64) {
	of = OptionsFile{}
	of.Parse.Delimiter = ","
	of.Parse.Identifier = 0
	of.Parse.Parent = 1
	success = true
	//list of options used to change the output filename
	opt = ""

	if len(os.Args) <= 2 || os.Args[2] == "-help" {
		parsePrintUsage()
		return false, of, opt, seed
	}

	//List of unrecognised command switches
	uc := []string{}

	skipnext := false
	for i, arg := range os.Args[3:len(os.Args)] {<commit_msg>Bug fix: orgnetsim parse panics with nil pointer<commit_after>package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"strings"
	"time"

	"github.com/codeafix/orgnetsim/sim"
)

//OptionsFile is the format of the optional file to configure the parse and construction of a network
type OptionsFile struct {
	Network *sim.NetworkOptions `json:"network"`
	Parse   *sim.ParseOptions   `json:"parse"`
}

//Parse provides the functionality for the orgnetsim parse command utility
func Parse() {
	success, of, opt, seed := parseCommandLineOptions()
	if !success {
		return
	}

	infile := os.Args[2]
	data := readFileIntoArray(infile)

	suffix := infile[strings.LastIndex(infile, "."):len(infile)]
	of.Parse.Delimiter = ","
	if suffix == ".txt" {
		of.Parse.Delimiter = "\t"
	}

	rand.Seed(int64(seed))

	rm, err := of.Parse.ParseDelim(data)
	check(err)

	crm, err := of.Network.CloneModify(rm)
	check(err)

	n := crm.(*sim.Network)

	outfile := ""
	i := strings.LastIndex(infile, ".")
	if i > 0 {
		outfile = infile[:i] + opt + ".json"
	} else {
		outfile = infile + opt + ".json"
	}

	fo, err := os.Create(outfile)
	check(err)
	defer fo.Close()
	json := n.Serialise()
	_, err = fo.Write([]byte(json))
	check(err)
}

func newOptionsFile() (of OptionsFile) {
	of = OptionsFile{}
	of.Parse = &sim.ParseOptions{}
	of.Parse.Delimiter = ","
	of.Parse.Identifier = 0
	of.Parse.Parent = 1
	of.Network = &sim.NetworkOptions{}
	return of
}

func parseCommandLineOptions() (success bool, of OptionsFile, opt string, seed int64) {
	of = newOptionsFile()

	success = true
	//list of options used to change the output filename
	opt = ""

	if len(os.Args) <= 2 || os.Args[2] == "-help" {
		parsePrintUsage()
		return false, of, opt, seed
	}

	//List of unrecognised command switches
	uc := []string{}

	skipnext := false
	for i, arg := range os.Args[3:len(os.Args)] {
{'fraction_non_alphanumeric': 0.1557422969187675, 'fraction_numerical': 0.0061624649859943975, 'mean_word_length': 3.832205683355886, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1503018', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1309, 'n_words': 343}