<commit_before><commit_msg>cleanup<commit_after>// Copyright 2012-2014, <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

// Check returns true if the Graph given as a parameter conforms to the
// schema represented by the receiver Graph.
func (schema *Graph) Check(g *Graph) (bool, string) {

	for i := 0; i < g.Len(); i++ {
		ns := schema.GetAt(i)
		nx := g.GetAt(i)

		b := ns.checkNode(nx)
		if !b {
			if ns != nil {
				return false, "want " + ns.String() + ", got " + nx.String()
			}
		}

		ok, mess := ns.Check(nx)
		if !ok {
			return false, mess
		}
	}

	return true, ""
}

func (schema *Graph) checkNode(g *Graph) bool {

	if schema == nil || g == nil {
		return false
	}

	sx := g.String()
	sc := schema.String()

	ty := g.Type()
	var ok bool

	// literal | literal* | literal? | literal+ | ** | ***
	if sc[0] != '!' {
		return sx == sc
	}

	// some type
	switch sc {

	case "!float":
		_, ok = _float64f(g.This)
		return ok

	case "!int":
		_, ok = _int64f(g.This)
		return ok

	case "!bool":
		_, ok = _boolf(g.This)
		return ok

	case "!string":
		return ty == "string"

	case "!binary":
		return ty == "[]byte"
	}

	return false
}
{'fraction_non_alphanumeric': 0.1635777598710717, 'fraction_numerical': 0.011281224818694601, 'mean_word_length': 2.72972972972973, 'pattern_counts': {'":': 5, '<': 5, '<?xml version=': 0, '>': 4, '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': '6378655', 'n_tokens_mistral': 512, 'n_tokens_neox': 458, 'n_words': 151}