<commit_before>package linkedql

import (
	"context"

	"github.com/cayleygraph/cayley/graph"
	"github.com/cayleygraph/cayley/graph/iterator"
	"github.com/cayleygraph/cayley/query"
	"github.com/cayleygraph/cayley/query/path"
	"github.com/cayleygraph/quad"
)

var _ query.Iterator = (*DocumentIterator)(nil)

type document = map[string]interface{}

// DocumentIterator is an iterator of documents from the graph
type DocumentIterator struct {
	qs         graph.QuadStore
	path       *path.Path
	ids        []quad.Value
	scanner    iterator.Scanner
	properties map[quad.Value]map[string][]quad.Value
	current    int
}

// NewDocumentIterator returns a new DocumentIterator for a QuadStore and Path.
func NewDocumentIterator(qs graph.QuadStore, p *path.Path) *DocumentIterator {
	return &DocumentIterator{qs: qs, path: p, current: -1}
}

// Next implements query.Iterator.
func (it *DocumentIterator) Next(ctx context.Context) bool {
	if it.properties == nil {
		it.properties = make(map[quad.Value]map[string][]quad.Value)
		it.scanner = it.path.BuildIterator(ctx).Iterate()
		for it.scanner.Next(ctx) {
			id := it.qs.NameOf(it.scanner.Result())
			it.ids = append(it.ids, id)

			tags := make(map[string]graph.Ref)
			it.scanner.TagResults(tags)

			for k, ref := range tags {
				value := it.qs.NameOf(ref)
				m, ok := it.properties[id]
				if !ok {
					m = make(map[string][]quad.Value)
					it.properties[id] = m
				}
				m[k] = append(m[k], value)
			}
		}
	}<commit_msg>linkedql: minimize the accepted interface for DocumentIterator<commit_after>package linkedql

import (
	"context"

	"github.com/cayleygraph/cayley/graph/iterator"
	"github.com/cayleygraph/cayley/graph/refs"
	"github.com/cayleygraph/cayley/query"
	"github.com/cayleygraph/cayley/query/path"
	"github.com/cayleygraph/quad"
)

var _ query.Iterator = (*DocumentIterator)(nil)

type document = map[string]interface{}

// DocumentIterator is an iterator of documents from the graph
type DocumentIterator struct {
	qs         refs.Namer
	path       *path.Path
	ids        []quad.Value
	scanner    iterator.Scanner
	properties map[quad.Value]map[string][]quad.Value
	current    int
}

// NewDocumentIterator returns a new DocumentIterator for a QuadStore and Path.
func NewDocumentIterator(qs refs.Namer, p *path.Path) *DocumentIterator {
	return &DocumentIterator{qs: qs, path: p, current: -1}
}

// Next implements query.Iterator.
func (it *DocumentIterator) Next(ctx context.Context) bool {
	if it.properties == nil {
		it.properties = make(map[quad.Value]map[string][]quad.Value)
		it.scanner = it.path.BuildIterator(ctx).Iterate()
		for it.scanner.Next(ctx) {
			id := it.qs.NameOf(it.scanner.Result())
			it.ids = append(it.ids, id)

			tags := make(map[string]refs.Ref)
			it.scanner.TagResults(tags)

			for k, ref := range tags {
				value := it.qs.NameOf(ref)
				m, ok := it.properties[id]
				if !ok {
					m = make(map[string][]quad.Value)
					it.properties[id] = m
				}
				m[k] = append(m[k], value)
			}
		}
	}
{'fraction_non_alphanumeric': 0.13413413413413414, 'fraction_numerical': 0.000667334000667334, 'mean_word_length': 3.7587301587301587, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7191959', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1047, 'n_words': 220}