quad

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package quad defines quad and triple handling.

Index

Constants

View Source
const HashSize = sha1.Size

HashSize is a size of the slice, returned by HashOf.

Variables

View Source
var (
	ErrInvalid    = errors.New("invalid N-Quad")
	ErrIncomplete = errors.New("incomplete N-Quad")
)

Functions

func HashOf added in v0.6.0

func HashOf(v Value) []byte

HashOf calculates a hash of value v.

func HashTo added in v0.6.0

func HashTo(v Value, p []byte)

HashTo calculates a hash of value v, storing it in a slice p.

func NativeOf added in v0.6.0

func NativeOf(v Value) interface{}

NativeOf safely call v.Native, returning nil in case of nil Value.

func RegisterStringConversion added in v0.6.0

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.

func StringOf added in v0.6.0

func StringOf(v Value) string

StringOf safely call v.String, returning empty string in case of nil Value.

Types

type BNode added in v0.6.0

type BNode string

BNode is an RDF Blank Node (ex: _:name).

func (BNode) Native added in v0.6.0

func (s BNode) Native() interface{}

func (BNode) String added in v0.6.0

func (s BNode) String() string

type Bool added in v0.6.0

type Bool bool

Bool is a native wrapper for bool type.

It uses NQuad notation similar to TypedString.

func (Bool) Native added in v0.6.0

func (s Bool) Native() interface{}

func (Bool) String added in v0.6.0

func (s Bool) String() string

type ByQuadString added in v0.6.0

type ByQuadString []Quad

func (ByQuadString) Len added in v0.6.0

func (o ByQuadString) Len() int

func (ByQuadString) Less added in v0.6.0

func (o ByQuadString) Less(i, j int) bool

func (ByQuadString) Swap added in v0.6.0

func (o ByQuadString) Swap(i, j int)

type ByValueString added in v0.6.0

type ByValueString []Value

func (ByValueString) Len added in v0.6.0

func (o ByValueString) Len() int

func (ByValueString) Less added in v0.6.0

func (o ByValueString) Less(i, j int) bool

func (ByValueString) Swap added in v0.6.0

func (o ByValueString) Swap(i, j int)

type Direction

type Direction byte

Direction specifies an edge's type.

const (
	Any Direction = iota
	Subject
	Predicate
	Object
	Label
)

List of the valid directions of a quad.

func (Direction) Prefix

func (d Direction) Prefix() byte

func (Direction) String

func (d Direction) String() string

type Equaler added in v0.6.0

type Equaler interface {
	Equal(v Value) bool
}

Equaler interface is implemented by values, that needs a special equality check.

type Float added in v0.6.0

type Float float64

Float is a native wrapper for float64 type.

It uses NQuad notation similar to TypedString.

func (Float) Native added in v0.6.0

func (s Float) Native() interface{}

func (Float) String added in v0.6.0

func (s Float) String() string

type IRI added in v0.6.0

type IRI string

IRI is an RDF Internationalized Resource Identifier (ex: <name>).

func (IRI) Native added in v0.6.0

func (s IRI) Native() interface{}

func (IRI) String added in v0.6.0

func (s IRI) String() string

type Int added in v0.6.0

type Int int64

Int is a native wrapper for int64 type.

It uses NQuad notation similar to TypedString.

func (Int) Native added in v0.6.0

func (s Int) Native() interface{}

func (Int) String added in v0.6.0

func (s Int) String() string

type LangString added in v0.6.0

type LangString struct {
	Value String
	Lang  string
}

LangString is an RDF string with language (ex: "name"@lang).

func (LangString) Native added in v0.6.0

func (s LangString) Native() interface{}

func (LangString) String added in v0.6.0

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 added in v0.6.0

func Make(subject, predicate, object, label interface{}) (q Quad)

Make creates a quad with provided values.

func MakeRaw added in v0.6.0

func MakeRaw(subject, predicate, object, label string) (q Quad)

MakeRaw creates a quad with provided raw values (nquads-escaped).

func (Quad) Get

func (q Quad) Get(d Direction) Value

Per-field accessor for quads.

func (Quad) GetString added in v0.6.0

func (q Quad) GetString(d Direction) string

Per-field accessor for quads that returns strings instead of values.

func (Quad) IsValid

func (q Quad) IsValid() bool

func (Quad) MarshalJSON added in v0.6.0

func (q Quad) MarshalJSON() ([]byte, error)

func (Quad) NQuad added in v0.4.1

func (q Quad) NQuad() string

Prints a quad in N-Quad format.

func (Quad) String

func (q Quad) String() string

Pretty-prints a quad.

func (*Quad) UnmarshalJSON added in v0.6.0

func (q *Quad) UnmarshalJSON(data []byte) error

type Raw added in v0.6.0

type Raw string

Raw is a Turtle/NQuads-encoded value.

func (Raw) Native added in v0.6.0

func (s Raw) Native() interface{}

func (Raw) String added in v0.6.0

func (s Raw) String() string

type String added in v0.6.0

type String string

String is an RDF string value (ex: "name").

func (String) Native added in v0.6.0

func (s String) Native() interface{}

func (String) String added in v0.6.0

func (s String) String() string

type StringConversion added in v0.6.0

type StringConversion func(string) (Value, error)

StringConversion is a function to convert string values with a specific IRI type to their native equivalents.

type Time added in v0.6.0

type Time time.Time

Time is a native wrapper for time.Time type.

It uses NQuad notation similar to TypedString.

func (Time) Equal added in v0.6.0

func (s Time) Equal(v Value) bool

func (Time) Native added in v0.6.0

func (s Time) Native() interface{}

func (Time) String added in v0.6.0

func (s Time) String() string

type TypedString added in v0.6.0

type TypedString struct {
	Value String
	Type  IRI
}

TypedString is an RDF value with type (ex: "name"^^<type>).

func (TypedString) Native added in v0.6.0

func (s TypedString) Native() interface{}

func (TypedString) ParseValue added in v0.6.0

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 added in v0.6.0

func (s TypedString) String() string

type Unmarshaler

type Unmarshaler interface {
	Unmarshal() (Quad, error)
}

type Value added in v0.6.0

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 added in v0.6.0

func AsValue(v interface{}) (out Value, ok bool)

AsValue converts native type into closest Value representation. It returns false if type was not recognized.

func StringToValue added in v0.6.0

func StringToValue(v string) Value

StringToValue is a function to convert strings to typed quad values.

Warning: should not be used directly - will be deprecated.

Directories

Path Synopsis
Package cquads implements parsing N-Quads like line-based syntax for RDF datasets.
Package cquads implements parsing N-Quads like line-based syntax for RDF datasets.
Package nquads implements parsing the RDF 1.1 N-Quads line-based syntax for RDF datasets.
Package nquads implements parsing the RDF 1.1 N-Quads line-based syntax for RDF datasets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL