本文整理汇总了Golang中github.com/google/badwolf/triple.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Parse函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Eval
// Eval loads the triples in the file against as indicated by the command.
func Eval(ctx context.Context, usage string, args []string, store storage.Store, bulkSize, builderSize int) int {
if len(args) <= 3 {
fmt.Fprintf(os.Stderr, "[ERROR] Missing required file path and/or graph names.\n\n%s", usage)
return 2
}
graphs, lb := strings.Split(args[len(args)-1], ","), literal.NewBoundedBuilder(builderSize)
trplsChan, errChan, doneChan := make(chan *triple.Triple), make(chan error), make(chan bool)
path := args[len(args)-2]
go storeTriple(ctx, store, graphs, bulkSize, trplsChan, errChan, doneChan)
cnt, err := io.ProcessLines(path, func(line string) error {
t, err := triple.Parse(line, lb)
if err != nil {
return err
}
trplsChan <- t
return <-errChan
})
if err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Failed to process file %q. Ivalid triple on line %d. %v\n", path, cnt, err)
return 2
}
doneChan <- true
if err := <-errChan; err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Failed to process file %q. Ivalid triple on line %d. %v\n", path, cnt, err)
return 2
}
fmt.Printf("Successfully processed %d lines from file %q.\nTriples loaded into graphs:\n\t- %s\n", cnt, path, strings.Join(graphs, "\n\t- "))
return 0
}
开发者ID:google,项目名称:badwolf,代码行数:30,代码来源:load.go
示例2: 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
示例3: 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
示例4: TestStatementAddData
func TestStatementAddData(t *testing.T) {
tr, err := triple.Parse(`/_<foo> "foo"@[] /_<bar>`, literal.DefaultBuilder())
if err != nil {
t.Fatalf("triple.Parse 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:msingle,项目名称:badwolf,代码行数:12,代码来源:semantic_test.go
示例5: 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
示例6: 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
示例7: 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
示例8: TestDataAccessTripleToRowSubjectBindings
func TestDataAccessTripleToRowSubjectBindings(t *testing.T) {
n, p, _ := testNodePredicateLiteral(t)
testTable := []struct {
t string
cls *semantic.GraphClause
sc *table.Cell
ac *table.Cell
tc *table.Cell
ic *table.Cell
}{
{
t: n.String() + "\t" + p.String() + "\t" + n.String(),
cls: &semantic.GraphClause{
SBinding: "?s",
SAlias: "?alias",
STypeAlias: "?type",
SIDAlias: "?id",
},
sc: &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())},
},
}
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["?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["?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["?type"], entry.tc; !reflect.DeepEqual(got, want) {
t.Errorf("tripleToRow failed to return right value for binding \"?type\"; 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 \"?ud\"; got %q, want %q", got, want)
}
}
}
开发者ID:google,项目名称:badwolf,代码行数:47,代码来源:data_access_test.go
示例9: ReadIntoGraph
// ReadIntoGraph reads a graph out of the provided reader. The data on the
// reader is interpret as text. Each line represents one triple using the
// standard serialized format. ReadIntoGraph will stop if fails to Parse
// a triple on the stream. The triples read till then would have also been
// added to the graph. The int value returns the number of triples added.
func ReadIntoGraph(ctx context.Context, g storage.Graph, r io.Reader, b literal.Builder) (int, error) {
cnt, scanner := 0, bufio.NewScanner(r)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
text := strings.TrimSpace(scanner.Text())
if text == "" {
continue
}
t, err := triple.Parse(text, b)
if err != nil {
return cnt, err
}
cnt++
g.AddTriples(ctx, []*triple.Triple{t})
}
return cnt, nil
}
开发者ID:google,项目名称:badwolf,代码行数:22,代码来源:io.go
示例10: getTestTriples
func getTestTriples(t *testing.T) []*triple.Triple {
ts := []*triple.Triple{}
ss := []string{
"/u<john>\t\"knows\"@[]\t/u<mary>",
"/u<john>\t\"knows\"@[]\t/u<peter>",
"/u<john>\t\"knows\"@[]\t/u<alice>",
"/u<mary>\t\"knows\"@[]\t/u<andrew>",
"/u<mary>\t\"knows\"@[]\t/u<kim>",
"/u<mary>\t\"knows\"@[]\t/u<alice>",
}
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:defrager,项目名称:badwolf,代码行数:20,代码来源:memory_test.go
示例11: populateSources
// populateSources create all the graph required for the story and
// populates it with the provided data.
func (s *Story) populateSources(ctx context.Context, st storage.Store, b literal.Builder) error {
for _, src := range s.Sources {
g, err := getGraphFromStore(ctx, st, src.ID)
if err != nil {
return err
}
var trps []*triple.Triple
for _, trp := range src.Facts {
t, err := triple.Parse(trp, b)
if err != nil {
return err
}
trps = append(trps, t)
}
if err := g.AddTriples(ctx, trps); err != nil {
return err
}
}
return nil
}
开发者ID:google,项目名称:badwolf,代码行数:22,代码来源:runner.go
注:本文中的github.com/google/badwolf/triple.Parse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论