コード例 #1
0
ファイル: table_test.go プロジェクト: msingle/badwolf
func TestCellString(t *testing.T) {
	now := time.Now()
	n := node.NewBlankNode()
	p, err := predicate.NewImmutable("foo")
	if err != nil {
		t.Fatalf("failed to create predicate with error %v", err)
	}
	l, err := literal.DefaultBuilder().Parse(`"true"^^type:bool`)
	if err != nil {
		t.Fatalf("failed to create literal with error %v", err)
	}
	testTable := []struct {
		c    *Cell
		want string
	}{
		{c: &Cell{S: "foo"}, want: `foo`},
		{c: &Cell{N: n}, want: n.String()},
		{c: &Cell{P: p}, want: p.String()},
		{c: &Cell{L: l}, want: l.String()},
		{c: &Cell{T: &now}, want: now.Format(time.RFC3339Nano)},
	}
	for _, entry := range testTable {
		if got := entry.c.String(); got != entry.want {
			t.Errorf("Cell.String failed to return the right string; got %q, want %q", got, entry.want)
		}
	}
}
コード例 #2
0
ファイル: triple.go プロジェクト: ranjeet-floyd/badwolf
// Reify given the current triple it returns the original triple and the newly
// reified ones. It also returns the newly created blank node.
func (t *Triple) Reify() ([]*Triple, *node.Node, error) {
	// Function that create the proper reification predicates.
	rp := func(id string, p *predicate.Predicate) (*predicate.Predicate, error) {
		if p.Type() == predicate.Temporal {
			ta, _ := p.TimeAnchor()
			return predicate.NewTemporal(string(p.ID()), *ta)
		}
		return predicate.NewImmutable(id)
	}

	fmt.Println(t.String())
	b := node.NewBlankNode()
	s, err := rp("_subject", t.p)
	if err != nil {
		return nil, nil, err
	}
	ts, _ := NewTriple(b, s, NewNodeObject(t.s))
	p, err := rp("_predicate", t.p)
	if err != nil {
		return nil, nil, err
	}
	tp, _ := NewTriple(b, p, NewPredicateObject(t.p))
	var to *Triple
	if t.o.l != nil {
		o, err := rp("_object", t.p)
		if err != nil {
			return nil, nil, err
		}
		to, _ = NewTriple(b, o, NewLiteralObject(t.o.l))
	}
	if t.o.n != nil {
		o, err := rp("_object", t.p)
		if err != nil {
			return nil, nil, err
		}
		to, _ = NewTriple(b, o, NewNodeObject(t.o.n))
	}
	if t.o.p != nil {
		o, err := rp("_object", t.p)
		if err != nil {
			return nil, nil, err
		}
		to, _ = NewTriple(b, o, NewPredicateObject(t.o.p))
	}

	return []*Triple{t, ts, tp, to}, b, nil
}