本文整理汇总了Golang中github.com/google/badwolf/triple/literal.DefaultBuilder函数的典型用法代码示例。如果您正苦于以下问题:Golang DefaultBuilder函数的具体用法?Golang DefaultBuilder怎么用?Golang DefaultBuilder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultBuilder函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSumAccumulators
func TestSumAccumulators(t *testing.T) {
// int64 sum accumulator.
var (
iv interface{}
ia = NewSumInt64LiteralAccumulator(0)
)
for i := int64(0); i < 5; i++ {
l, _ := literal.DefaultBuilder().Build(literal.Int64, i)
iv, _ = ia.Accumulate(l)
}
if got, want := iv.(int64), int64(10); got != want {
t.Errorf("Int64 sum accumulator failed; got %d, want %d", got, want)
}
// float64 sum accumulator.
var (
fv interface{}
fa = NewSumFloat64LiteralAccumulator(0)
)
for i := float64(0); i < 5; i += 1.0 {
l, _ := literal.DefaultBuilder().Build(literal.Float64, i)
fv, _ = fa.Accumulate(l)
}
if got, want := fv.(float64), float64(10); got != want {
t.Errorf("Int64 sum accumulator failed; got %f, want %f", got, want)
}
}
开发者ID:msingle,项目名称:badwolf,代码行数:26,代码来源:table_test.go
示例2: groupRangeReduce
// groupRangeReduce takes a sorted range and generates a new row containing
// the aggregated columns and the non aggregated ones.
func (t *Table) groupRangeReduce(i, j int, alias map[string]string, acc map[string]Accumulator) (Row, error) {
if i > j {
return nil, fmt.Errorf("cannot aggregate empty ranges [%d, %d)", i, j)
}
// Initialize the range and accumulator results.
rng := t.data[i:j]
vaccs := make(map[string]interface{})
// Reset the accumulators.
for _, a := range acc {
a.Reset()
}
// Aggregate the range using the provided aggregators.
for _, r := range rng {
for b, a := range acc {
av, err := a.Accumulate(r[b])
if err != nil {
return nil, err
}
vaccs[b] = av
}
}
// Create a new row based on the resulting aggregations with the proper
// binding aliasing and the non aggregated values.
newRow := Row{}
for b, v := range rng[0] {
acc, ok := vaccs[b]
if !ok {
if a, ok := alias[b]; ok {
newRow[a] = v
} else {
newRow[b] = v
}
} else {
a, ok := alias[b]
if !ok {
return nil, fmt.Errorf("aggregated bindings require and alias; binding %s missing alias", b)
}
// Accumulators currently only can return numeric literals.
switch acc.(type) {
case int64:
l, err := literal.DefaultBuilder().Build(literal.Int64, acc)
if err != nil {
return nil, err
}
newRow[a] = &Cell{L: l}
case float64:
l, err := literal.DefaultBuilder().Build(literal.Float64, acc)
if err != nil {
return nil, err
}
newRow[a] = &Cell{L: l}
default:
return nil, fmt.Errorf("aggregation of binding %s returned unknown value %v or type", b, acc)
}
}
}
return newRow, nil
}
开发者ID:google,项目名称:badwolf,代码行数:60,代码来源:table.go
示例3: TestCellString
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)
}
}
}
开发者ID:msingle,项目名称:badwolf,代码行数:27,代码来源:table_test.go
示例4: TestCountAccumulators
func TestCountAccumulators(t *testing.T) {
// Count accumulator.
var (
cv interface{}
ca = NewCountAccumulator()
)
for i := int64(0); i < 5; i++ {
cv, _ = ca.Accumulate(i)
}
if got, want := cv.(int64), int64(5); got != want {
t.Errorf("Count accumulator failed; got %d, want %d", got, want)
}
// Count distint accumulator
var (
dv interface{}
da = NewCountDistinctAccumulator()
)
for i := int64(0); i < 10; i++ {
l, _ := literal.DefaultBuilder().Build(literal.Int64, i%2)
dv, _ = da.Accumulate(l)
}
if got, want := dv.(int64), int64(2); got != want {
t.Errorf("Count distinct accumulator failed; got %d, want %d", got, want)
}
}
开发者ID:msingle,项目名称:badwolf,代码行数:25,代码来源:table_test.go
示例5: limitCollection
// limitCollection collects the limit of rows to return as indicated by the
// LIMIT clause.
func limitCollection() ElementHook {
var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
if ce.IsSymbol() || ce.token.Type == lexer.ItemLimit {
return f, nil
}
if ce.token.Type != lexer.ItemLiteral {
return nil, fmt.Errorf("limit clause required an int64 literal; found %v instead", ce.token)
}
l, err := literal.DefaultBuilder().Parse(ce.token.Text)
if err != nil {
return nil, fmt.Errorf("failed to parse limit literal %q with error %v", ce.token.Text, err)
}
if l.Type() != literal.Int64 {
return nil, fmt.Errorf("limit required an int64 value; found %s instead", l)
}
lv, err := l.Int64()
if err != nil {
return nil, fmt.Errorf("failed to retrieve the int64 value for literal %v with error %v", l, err)
}
st.limitSet, st.limit = true, lv
return f, nil
}
return f
}
开发者ID:google,项目名称:badwolf,代码行数:27,代码来源:hooks.go
示例6: populateBenchmarkStore
func populateBenchmarkStore(b *testing.B) storage.Store {
s, ctx := memory.NewStore(), context.Background()
g, err := s.NewGraph(ctx, "?test")
if err != nil {
b.Fatalf("memory.NewGraph failed to create \"?test\" with error %v", err)
}
buf := bytes.NewBufferString(testTriples)
if _, err := io.ReadIntoGraph(ctx, g, buf, literal.DefaultBuilder()); err != nil {
b.Fatalf("io.ReadIntoGraph failed to read test graph with error %v", err)
}
trpls := make(chan *triple.Triple)
go func() {
if err := g.Triples(ctx, trpls); err != nil {
b.Fatal(err)
}
}()
cnt := 0
for _ = range trpls {
cnt++
}
if got, want := cnt, len(strings.Split(testTriples, "\n"))-1; got != want {
b.Fatalf("Failed to import all test triples; got %v, want %v", got, want)
}
return s
}
开发者ID:google,项目名称:badwolf,代码行数:25,代码来源:planner_test.go
示例7: TestDataAccessTripleToRowObjectBindingsDroping
func TestDataAccessTripleToRowObjectBindingsDroping(t *testing.T) {
n, p, _ := testNodeTemporalPredicateLiteral(t)
ts, err := p.TimeAnchor()
if err != nil {
t.Fatal(err)
}
testTable := []struct {
t string
cls *semantic.GraphClause
bc *table.Cell
ac *table.Cell
tc *table.Cell
ic *table.Cell
tsc *table.Cell
atc *table.Cell
}{
{
t: n.String() + "\t" + p.String() + "\t" + n.String(),
cls: &semantic.GraphClause{
OBinding: "?o",
OAlias: "?alias",
OTypeAlias: "?o",
OIDAlias: "?id",
},
bc: &table.Cell{N: n},
ac: &table.Cell{N: n},
tc: &table.Cell{S: table.CellString(n.Type().String())},
ic: &table.Cell{S: table.CellString(n.ID().String())},
},
{
t: n.String() + "\t" + p.String() + "\t" + p.String(),
cls: &semantic.GraphClause{
OBinding: "?o",
OAlias: "?alias",
OIDAlias: "?id",
OAnchorBinding: "?ts",
OAnchorAlias: "?o",
},
bc: &table.Cell{P: p},
ac: &table.Cell{P: p},
ic: &table.Cell{S: table.CellString(string(p.ID()))},
tsc: &table.Cell{T: ts},
atc: &table.Cell{T: ts},
},
}
for _, entry := range testTable {
tpl, err := triple.Parse(entry.t, literal.DefaultBuilder())
if err != nil {
t.Errorf("triple.Parse failed to parse valid triple %q with error %v", entry.t, err)
}
r, err := tripleToRow(tpl, entry.cls)
if err != nil {
t.Errorf("tripleToRow for triple %q and clasuse %v, failed with error %v", tpl, entry.cls, err)
}
if r != nil {
t.Errorf("tripleToRow for triple %q and clasuse %v, failed to drop triple and returned %v", tpl, entry.cls, r)
}
}
}
开发者ID:google,项目名称:badwolf,代码行数:59,代码来源:data_access_test.go
示例8: TestDataAccessTripleToRowPredicateBindings
func TestDataAccessTripleToRowPredicateBindings(t *testing.T) {
n, p, _ := testNodeTemporalPredicateLiteral(t)
ts, err := p.TimeAnchor()
if err != nil {
t.Fatal(err)
}
testTable := []struct {
t string
cls *semantic.GraphClause
bc *table.Cell
ac *table.Cell
ic *table.Cell
tc *table.Cell
atc *table.Cell
}{
{
t: n.String() + "\t" + p.String() + "\t" + n.String(),
cls: &semantic.GraphClause{
PBinding: "?p",
PAlias: "?alias",
PIDAlias: "?id",
PAnchorBinding: "?ts",
PAnchorAlias: "?tsa",
},
bc: &table.Cell{P: p},
ac: &table.Cell{P: p},
ic: &table.Cell{S: table.CellString(string(p.ID()))},
tc: &table.Cell{T: ts},
atc: &table.Cell{T: ts},
},
}
for _, entry := range testTable {
tpl, err := triple.Parse(entry.t, literal.DefaultBuilder())
if err != nil {
t.Errorf("triple.Parse failed to parse valid triple %q with error %v", entry.t, err)
}
r, err := tripleToRow(tpl, entry.cls)
if err != nil {
t.Errorf("tripleToRow for triple %q and clasuse %v, failed with error %v", tpl, entry.cls, err)
}
if got, want := r["?p"], entry.bc; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding \"?p\"; got %q, want %q", got, want)
}
if got, want := r["?alias"], entry.ac; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding alias \"?alias\"; got %q, want %q", got, want)
}
if got, want := r["?id"], entry.ic; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding \"?id\"; got %q, want %q", got, want)
}
if got, want := r["?ts"], entry.tc; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding \"?ts\"; got %q, want %q", got, want)
}
if got, want := r["?tsa"], entry.tc; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding \"?tsa\"; got %q, want %q", got, want)
}
}
}
开发者ID:google,项目名称:badwolf,代码行数:57,代码来源:data_access_test.go
示例9: TestSerializationContents
func TestSerializationContents(t *testing.T) {
var buffer bytes.Buffer
ts, ctx := getTestTriples(t), context.Background()
g, err := memory.NewStore().NewGraph(ctx, "test")
if err != nil {
t.Fatalf("memory.NewStore().NewGraph should have never failed to create a graph")
}
if err := g.AddTriples(ctx, ts); err != nil {
t.Errorf("storage.AddTriples should have not fail to add triples %v with error %v", ts, err)
}
// Serialize to a buffer.
cnt, err := WriteGraph(ctx, &buffer, g)
if err != nil {
t.Errorf("io.WriteGraph failed to read %s with error %v", buffer.String(), err)
}
if cnt != 6 {
t.Errorf("io.WriteGraph should have been able to write 6 triples not %d", cnt)
}
// Deserialize from a buffer.
g2, err := memory.DefaultStore.NewGraph(ctx, "test2")
if err != nil {
t.Fatalf("memory.DefaultStore.NewGraph should have never failed to create a graph")
}
cnt2, err := ReadIntoGraph(ctx, g2, &buffer, literal.DefaultBuilder())
if err != nil {
t.Errorf("io.readIntoGraph failed to read %s with error %v", buffer.String(), err)
}
if cnt2 != 6 {
t.Errorf("io.readIntoGraph should have been able to read 6 triples not %d", cnt2)
}
// Check the graphs are equal
m := make(map[string]bool)
gs := 0
gtpls, err := g.Triples(ctx)
if err != nil {
t.Errorf("g.Triples failed to retrieve triples with error %v", err)
}
for trpl := range gtpls {
m[trpl.GUID()] = true
gs++
}
gos := 0
g2tpls, err := g2.Triples(ctx)
if err != nil {
t.Errorf("g2.Triples failed to retrieve triples with error %v", err)
}
for trpl := range g2tpls {
if _, ok := m[trpl.GUID()]; !ok {
t.Errorf("Failed to unmarshal marshaled triple; could not find triple %s", trpl.String())
}
gos++
}
if gs != gos || gs != 6 || gos != 6 {
t.Errorf("Failed to unmarshal marshaled the right number of triples, %d != %d != 6", gs, gos)
}
}
开发者ID:msingle,项目名称:badwolf,代码行数:57,代码来源:io_test.go
示例10: TestReify
func TestReify(t *testing.T) {
tr, err := ParseTriple("/some/type<some id>\t\"foo\"@[]\t\"bar\"@[]", literal.DefaultBuilder())
if err != nil {
t.Fatalf("triple.ParseTriple failed to parse valid triple with error %v", err)
}
rts, bn := tr.Reify()
if len(rts) != 4 || bn == nil {
t.Errorf("triple.Reify failed to create 4 valid triples and a valid blank node; returned %v, %s instead", rts, bn)
}
}
开发者ID:kleopatra999,项目名称:badwolf,代码行数:10,代码来源:triple_test.go
示例11: ToLiteral
// ToLiteral converts the node found by the lexer and converts it into a
// BadWolf literal.
func ToLiteral(ce ConsumedElement) (*literal.Literal, error) {
if ce.IsSymbol() {
return nil, fmt.Errorf("semantic.ToLiteral cannot convert symbol %v to a literal", ce)
}
tkn := ce.Token()
if tkn.Type != lexer.ItemLiteral {
return nil, fmt.Errorf("semantic.ToLiteral cannot convert token type %s to a literal", tkn.Type)
}
return literal.DefaultBuilder().Parse(tkn.Text)
}
开发者ID:ranjeet-floyd,项目名称:badwolf,代码行数:12,代码来源:convert.go
示例12: TestParsetriple
func TestParsetriple(t *testing.T) {
ss := []string{
"/some/type<some id>\t\"foo\"@[]\t/some/type<some id>",
"/some/type<some id>\t\"foo\"@[]\t\"bar\"@[]",
}
for _, s := range ss {
if _, err := ParseTriple(s, literal.DefaultBuilder()); err != nil {
t.Errorf("triple.Parse failed to parse valid triple %s with error %v", s, err)
}
}
}
开发者ID:ranjeet-floyd,项目名称:badwolf,代码行数:11,代码来源:triple_test.go
示例13: InitializeCommands
// InitializeCommands initializes the available commands with the given storage
// instance.
func InitializeCommands(driver storage.Store, chanSize, bulkTripleOpSize, builderSize int, rl repl.ReadLiner) []*command.Command {
return []*command.Command{
assert.New(driver, literal.DefaultBuilder(), chanSize),
benchmark.New(driver, chanSize),
export.New(driver, bulkTripleOpSize),
load.New(driver, bulkTripleOpSize, builderSize),
run.New(driver, chanSize),
repl.New(driver, chanSize, bulkTripleOpSize, builderSize, rl),
version.New(),
}
}
开发者ID:google,项目名称:badwolf,代码行数:13,代码来源:common.go
示例14: TestStatementAddData
func TestStatementAddData(t *testing.T) {
tr, err := triple.ParseTriple(`/_<foo> "foo"@[] /_<bar>`, literal.DefaultBuilder())
if err != nil {
t.Fatalf("triple.ParseTriple failed to parse valid triple with error %v", err)
}
st := &Statement{}
st.BindType(Query)
st.AddData(tr)
if got, want := st.Data(), []*triple.Triple{tr}; !reflect.DeepEqual(got, want) {
t.Errorf("semantic.AddData returned the wrong data avaiable; got %v, want %v", got, want)
}
}
开发者ID:opavader,项目名称:badwolf,代码行数:12,代码来源:semantic_test.go
示例15: init
func init() {
dach = dataAccumulator(literal.DefaultBuilder())
gach = graphAccumulator()
wnch = whereNextWorkingClause()
wich = whereInitWorkingClause()
wsch = whereSubjectClause()
wpch = wherePredicateClause()
woch = whereObjectClause()
predicateRegexp = regexp.MustCompile(`^"(.+)"@\["?([^\]"]*)"?\]$`)
boundRegexp = regexp.MustCompile(`^"(.+)"@\["?([^\]"]*)"?,"?([^\]"]*)"?\]$`)
}
开发者ID:ranjeet-floyd,项目名称:badwolf,代码行数:12,代码来源:hooks.go
示例16: populateTestStore
func populateTestStore(t *testing.T) storage.Store {
s := memory.NewStore()
g, err := s.NewGraph("?test_graph")
if err != nil {
t.Fatalf("memory.NewGraph failed to create \"?test_graph\" with error %v", err)
}
b := bytes.NewBufferString(testTriples)
if _, err := io.ReadIntoGraph(g, b, literal.DefaultBuilder()); err != nil {
t.Fatalf("io.ReadIntoGraph failed to read test graph with error %v", err)
}
return s
}
开发者ID:rtu,项目名称:badwolf,代码行数:12,代码来源:planner_test.go
示例17: createTriples
func createTriples(t *testing.T, ss []string) []*triple.Triple {
ts := []*triple.Triple{}
for _, s := range ss {
trpl, err := triple.Parse(s, literal.DefaultBuilder())
if err != nil {
t.Errorf("triple.Parse failed to parse valid triple %s with error %v", s, err)
continue
}
ts = append(ts, trpl)
}
return ts
}
开发者ID:google,项目名称:badwolf,代码行数:12,代码来源:memory_test.go
示例18: assertCommand
// assertCommand runs all the BQL statements available in the file.
func assertCommand(cmd *Command, args []string) int {
if len(args) < 3 {
fmt.Fprintf(os.Stderr, "Missing required folder path. ")
cmd.Usage()
return 2
}
// Open the folder.
folder := strings.TrimSpace(args[2])
f, err := os.Open(folder)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to open folder %s\n\n\t%v\n\n", folder, err)
return 2
}
fis, err := f.Readdir(0)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to read folder %s\n\n\t%v\n\n", folder, err)
return 2
}
fmt.Printf("Processing folder %q...\n\n", folder)
for _, fi := range fis {
if !strings.Contains(fi.Name(), "json") {
continue
}
fmt.Println("-------------------------------------------------------------")
fmt.Printf("Processing file %q...\n\n", fi.Name())
lns, err := readLines(path.Join(folder, fi.Name()))
if err != nil {
fmt.Fprintf(os.Stderr, "\n\n\tFailed to read file content with error %v\n\n", err)
return 2
}
rawStory := strings.Join(lns, "\n")
s := &compliance.Story{}
if err := s.Unmarshal(rawStory); err != nil {
fmt.Fprintf(os.Stderr, "\n\n\tFailed to unmarshal story with error %v\n\n", err)
return 2
}
m, err := s.Run(memory.NewStore(), literal.DefaultBuilder())
if err != nil {
fmt.Fprintf(os.Stderr, "\n\n\tFailed to run story %q with error %v\n\n", s.Name, err)
return 2
}
for aid, aido := range m {
if aido.Equal {
fmt.Printf("%s [TRUE]\n", aid)
} else {
fmt.Printf("%s [FALSE]\n\nGot:\n\n%s\nWant:\n\n%s\n", aid, aido.Got, aido.Want)
}
}
}
fmt.Println("-------------------------------------------------------------")
fmt.Println("\ndone")
return 0
}
开发者ID:defrager,项目名称:badwolf,代码行数:54,代码来源:assert.go
示例19: getTestTriples
func getTestTriples(t *testing.T, trpls []string) []*triple.Triple {
var ts []*triple.Triple
for _, s := range trpls {
trpl, err := triple.Parse(s, literal.DefaultBuilder())
if err != nil {
t.Fatalf("triple.Parse failed to parse valid triple %s with error %v", s, err)
continue
}
ts = append(ts, trpl)
}
return ts
}
开发者ID:google,项目名称:badwolf,代码行数:12,代码来源:data_access_test.go
示例20: TestDataAccessBasicBindings
func TestDataAccessBasicBindings(t *testing.T) {
n, p, l := testNodePredicateLiteral(t)
cls := &semantic.GraphClause{
SBinding: "?s",
PBinding: "?p",
OBinding: "?o",
}
testTable := []struct {
t string
sc *table.Cell
pc *table.Cell
oc *table.Cell
}{
{
t: n.String() + "\t" + p.String() + "\t" + n.String(),
sc: &table.Cell{N: n},
pc: &table.Cell{P: p},
oc: &table.Cell{N: n},
},
{
t: n.String() + "\t" + p.String() + "\t" + p.String(),
sc: &table.Cell{N: n},
pc: &table.Cell{P: p},
oc: &table.Cell{P: p},
},
{
t: n.String() + "\t" + p.String() + "\t" + l.String(),
sc: &table.Cell{N: n},
pc: &table.Cell{P: p},
oc: &table.Cell{L: l},
},
}
for _, entry := range testTable {
tpl, err := triple.Parse(entry.t, literal.DefaultBuilder())
if err != nil {
t.Errorf("triple.Parse failed to parse valid triple %q with error %v", entry.t, err)
}
r, err := tripleToRow(tpl, cls)
if err != nil {
t.Errorf("tripleToRow for triple %q and clasuse %v, failed with error %v", tpl, cls, err)
}
if got, want := r["?s"], entry.sc; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding \"?s\"; got %q, want %q", got, want)
}
if got, want := r["?p"], entry.pc; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding \"?p\"; got %q, want %q", got, want)
}
if got, want := r["?o"], entry.oc; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding \"?o\"; got %q, want %q", got, want)
}
}
}
开发者ID:google,项目名称:badwolf,代码行数:52,代码来源:data_access_test.go
注:本文中的github.com/google/badwolf/triple/literal.DefaultBuilder函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论