Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binding ¶
type Binding map[string]struct { Type Type `json:"type"` DataType IRI `json:"datatype"` XMLLang string `json:"xml:lang"` Value interface{} `json:"value"` }
Binding is a part of a SPARQL query result json.
type Client ¶
type Client struct { HTTPClient http.Client Logger logger.Logger Endpoint string // contains filtered or unexported fields }
Client queries to its SPARQL endpoint.
func (*Client) Query ¶
Query queries to the endpoint.
Example (Ask) ¶
cli, err := New("http://ja.dbpedia.org/sparql", MaxIdleConns(100), IdleConnTimeout(90*time.Second), Timeout(30*time.Second), Prefix("dbpj", "http://ja.dbpedia.org/resource/"), Prefix("dbp-owl", "http://dbpedia.org/ontology/"), ) if err != nil { panic(err) } ctx := context.Background() if err2 := cli.Ping(ctx); err2 != nil { panic(err2) } // Ask result, err := cli.Query( ctx, `ask { dbpj:有安杏果 dbp-owl:birthYear "1995"^^xsd:gYear . }`, ) if err != nil { panic(err) } log.Printf("%+v\n", result)
Output:
Example (Iri_parameter) ¶
cli, err := New("http://ja.dbpedia.org/sparql", MaxIdleConns(100), IdleConnTimeout(90*time.Second), Timeout(30*time.Second), Prefix("dbpj", "http://ja.dbpedia.org/resource/"), Prefix("dbp-owl", "http://dbpedia.org/ontology/"), ) if err != nil { panic(err) } ctx := context.Background() if err2 := cli.Ping(ctx); err2 != nil { panic(err2) } // IRI parameter result, err := cli.Query( ctx, "select * where "+ "{ $1 <http://ja.dbpedia.org/property/name> ?name . } LIMIT 10", Param{ Ordinal: 1, Value: IRI("http://ja.dbpedia.org/resource/ももいろクローバーZ"), }, ) if err != nil { panic(err) } log.Printf("%+v\n", result)
Output:
Example (Language_tag) ¶
cli, err := New("http://ja.dbpedia.org/sparql", MaxIdleConns(100), IdleConnTimeout(90*time.Second), Timeout(30*time.Second), Prefix("dbpj", "http://ja.dbpedia.org/resource/"), Prefix("dbp-owl", "http://dbpedia.org/ontology/"), ) if err != nil { panic(err) } ctx := context.Background() if err2 := cli.Ping(ctx); err2 != nil { panic(err2) } // With language tags result, err := cli.Query( ctx, `select * where { ?s <http://ja.dbpedia.org/property/name> $1 . } LIMIT 10`, Param{ Ordinal: 1, Value: Literal{ Value: "ももいろクローバー", LanguageTag: "ja", }, }, ) if err != nil { panic(err) } log.Printf("%+v\n", result)
Output:
Example (Parameter) ¶
cli, err := New("http://ja.dbpedia.org/sparql", MaxIdleConns(100), IdleConnTimeout(90*time.Second), Timeout(30*time.Second), Prefix("dbpj", "http://ja.dbpedia.org/resource/"), Prefix("dbp-owl", "http://dbpedia.org/ontology/"), ) if err != nil { panic(err) } ctx := context.Background() if err2 := cli.Ping(ctx); err2 != nil { panic(err2) } // Parameter result, err := cli.Query( ctx, `select * where { ?s <http://dbpedia.org/ontology/wikiPageID> $1 . } LIMIT 1`, Param{ Ordinal: 1, Value: 1529557, }, ) if err != nil { panic(err) } log.Printf("%+v\n", result)
Output:
Example (Parameterized_subject_and_object) ¶
cli, err := New("http://ja.dbpedia.org/sparql", MaxIdleConns(100), IdleConnTimeout(90*time.Second), Timeout(30*time.Second), Prefix("dbpj", "http://ja.dbpedia.org/resource/"), Prefix("dbp-owl", "http://dbpedia.org/ontology/"), ) if err != nil { panic(err) } ctx := context.Background() if err2 := cli.Ping(ctx); err2 != nil { panic(err2) } // Parameterized subject and object result, err := cli.Query(ctx, `select * where { $1 $2 ?o . } LIMIT 1000`, Param{ Ordinal: 1, Value: PrefixedName("dbpj:有安杏果"), }, Param{ Ordinal: 2, Value: PrefixedName("dbp-owl:birthYear"), }, ) if err != nil { panic(err) } log.Printf("%+v\n", result)
Output:
Example (Simple) ¶
cli, err := New("http://ja.dbpedia.org/sparql", MaxIdleConns(100), IdleConnTimeout(90*time.Second), Timeout(30*time.Second), Prefix("dbpj", "http://ja.dbpedia.org/resource/"), Prefix("dbp-owl", "http://dbpedia.org/ontology/"), ) if err != nil { panic(err) } ctx := context.Background() if err2 := cli.Ping(ctx); err2 != nil { panic(err2) } // Simple use case result, err := cli.Query( ctx, "select distinct * where "+ "{ <http://ja.dbpedia.org/resource/東京都> ?p ?o . } LIMIT 10", ) if err != nil { panic(err) } log.Printf("%+v\n", result)
Output:
Example (Typed_literal_prefixed_name) ¶
cli, err := New("http://ja.dbpedia.org/sparql", MaxIdleConns(100), IdleConnTimeout(90*time.Second), Timeout(30*time.Second), Prefix("dbpj", "http://ja.dbpedia.org/resource/"), Prefix("dbp-owl", "http://dbpedia.org/ontology/"), ) if err != nil { panic(err) } ctx := context.Background() if err2 := cli.Ping(ctx); err2 != nil { panic(err2) } // Typed literal with PrefixedName result, err := cli.Query( ctx, `select * where { ?s <http://dbpedia.org/ontology/birthYear> $1 . } LIMIT 1`, Param{ Ordinal: 1, Value: Literal{ Value: "1995", DataType: PrefixedName("xsd:gYear"), }, }, ) if err != nil { panic(err) } log.Printf("%+v\n", result)
Output:
Example (Typed_literal_with_iri) ¶
cli, err := New("http://ja.dbpedia.org/sparql", MaxIdleConns(100), IdleConnTimeout(90*time.Second), Timeout(30*time.Second), Prefix("dbpj", "http://ja.dbpedia.org/resource/"), Prefix("dbp-owl", "http://dbpedia.org/ontology/"), ) if err != nil { panic(err) } ctx := context.Background() if err2 := cli.Ping(ctx); err2 != nil { panic(err2) } // Typed literal with IRI result, err := cli.Query( ctx, "select * where "+ "{ ?s <http://dbpedia.org/ontology/wikiPageLength> $1 . } LIMIT 1", Param{ Ordinal: 1, Value: Literal{ Value: 76516, DataType: IRI("http://www.w3.org/2001/XMLSchema#nonNegativeInteger"), }, }, ) if err != nil { panic(err) } log.Printf("%+v\n", result)
Output:
type Head ¶
type Head struct {
Vars []string `json:"vars"`
}
Head is a part of a SPARQL query result json.
type Option ¶
Option sets an option to the SPARQL client.
func IdleConnTimeout ¶
IdleConnTimeout sets the maximum amount of time an idle (keep-alive) connection.
type Param ¶
type Param struct { // Ordinal position of the parameter starting from one and is always set. Ordinal int // Value is the parameter value. Value interface{} }
Param is a parameter to fill placeholders
type PrefixedName ¶
type PrefixedName string
PrefixedName https://www.w3.org/TR/rdf-sparql-query/#rPrefixedName
type QueryResult ¶
type QueryResult struct { Head Head `json:"head"` Results Results `json:"results"` Boolean bool `json:"boolean"` }
QueryResult is a destination to decoding a SPARQL query result json.
type Results ¶
type Results struct {
Bindings []Binding `json:"bindings"`
}
Results is a part of a SPARQL query result json.
type Serializable ¶
type Serializable interface {
Serialize() string
}
Serializable serialize data to embed to queries.
Click to show internal directories.
Click to hide internal directories.