Exemplo n.º 1
0
func Load(ts graph.TripleStore, cfg *config.Config, dec quad.Unmarshaler) error {
	bulker, canBulk := ts.(graph.BulkLoader)
	if canBulk {
		switch err := bulker.BulkLoad(dec); err {
		case nil:
			return nil
		case graph.ErrCannotBulkLoad:
			// Try individual loading.
		default:
			return err
		}
	}

	block := make([]quad.Quad, 0, cfg.LoadSize)
	for {
		t, err := dec.Unmarshal()
		if err != nil {
			if err == io.EOF {
				break
			}
			return err
		}
		block = append(block, t)
		if len(block) == cap(block) {
			ts.AddTripleSet(block)
			block = block[:0]
		}
	}
	ts.AddTripleSet(block)

	return nil
}
Exemplo n.º 2
0
Arquivo: load.go Projeto: ZSIT/cayley
func LoadTriplesInto(tChan chan *graph.Triple, ts graph.TripleStore, loadSize int) {
	tripleblock := make([]*graph.Triple, loadSize)
	i := 0
	for t := range tChan {
		tripleblock[i] = t
		i++
		if i == loadSize {
			ts.AddTripleSet(tripleblock)
			i = 0
		}
	}
	ts.AddTripleSet(tripleblock[0:i])
}
Exemplo n.º 3
0
func LoadTriplesFromFileInto(ts graph.TripleStore, filename string, loadSize int) {
	tChan := make(chan *graph.Triple)
	go ReadTriplesFromFile(tChan, filename)
	tripleblock := make([]*graph.Triple, loadSize)
	i := 0
	for t := range tChan {
		tripleblock[i] = t
		i++
		if i == loadSize {
			ts.AddTripleSet(tripleblock)
			i = 0
		}
	}
	ts.AddTripleSet(tripleblock[0:i])
}
Exemplo n.º 4
0
func Load(ts graph.TripleStore, cfg *config.Config, path string) error {
	f, err := os.Open(path)
	if err != nil {
		return fmt.Errorf("could not open file %q: %v", path, err)
	}
	defer f.Close()

	r, err := decompressor(f)
	if err != nil {
		glog.Fatalln(err)
	}

	dec := cquads.NewDecoder(r)

	bulker, canBulk := ts.(graph.BulkLoader)
	if canBulk {
		err = bulker.BulkLoad(dec)
		if err == nil {
			return nil
		}
		if err == graph.ErrCannotBulkLoad {
			err = nil
		}
	}
	if err != nil {
		return err
	}

	block := make([]*quad.Quad, 0, cfg.LoadSize)
	for {
		t, err := dec.Unmarshal()
		if err != nil {
			if err == io.EOF {
				break
			}
			return err
		}
		block = append(block, t)
		if len(block) == cap(block) {
			ts.AddTripleSet(block)
			block = block[:0]
		}
	}
	ts.AddTripleSet(block)

	return nil
}