コード例 #1
0
ファイル: data_access.go プロジェクト: google/badwolf
// addTriples add all the retrieved triples from the graphs into the results
// table. The semantic graph clause is also passed to be able to identify what
// bindings to set.
func addTriples(ts <-chan *triple.Triple, cls *semantic.GraphClause, tbl *table.Table) error {
	for t := range ts {
		if cls.PID != "" {
			// The triples need to be filtered.
			if string(t.Predicate().ID()) != cls.PID {
				continue
			}
			if cls.PTemporal {
				if t.Predicate().Type() != predicate.Temporal {
					continue
				}
				ta, err := t.Predicate().TimeAnchor()
				if err != nil {
					return fmt.Errorf("failed to retrieve time anchor from time predicate in triple %s with error %v", t, err)
				}
				// Need to check teh bounds of the triple.
				if cls.PLowerBound != nil && cls.PLowerBound.After(*ta) {
					continue
				}
				if cls.PUpperBound != nil && cls.PUpperBound.Before(*ta) {
					continue
				}
			}
		}
		if cls.OID != "" {
			if p, err := t.Object().Predicate(); err == nil {
				// The triples need to be filtered.
				if string(p.ID()) != cls.OID {
					continue
				}
				if cls.OTemporal {
					if p.Type() != predicate.Temporal {
						continue
					}
					ta, err := p.TimeAnchor()
					if err != nil {
						return fmt.Errorf("failed to retrieve time anchor from time predicate in triple %s with error %v", t, err)
					}
					// Need to check teh bounds of the triple.
					if cls.OLowerBound != nil && cls.OLowerBound.After(*ta) {
						continue
					}
					if cls.OUpperBound != nil && cls.OUpperBound.Before(*ta) {
						continue
					}
				}
			}
		}
		r, err := tripleToRow(t, cls)
		if err != nil {
			return err
		}
		if r != nil {
			tbl.AddRow(r)
		}
	}
	return nil
}
コード例 #2
0
ファイル: data_access.go プロジェクト: rossdakin/badwolf
// addTriples add all the retrieved triples from the graphs into the results
// table. The semantic graph clause is also passed to be able to identify what
// bindings to set.
func addTriples(ts storage.Triples, cls *semantic.GraphClause, tbl *table.Table) error {
	for t := range ts {
		r, err := tripleToRow(t, cls)
		if err != nil {
			return err
		}
		tbl.AddRow(r)
	}
	return nil
}