<commit_before>// Copyright 2012-2018, <NAME> and contributors.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package ogdl

import (
	"errors"
	"fmt"
	"math"
	"reflect"
	"regexp"
	"strconv"
)

// Find returns a Graph with all subnodes that match the regular
// expression given. It only walks through the subnodes of the current Graph.
// If the regex doesn't compile, an error will be returned. If the result set
// is empty, both return values are nil (no error is signaled).
func (g *Graph) Find(re string) (*Graph, error) {
	exp, err := regexp.Compile(re)

	if err != nil {
		return nil, err
	}

	r := New("_")

	for _, node := range g.Out {
		if exp.MatchString(node.ThisString()) {
			r.Add(node)
		}
	}

	return r, nil
}

// Int64 returns the node as an int64. If the node is not a number, it
// returns 0, or the default value if given.
func (g *Graph) Int64(def ...int64) int64 {
	n, ok := _int64f(g.String())
	if !ok {
		if len(def) == 0 {
			return 0
		}
		return def[0]
	}
	return n
}

// Float64 returns the node as a float64. If the node is not a number, it
// return NaN, or the default value if given.
func (g *Graph) Float64(def ...float64) float64 {
	n, ok := _float64f(g.String())
	if !ok {
		if len(def) == 0 {
			return math.NaN()
		}
		return def[0]
	}
	return n
}

// Bool returns the node as a boolean. If the node is not a
// boolean, it returns false, or the default value if given.
func (g *Graph) Bool() bool {
	n, ok := _boolf(g.String())
	if !ok {
		return false
	}
	return n
}

// ThisValue returns this node as a reflect.Value.
func (g *Graph) ThisValue() reflect.Value {
	return reflect.ValueOf(g.This)
}

// Value returns the node as a reflect.Value.<commit_msg>Add default parameter option to Bool()<commit_after>// Copyright 2012-2018, <NAME> and contributors.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package ogdl

import (
	"errors"
	"fmt"
	"math"
	"reflect"
	"regexp"
	"strconv"
)

// Find returns a Graph with all subnodes that match the regular
// expression given. It only walks through the subnodes of the current Graph.
// If the regex doesn't compile, an error will be returned. If the result set
// is empty, both return values are nil (no error is signaled).
func (g *Graph) Find(re string) (*Graph, error) {
	exp, err := regexp.Compile(re)

	if err != nil {
		return nil, err
	}

	r := New("_")

	for _, node := range g.Out {
		if exp.MatchString(node.ThisString()) {
			r.Add(node)
		}
	}

	return r, nil
}

// Int64 returns the node as an int64. If the node is not a number, it
// returns 0, or the default value if given.
func (g *Graph) Int64(def ...int64) int64 {
	n, ok := _int64f(g.String())
	if !ok {
		if len(def) == 0 {
			return 0
		}
		return def[0]
	}
	return n
}

// Float64 returns the node as a float64. If the node is not a number, it
// return NaN, or the default value if given.
func (g *Graph) Float64(def ...float64) float64 {
	n, ok := _float64f(g.String())
	if !ok {
		if len(def) == 0 {
			return math.NaN()
		}
		return def[0]
	}
	return n
}

// Bool returns the node as a boolean. If the node is not a
// boolean, it returns false, or the default value if given.
func (g *Graph) Bool(def ...bool) bool {
	n, ok := _boolf(g.String())
	if !ok {
		if len(def) == 0 {
			return false
		}
		return def[0]
	}
	return n
}

// ThisValue returns this node as a reflect.Value.
func (g *Graph) ThisValue() reflect.Value {
	return reflect.ValueOf(g.This)
}

// Value returns the node as a reflect.Value.
{'fraction_non_alphanumeric': 0.12402452619843925, 'fraction_numerical': 0.021739130434782608, 'mean_word_length': 2.983351831298557, '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': '6361520', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1237, 'n_words': 518}