Documentation ¶
Overview ¶
Package quad defines quad and triple handling.
Index ¶
- Constants
- Variables
- func Copy(dst Writer, src Reader) (n int, err error)
- func CopyBatch(dst BatchWriter, src Reader, batchSize int) (cnt int, err error)
- func HashOf(v Value) []byte
- func HashTo(v Value, p []byte)
- func NativeOf(v Value) interface{}
- func RegisterFormat(f Format)
- func RegisterStringConversion(dataType IRI, fnc StringConversion)
- func StringOf(v Value) string
- type BNode
- type BatchReader
- type BatchWriter
- type Bool
- type ByQuadString
- type ByValueString
- type Direction
- type Equaler
- type Float
- type Format
- type IRI
- type Int
- type LangString
- type Quad
- func (q Quad) Get(d Direction) Value
- func (q Quad) GetString(d Direction) string
- func (q Quad) IsValid() bool
- func (q Quad) MarshalJSON() ([]byte, error)
- func (q Quad) NQuad() string
- func (q *Quad) Set(d Direction, v Value)
- func (q Quad) String() string
- func (q *Quad) UnmarshalJSON(data []byte) error
- type Quads
- type Raw
- type ReadCloser
- type ReadSkipCloser
- type Reader
- type Sequence
- type Skipper
- type String
- type StringConversion
- type Time
- type TypedString
- type TypedStringer
- type Value
- type WriteCloser
- type Writer
Constants ¶
const HashSize = sha1.Size
HashSize is a size of the slice, returned by HashOf.
Variables ¶
var ( ErrInvalid = errors.New("invalid N-Quad") ErrIncomplete = errors.New("incomplete N-Quad") )
var DefaultBatch = 10000
Functions ¶
func Copy ¶
Copy will copy all quads from src to dst. It returns copied quads count and an error, if it failed.
Copy will try to cast dst to BatchWriter and will switch to CopyBatch implementation in case of success.
func CopyBatch ¶
func CopyBatch(dst BatchWriter, src Reader, batchSize int) (cnt int, err error)
CopyBatch will copy all quads from src to dst in a batches of batchSize. It returns copied quads count and an error, if it failed.
If batchSize <= 0 default batch size will be used.
func NativeOf ¶
func NativeOf(v Value) interface{}
NativeOf safely call v.Native, returning nil in case of nil Value.
func RegisterFormat ¶
func RegisterFormat(f Format)
RegisterFormat registers a new quad-file format.
func RegisterStringConversion ¶
func RegisterStringConversion(dataType IRI, fnc StringConversion)
RegisterStringConversion will register an automatic conversion of TypedString values with provided type to a native equivalent such as Int, Time, etc.
If fnc is nil, automatic conversion from selected type will be removed.
Types ¶
type BNode ¶
type BNode string
BNode is an RDF Blank Node (ex: _:name).
func RandomBlankNode ¶
func RandomBlankNode() BNode
RandomBlankNode returns a randomly generated Blank Node.
type BatchReader ¶
BatchReader is an interface for reading quads in batches.
ReadQuads reads at most len(buf) quads into buf. It returns number of quads that were read and an error. It returns an io.EOF if there is no more quads to read.
type BatchWriter ¶
BatchWriter is an interface for writing quads in batches.
WriteQuads returns a number of quads that where written and an error, if any.
type Bool ¶
type Bool bool
Bool is a native wrapper for bool type.
It uses NQuad notation similar to TypedString.
func (Bool) TypedString ¶
func (s Bool) TypedString() TypedString
type ByQuadString ¶
type ByQuadString []Quad
func (ByQuadString) Len ¶
func (o ByQuadString) Len() int
func (ByQuadString) Less ¶
func (o ByQuadString) Less(i, j int) bool
func (ByQuadString) Swap ¶
func (o ByQuadString) Swap(i, j int)
type ByValueString ¶
type ByValueString []Value
func (ByValueString) Len ¶
func (o ByValueString) Len() int
func (ByValueString) Less ¶
func (o ByValueString) Less(i, j int) bool
func (ByValueString) Swap ¶
func (o ByValueString) Swap(i, j int)
type Direction ¶
type Direction byte
Direction specifies an edge's type.
List of the valid directions of a quad.
type Float ¶
type Float float64
Float is a native wrapper for float64 type.
It uses NQuad notation similar to TypedString.
func (Float) TypedString ¶
func (s Float) TypedString() TypedString
type Format ¶
type Format struct { // Name is a short format name used as identifier for RegisterFormat. Name string // Ext is a list of file extensions, allowed for file format. Can be used to detect file format, given a path. Ext []string // Mime is a list of MIME (content) types, allowed for file format. Can be used in HTTP request/responses. Mime []string // Reader is a function for creating format reader, that reads serialized data from io.Reader. Reader func(io.Reader) ReadCloser // Writer is a function for creating format writer, that streams serialized data to io.Writer. Writer func(io.Writer) WriteCloser // Binary is set to true if format is not human-readable. Binary bool }
Format is a description for quad-file formats.
func FormatByExt ¶
FormatByExt returns a registered format by its file extension. Will return nil if format is not found.
func FormatByMime ¶
FormatByMime returns a registered format by its MIME type. Will return nil if format is not found.
func FormatByName ¶
FormatByName returns a registered format by its name. Will return nil if format is not found.
type Int ¶
type Int int64
Int is a native wrapper for int64 type.
It uses NQuad notation similar to TypedString.
func (Int) TypedString ¶
func (s Int) TypedString() TypedString
type LangString ¶
LangString is an RDF string with language (ex: "name"@lang).
func (LangString) Native ¶
func (s LangString) Native() interface{}
func (LangString) String ¶
func (s LangString) String() string
type Quad ¶
type Quad struct { Subject Value `json:"subject"` Predicate Value `json:"predicate"` Object Value `json:"object"` Label Value `json:"label,omitempty"` }
Our quad struct, used throughout.
func Make ¶
func Make(subject, predicate, object, label interface{}) (q Quad)
Make creates a quad with provided values.
func ReadAll ¶
ReadAll reads all quads from r until EOF. It returns a slice with all quads that were read and an error, if any.
func (Quad) MarshalJSON ¶
func (*Quad) UnmarshalJSON ¶
type Quads ¶
type Quads struct {
// contains filtered or unexported fields
}
type ReadCloser ¶
type Reader ¶
Reader is a minimal interface for quad readers. Used for quad deserializers and quad iterators.
ReadQuad reads next valid Quad. It returns io.EOF if no quads are left.
type Sequence ¶
type Sequence struct {
// contains filtered or unexported fields
}
Sequence is an object to generate a sequence of Blank Nodes.
type Skipper ¶
type Skipper interface {
SkipQuad() error
}
Skipper is an interface for quad reader that can skip quads efficiently without decoding them.
It returns io.EOF if no quads are left.
type StringConversion ¶
StringConversion is a function to convert string values with a specific IRI type to their native equivalents.
type Time ¶
Time is a native wrapper for time.Time type.
It uses NQuad notation similar to TypedString.
func (Time) TypedString ¶
func (s Time) TypedString() TypedString
type TypedString ¶
TypedString is an RDF value with type (ex: "name"^^<type>).
func (TypedString) Native ¶
func (s TypedString) Native() interface{}
func (TypedString) ParseValue ¶
func (s TypedString) ParseValue() (Value, error)
ParseValue will try to parse underlying string value using registered functions.
It will return unchanged value if suitable function is not available.
Error will be returned if the type was recognizes, but parsing failed.
func (TypedString) String ¶
func (s TypedString) String() string
type TypedStringer ¶
type TypedStringer interface {
TypedString() TypedString
}
type Value ¶
type Value interface { String() string // Native converts Value to a closest native Go type. // // If type has no analogs in Go, Native return an object itself. Native() interface{} }
Value is a type used by all quad directions.
func AsValue ¶
AsValue converts native type into closest Value representation. It returns false if type was not recognized.
func StringToValue ¶
StringToValue is a function to convert strings to typed quad values.
Warning: should not be used directly - will be deprecated.
type WriteCloser ¶
Directories ¶
Path | Synopsis |
---|---|
Package dot provides an encoder for DOT format (graphviz).
|
Package dot provides an encoder for DOT format (graphviz). |
Package gml provides an encoder for Graph Modeling Format
|
Package gml provides an encoder for Graph Modeling Format |
Package graphml provides an encoder for GraphML format
|
Package graphml provides an encoder for GraphML format |
Package json provides an encoder/decoder for JSON quad formats
|
Package json provides an encoder/decoder for JSON quad formats |
Package jsonld provides an encoder/decoder for JSON-LD quad format
|
Package jsonld provides an encoder/decoder for JSON-LD quad format |
Package nquads implements parsing the RDF 1.1 N-Quads like line-based syntax for RDF datasets.
|
Package nquads implements parsing the RDF 1.1 N-Quads like line-based syntax for RDF datasets. |
Package pquads implements Cayley-specific protobuf-based quads format.
|
Package pquads implements Cayley-specific protobuf-based quads format. |