-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoc.go
64 lines (64 loc) · 2.24 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Package sparql provides a series of parsers for turning SPARQL JSON
// (mime type: application/sparql-results+json only- this package doesn't
// touch xml) into useful go data types.
//
// Within this package there are two subpackages:
//
// 1. github.com/anglo-korean/sparql/bank - a sparql 'query bank' (though realistically I guess this may work for other well-formed data) with `text/template` support
// 2. github.com/anglo-korean/sparql/repo - a sparql respository client, with various helpers such as auth, and caching
//
// This package is simple to use, stable, and relatively quick. It accepts some json, in `string`, `[]byte`, or `io.Reader` form, and returns some rdf terms:
//
// package main
//
// import (
// "fmt"
//
// "github.com/anglo-korean/sparql"
// )
//
// var data = `{"head":{"vars":["item","itemLabel"]},"results":{"bindings":[{"item":{"type":"uri","value":"http://www.wikidata.org/entity/Q378619"},"itemLabel":{"xml:lang":"en","type":"literal","value":"CC"}},{"item":{"type":"uri","value":"http://www.wikidata.org/entity/Q498787"},"itemLabel":{"xml:lang":"en","type":"literal","value":"Muezza"}}]}}`
//
// func main() {
// res, err := sparql.ParseString(data)
// if err != nil {
// return
// }
//
// fmt.Printf("%v\n", res.Solutions())
// }
//
// Or, to query data using the provided client:
//
// package main
//
// import (
// "fmt"
//
// "github.com/anglo-korean/sparql/repo"
// )
//
// func main() {
// client, err := repo.New("https://example.com")
// if err != nil {
// return
// }
//
// res, err := client.Query("SELECT * WHERE { ?s ?p ?o } LIMIT 1")
// if err != nil {
// return
// }
//
// fmt.Printf("%v\n", res.Solutions())
// }
//
// Note that the client provided in repo parses returned json autiomatically.
// (Further documentation for both the repo client and the query bank may be found in those specific packages)
//
// Parsed results are parsed into a sparql.Results type, which contains two functions used for accessing data:
//
// 1. `res.Bindings()` -> `map[string][]rdf.Term`
// 2. `res.Solutions()` -> `[]map[string]rdf.Term`
//
// An example of working with this data may be found in the examples directory
package sparql