Documentation ¶
Overview ¶
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
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DateFormat = time.RFC3339
DateFormat is the expected layout of the xsd:DateTime values. You can override it if your triple store uses a different layout.
Functions ¶
This section is empty.
Types ¶
type Results ¶
type Results struct { Head header Results results }
Results holds the parsed results of a application/sparql-results+json response.
func Parse ¶
Parse takes an application/sparql-results+json response as an io.Reader (like from an http.Response.Body) and parses it into a Results struct
func ParseBytes ¶
ParseBytes takes a bytes containing valid sparql-results+json and returns a set of Results
func ParseString ¶
ParseString takes a string containing valid sparql-results+json and returns a set of Results
Directories ¶
Path | Synopsis |
---|---|
Package bank provides a query bank for sparql queries.
|
Package bank provides a query bank for sparql queries. |
Package repo provides a simple http client for interacting with sparql endpoints.
|
Package repo provides a simple http client for interacting with sparql endpoints. |