Documentation
¶
Overview ¶
Package sparql is an in-process RDF quad store with a SPARQL 1.1 query and update engine.
Index ¶
- Constants
- func ParseRDFLenient(f Format, data []byte, opts ParseOptions, skip bool) ([]Quad, []*ParseError)
- func SerializeQuads(f Format, qs []Quad) ([]byte, error)
- func SerializeTriples(f Format, ts []Triple) ([]byte, error)
- func SortedGraphNames(gs []Term) []string
- func WriteResult(r *Result, f ResultFormat) ([]byte, error)
- type Binding
- type DocFetcher
- type Document
- type Expr
- type Fetcher
- type Format
- type Hints
- type Kind
- type NumericDataError
- type ParameterError
- type ParseError
- type ParseOptions
- type Quad
- type Query
- type Result
- type ResultFormat
- type ResultKind
- type ServiceFunc
- type Storage
- type Store
- func (s *Store) Add(qs []Quad) int
- func (s *Store) Apply(ctx context.Context, u *Update, opts UpdateOptions) (UpdateResult, error)
- func (s *Store) ApplyGraphWrite(g Term, qs []Quad, replace bool)
- func (s *Store) Clear()
- func (s *Store) ClearGraph(g Term) int
- func (s *Store) Export() []byte
- func (s *Store) GraphQuads(g Term) []Quad
- func (s *Store) Graphs() []Term
- func (s *Store) Import(data []byte) error
- func (s *Store) Len() int
- func (s *Store) Query(ctx context.Context, src string) (*Result, error)
- func (s *Store) RebuildIndexes()
- func (s *Store) ReplaceGraph(g Term, qs []Quad)
- func (s *Store) Run(ctx context.Context, q *Query) (*Result, error)
- func (s *Store) Stats() (int, int, int)
- func (s *Store) Storage() Storage
- func (s *Store) Stream() *streamlog.Log
- func (s *Store) Summary() Summary
- func (s *Store) Update(ctx context.Context, src string, opts UpdateOptions) (UpdateResult, error)
- func (s *Store) Wipe()
- type SubjectStructure
- type Summary
- type SyntaxError
- type Term
- type Triple
- type Update
- type UpdateOptions
- type UpdateResult
Constants ¶
const ( DescribeForwardOneStep = "ForwardOneStep" DescribeSymmetricOneStep = "SymmetricOneStep" DescribeCBD = "CBD" DescribeSCBD = "SCBD" )
Documented DESCRIBE modes and limits (sparql-query-hints-for-describe.html).
const ( NSXSD = "http://www.w3.org/2001/XMLSchema#" NSRDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" NSRDFS = "http://www.w3.org/2000/01/rdf-schema#" NSOWL = "http://www.w3.org/2002/07/owl#" XSDString = NSXSD + "string" XSDInteger = NSXSD + "integer" XSDDecimal = NSXSD + "decimal" XSDDouble = NSXSD + "double" XSDFloat = NSXSD + "float" XSDBoolean = NSXSD + "boolean" XSDDateTime = NSXSD + "dateTime" RDFType = NSRDF + "type" RDFFirst = NSRDF + "first" RDFRest = NSRDF + "rest" RDFNil = NSRDF + "nil" RDFSubject = NSRDF + "subject" RDFPredicate = NSRDF + "predicate" RDFObject = NSRDF + "object" RDFLangString = NSRDF + "langString" // DefaultGraph is the named graph Neptune uses when no graph is given. DefaultGraph = "http://aws.amazon.com/neptune/vocab/v01/DefaultNamedGraph" // DefaultBase is the base IRI Neptune applies when a request carries none. DefaultBase = "http://aws.amazon.com/neptune/default/" )
Well-known IRIs.
const BlobThreshold = 1024
BlobThreshold is the term size from which a dictionary entry counts as a blob.
const HintNS = "http://aws.amazon.com/neptune/vocab/v01/QueryHints#"
HintNS is the Neptune query-hint vocabulary namespace.
Variables ¶
This section is empty.
Functions ¶
func ParseRDFLenient ¶
func ParseRDFLenient(f Format, data []byte, opts ParseOptions, skip bool) ([]Quad, []*ParseError)
ParseRDFLenient parses a document. With skip set, line-based formats resume after a bad line; other formats stop at their first error.
func SerializeQuads ¶
SerializeQuads renders quads in the given format. Triple-only formats ignore graph names.
func SerializeTriples ¶
SerializeTriples renders triples (no graph names).
func SortedGraphNames ¶
SortedGraphNames renders graph IRIs for listings.
func WriteResult ¶
func WriteResult(r *Result, f ResultFormat) ([]byte, error)
WriteResult serialises a SELECT or ASK result.
Types ¶
type DocFetcher ¶
DocFetcher retrieves a LOAD source together with its Content-Type.
type Format ¶
type Format uint8
Format is an RDF serialization.
const ( FormatNTriples Format = iota FormatNQuads FormatTurtle FormatTriG FormatRDFXML FormatJSONLD FormatTriX FormatRDF4JBinary )
RDF formats.
func FormatForContentType ¶
FormatForContentType maps the media types Neptune documents for SPARQL UPDATE LOAD to a format.
func FormatForSource ¶
FormatForSource guesses an RDF format from a LOAD source name.
type Hints ¶
type Hints struct {
QueryID string
DescribeMode string
TimeoutMs int64
IterLimit int
StmtLimit int
HasTimeout bool
// contains filtered or unexported fields
}
Hints are the Neptune query hints found in a request.
type NumericDataError ¶
type NumericDataError struct{ Msg string }
NumericDataError is an integer literal beyond the 64-bit range Neptune stores.
func (*NumericDataError) Error ¶
func (e *NumericDataError) Error() string
type ParameterError ¶
ParameterError is an invalid input value, such as a LOAD source that cannot be read or parsed.
func (*ParameterError) Error ¶
func (e *ParameterError) Error() string
func (*ParameterError) Unwrap ¶
func (e *ParameterError) Unwrap() error
type ParseError ¶
ParseError is a syntax error at a record (statement or line) of an RDF document.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type ParseOptions ¶
type ParseOptions struct {
// Base resolves relative IRIs (Neptune's loader default is http://aws.amazon.com/neptune/default).
Base string
// Graph receives triples that name no graph; DefaultGraph when unset.
Graph Term
// KeepBlankLabels keeps blank-node labels verbatim instead of scoping them to this document.
KeepBlankLabels bool
}
ParseOptions tunes RDF parsing.
type Query ¶
type Query struct {
Where *group
Values *valuesData
Prefixes map[string]string
Base string
Proj []projItem
Template []triplePat
Describe []node
From []Term
FromNamed []Term
GroupBy []projItem
Having []Expr
Order []orderCond
Hints Hints
Limit int
Offset int
Form queryForm
Distinct bool
Star bool
// contains filtered or unexported fields
}
Query is a parsed SPARQL query.
func (*Query) ProjectedVars ¶
ProjectedVars lists the variables a SELECT produces.
func (*Query) SetDataset ¶
SetDataset overrides the query's FROM / FROM NAMED clauses (SPARQL protocol default-graph-uri / named-graph-uri).
func (*Query) SetService ¶
func (q *Query) SetService(f ServiceFunc)
SetService supplies the federation transport for SERVICE clauses.
type Result ¶
type Result struct {
Vars []string
Rows []Binding
Triples []Triple
Kind ResultKind
Bool bool
}
Result is the outcome of a query.
func ParseSelectJSON ¶
ParseSelectJSON decodes a SPARQL 1.1 Query Results JSON document (SELECT or ASK).
type ResultFormat ¶
type ResultFormat uint8
ResultFormat is a query-result serialization.
const ( ResultJSON ResultFormat = iota ResultXML ResultCSV ResultTSV ResultBoolean ResultBinary )
Query-result formats.
type ResultKind ¶
type ResultKind uint8
ResultKind says which payload of a Result is populated.
const ( ResultSelect ResultKind = iota ResultAsk ResultGraph )
Result kinds.
type ServiceFunc ¶
ServiceFunc runs a SELECT query against the remote SPARQL endpoint of a SERVICE clause.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a concurrency-safe in-memory RDF quad store.
func (*Store) Apply ¶
func (s *Store) Apply(ctx context.Context, u *Update, opts UpdateOptions) (UpdateResult, error)
Apply runs a parsed update under the write lock; a failing operation rolls the whole request back.
func (*Store) ApplyGraphWrite ¶
ApplyGraphWrite implements Graph Store PUT (replace) and POST (merge) into g. Quads that name other graphs are written there too, and every triple also lands in g, as Neptune documents.
func (*Store) ClearGraph ¶
ClearGraph removes every triple in g and reports how many were removed.
func (*Store) GraphQuads ¶
GraphQuads returns a sorted copy of the triples in graph g.
func (*Store) RebuildIndexes ¶
func (s *Store) RebuildIndexes()
RebuildIndexes recreates the subject, predicate, object and graph indexes from the quads.
func (*Store) ReplaceGraph ¶
ReplaceGraph atomically swaps the contents of g for qs (all forced into g).
func (*Store) Stats ¶
Stats summarises the store for the DFE statistics endpoints: distinct predicate sets per subject (signatures), subjects (instances) and distinct predicates.
func (*Store) Storage ¶
Storage reports the quad count and the distinct terms a Neptune dictionary would hold.
func (*Store) Summary ¶
Summary lists the store's classes, predicate counts and subject structures for the graph summary endpoint.
func (*Store) Update ¶
func (s *Store) Update(ctx context.Context, src string, opts UpdateOptions) (UpdateResult, error)
Update parses and applies a SPARQL update request atomically.
type SubjectStructure ¶
SubjectStructure is a distinct predicate set and how many subjects have it.
type Summary ¶
type Summary struct {
Classes []string `json:"classes"`
Predicates []map[string]int `json:"predicates"`
SubjectStructures []SubjectStructure `json:"subjectStructures"`
NumDistinctSubjects int `json:"numDistinctSubjects"`
NumDistinctPreds int `json:"numDistinctPredicates"`
NumQuads int `json:"numQuads"`
NumClasses int `json:"numClasses"`
}
Summary is the Neptune graph summary payload for an RDF graph.
type SyntaxError ¶
type SyntaxError struct{ Msg string }
SyntaxError reports malformed query, update or RDF input.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type Term ¶
Term is an RDF term. A plain literal has an empty Datatype; a language-tagged one has Lang set.
func LangLiteral ¶
LangLiteral returns a language-tagged literal.
type Update ¶
type Update struct {
Hints Hints
// contains filtered or unexported fields
}
Update is a parsed SPARQL update request.
func ParseUpdate ¶
ParseUpdate parses a SPARQL 1.1 Update request.
type UpdateOptions ¶
type UpdateOptions struct {
Fetch Fetcher
FetchDoc DocFetcher
Service ServiceFunc
}
UpdateOptions carries the update's external dependencies; FetchDoc wins over Fetch.
type UpdateResult ¶
type UpdateResult struct{ Inserted, Deleted int }
UpdateResult counts the triples an update changed.
Source Files
¶
- aggregate.go
- ast.go
- bgp.go
- describe.go
- eval.go
- explain.go
- expr_eval.go
- expr_parse.go
- funcs.go
- funcs_hash.go
- hints.go
- jsonld.go
- jsonld_json.go
- lexer.go
- numeric.go
- parser.go
- query.go
- rdfparse.go
- rdfwrite.go
- rdfwrite_ext.go
- rdfxml.go
- results.go
- results_binary.go
- service.go
- storage.go
- store.go
- stream.go
- summary.go
- term.go
- update.go
- update_parse.go
- update_prefetch.go