Documentation ¶
Overview ¶
package rdf provides tools for the Resource Description Framework (RDF), see https://www.w3.org/RDF/.
Index ¶
- Constants
- Variables
- type BlankNode
- type Builder
- type Context
- type Graph
- func (g *Graph) Add(triples ...*Triple)
- func (g *Graph) AddTriple(s Subject, p Predicate, o Object)
- func (g *Graph) Get(s Subject) (rsc *Resource, ok bool)
- func (g *Graph) Len() int
- func (g *Graph) Namespaces() (ns []*domain.Namespace, err error)
- func (g *Graph) Resources() map[Subject]*Resource
- func (g *Graph) Stats() *GraphStats
- func (g *Graph) Triples() []*Triple
- func (g *Graph) TriplesOnce() ([]*Triple, error)
- type GraphIndex
- type GraphStats
- type IRI
- func (u IRI) Equal(other Term) bool
- func (u IRI) RawValue() (str string)
- func (u IRI) Split() (prefix, suffix string)
- func (u IRI) String() (str string)
- func (u IRI) Type() TermType
- func (u IRI) ValidAsObject()
- func (u IRI) ValidAsPredicate()
- func (u IRI) ValidAsSubject()
- func (u IRI) Validate() *validator.Validator
- type IRIBuilder
- type Literal
- func (l Literal) Equal(other Term) bool
- func (l Literal) HasImpliedDataType() bool
- func (l Literal) Lang() string
- func (l Literal) RawValue() string
- func (l Literal) String() string
- func (l Literal) Type() TermType
- func (l Literal) Typed() (interface{}, error)
- func (l Literal) ValidAsObject()
- func (l Literal) Validate() *validator.Validator
- type NamespaceManager
- type Object
- type Option
- type Parser
- type Predicate
- type Quad
- type Record
- type Resource
- func (r *Resource) Add(t *Triple)
- func (r *Resource) AddSimpleLiteral(predicateLabel, value string, options ...Option)
- func (r *Resource) HasErrors() bool
- func (r *Resource) Label() (Literal, bool)
- func (r *Resource) Predicates() map[Predicate]*resourcePredicate
- func (r *Resource) SortedPredicates() []*resourcePredicate
- func (r *Resource) Subject() Subject
- func (r *Resource) Triples() []*Triple
- func (r *Resource) Types() []IRI
- type Subject
- type Term
- type TermType
- type Triple
Constants ¶
const (
RDFType = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
)
Variables ¶
var ( // ErrEmptyIRI is returned when an IRI is empty ErrEmptyIRI = errors.New("empty IRI is not allowed") // ErrInvalidNamespaceLabel is returned when invalid characters are // part of the namespace label. ErrInvalidNamespaceLabel = errors.New("invalid namespace label") // ErrDisallowedCharacterInIRI is returned when an IRI contains // any of the disallowed characters: [\x00-\x20<>"{}|^`\] // This error is ofter wrapped in another error showing the offending character ErrDisallowedCharacterInIRI = errors.New("disallowed character") // ErrEmptyBlankNode is returned when a BlankNode is empty ErrEmptyBlankNode = errors.New("empty BlankNode is not allowed") // ErrInvalidLanguageTag is returned when a RDF Literal.lang tag is invalid ErrInvalidLanguageTag = errors.New("invalid language tag") // ErrInvalidDataType is returned when the RDF Literal.DataType IRI is malformed ErrInvalidDataType = errors.New("invalid Literal.DataType IRI") // ErrUnsupportedDataType is returned when the RDF Literal.DataType is not part // of SupportDataTypes. ErrUnsupportedDataType = errors.New("unsupported Literal.DataType IRI") // ErrInvalidLiteral is returned when the RDF Literal value is invalid ErrInvalidLiteral = errors.New("invalid literal value") )
var ( DC = &IRIBuilder{baseIRI: IRI{str: "http://purl.org/dc/elements/1.1/"}} DCAT = &IRIBuilder{baseIRI: IRI{str: "http://www.w3.org/ns/dcat#"}} DCTERMS = &IRIBuilder{baseIRI: IRI{str: "http://purl.org/dc/terms/"}} EDM = &IRIBuilder{baseIRI: IRI{str: "http://www.europeana.eu/schemas/edm/"}} FOAF = &IRIBuilder{baseIRI: IRI{str: "http://xmlns.com/foaf/0.1/"}} IIIF = &IRIBuilder{baseIRI: IRI{str: "http://iiif.io/api/image/2#"}} NAVE = &IRIBuilder{baseIRI: IRI{str: "http://schemas.delving.eu/nave/terms/"}} ODRL = &IRIBuilder{baseIRI: IRI{str: "http://www.w3.org/ns/odrl/2/"}} ORE = &IRIBuilder{baseIRI: IRI{str: "http://www.openarchives.org/ore/terms/"}} OWL = &IRIBuilder{baseIRI: IRI{str: "http://www.w3.org/2002/07/owl#"}} RDF = &IRIBuilder{baseIRI: IRI{str: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"}} RDFS = &IRIBuilder{baseIRI: IRI{str: "http://www.w3.org/2000/01/rdf-schema#"}} SCHEMA = &IRIBuilder{baseIRI: IRI{str: "http://schema.org/"}} SKOS = &IRIBuilder{baseIRI: IRI{str: "http://www.w3.org/2004/02/skos/core#"}} XML = &IRIBuilder{baseIRI: IRI{str: "http://www.w3.org/XML/1998/namespace"}} XSD = &IRIBuilder{baseIRI: IRI{str: "http://www.w3.org/2001/XMLSchema#"}} )
Shortcuts for the default support namespaces
var AnonNodeIDSize = 10
AnonNodeIdSize is the length of the generated identifier. The user can override this setting
var DateFormat = time.RFC3339
DateFormat defines the string representation of xsd:DateTime values. You can override it if you need another layout.
var ErrRecordNotFound = errors.New("record not found")
var IsA = Predicate(IRI{str: RDFType})
var ( // SupportDataTypes contains a list of valid DataType IRIs. // You can extend or set this list with additional XSD IRIs. SupportDataTypes = []IRI{ xsdString, xsdBoolean, xsdDecimal, xsdInteger, xsdDouble, xsdFloat, xsdDateTime, xsdByte, xsdInt, rdfLangString, xmlLiteral, admsIdentifier, edtf, wktLiteral, } )
The XML schema built-in datatypes (xsd): https://dvcs.w3.org/hg/rdf/raw-file/default/rdf-concepts/index.html#xsd-datatypes
Functions ¶
This section is empty.
Types ¶
type BlankNode ¶
type BlankNode struct {
// contains filtered or unexported fields
}
BlankNode represents a RDF blank node; an unqualified IRI with identified by a label.
func NewAnonNode ¶
func NewAnonNode() (bnode BlankNode)
NewAnonNode returns a new blank node with a pseudo-randomly generated ID.
func NewBlankNode ¶
NewBlank returns a new blank node with a given label. It returns an error only if the supplied label is blank.
Leading and trailing whitespace is trimmed from the id.
func (BlankNode) ValidAsObject ¶
func (b BlankNode) ValidAsObject()
ValidAsObject denotes that a Blank node is valid as a Triple's Object.
func (BlankNode) ValidAsSubject ¶
func (b BlankNode) ValidAsSubject()
ValidAsSubject denotes that a Blank node is valid as a Triple's Subject.
type Builder ¶
type Builder struct{}
func (*Builder) LiteralWithDataType ¶
func (*Builder) LiteralWithLang ¶
type Context ¶
type Context interface { Term ValidAsSubject() }
Context is the IRI namespace for the Quad
type Graph ¶
type Graph struct { BaseURI IRI UseIndex bool UseResource bool NamespaceManager NamespaceManager // contains filtered or unexported fields }
Graph is a collection of triples where the order of insertion is remembered
func (*Graph) Add ¶
AddTriple appends triple to the Graph triples Note: there is no deduplication. The same triple can be added multiple times
func (*Graph) Stats ¶
func (g *Graph) Stats() *GraphStats
func (*Graph) TriplesOnce ¶
TriplesOnce returns an list based on insertion order of the triples in Graph, an error is returned when triples have been Added after the previous read.
type GraphIndex ¶
type GraphStats ¶
type GraphStats struct { Languages int ObjectIRIs int ObjectLiterals int Predicates int Resources int Namespaces int Triples uint64 }
GraphStats returns counts for unique values in Graph
type IRI ¶
type IRI struct {
// contains filtered or unexported fields
}
IRI is an URI / IRI reference.
func NewIRI ¶
NewIRI returns a new IRI, or an error if it's not valid.
A valid IRI cannot be empty, or contain any of the disallowed characters: [\x00-\x20<>"{}|^`\].
func (IRI) Split ¶
Split returns the prefix and suffix of the IRI string, splitted at the first '/' or '#' character, in reverse order of the string.
When the IRI can't be split, both the prefix and suffix are returned empty
func (IRI) ValidAsObject ¶
func (u IRI) ValidAsObject()
ValidAsObject is a placeholder to verify that it can be used as an Object .
func (IRI) ValidAsPredicate ¶
func (u IRI) ValidAsPredicate()
ValidAsPredicate is a placeholder to verify that it can be used as a Predicate .
func (IRI) ValidAsSubject ¶
func (u IRI) ValidAsSubject()
ValidAsSubject is a placeholder to verify that it can be used as a Subject.
type IRIBuilder ¶
type IRIBuilder struct {
// contains filtered or unexported fields
}
IRIBuilder is used to easily create namespaces IRIs.
func NewIRIBuilder ¶
func NewIRIBuilder(base IRI) *IRIBuilder
NewIRIBuilder returns an IRIBuilder.
This base IRI is expected to be valid.
func (*IRIBuilder) IRI ¶
func (b *IRIBuilder) IRI(label string) (IRI, error)
IRI returns a namespaces IRI suffixed with the given label.
An error is returned when the label is invalid. Although this is extra error handling for each new IRI, we prefer the guarantees of correctness of the returned IRI.
type Literal ¶
type Literal struct { // The datatype of the Literal. DataType IRI // contains filtered or unexported fields }
Literal represents a RDF literal; a value with a datatype and (optionally) an associated language tag for strings.
func NewLiteral ¶
NewLiteral creates a RDF literal, it fails if the value string is not not well-formed.
The literal will have the datatype IRI xsd:String.
func NewLiteralInferred ¶
NewLiteralInferred returns a new Literal, or an error on invalid input. It tries to map the given Go values to a corresponding xsd datatype.
func NewLiteralWithLang ¶
NewLiteralWithLang creates a RDF literal with a given language tag, or fails if the language tag is not well-formed.
The literal will have the datatype IRI xsd:String.
func NewLiteralWithType ¶
NewLiteralWithType returns a literal with the given datatype, or fails if the DataType IRI is malformed.
func (Literal) HasImpliedDataType ¶
func (Literal) Typed ¶
Typed tries to parse the Literal's value into a Go type, according to the the DataType.
func (Literal) ValidAsObject ¶
func (l Literal) ValidAsObject()
ValidAsObject denotes that a Literal is valid as a Triple's Object.
type NamespaceManager ¶
type NamespaceManager interface { GetWithPrefix(prefix string) (ns *domain.Namespace, err error) GetWithBase(base string) (ns *domain.Namespace, err error) }
var DefaultNamespaceManager NamespaceManager
DefaultNamespaceManager can be set at package level to serve as a default when no NamespaceManager is set on a Graph.
The namespace manager is used by Resource and some RDF Encode/Decoder packages.
type Object ¶
type Object interface { Term ValidAsObject() }
Object interface distiguishes which Terms are valid as a Object of a Triple.
type Option ¶
func WithDataType ¶
WithDataType is an Option to set a DataType on AddSimpleLiteral()
func WithLanguage ¶
WithLanguage is an Option to set a Language on AddSimpleLiteral()
type Parser ¶
Parser is an interface for parsing RDF in io.Reader and storing it into the Graph.
This should be implemement by RDF parsing packages
type Predicate ¶
type Predicate interface { Term ValidAsPredicate() }
Predicate interface distiguishes which Terms are valid as a Predicate of a Triple.
type Quad ¶
type Quad struct { *Triple // contains filtered or unexported fields }
Quad represents a RDF Quad; a Triple plus the context in which it occurs.
type Record ¶
type Record struct { ID domain.HubID CreatedAt time.Time ModifiedAt time.Time Hash string Deleted bool Version int32 GraphData []byte GraphURI string MimeType string }
Record is the primary grouping of triples to represent a search record. This is a replacement of the old fragments.FragmentGraph. lod.RecordStore interface interacts as a storage layer for these records
TODO(kiivihal): implement index record
type Resource ¶
type Resource struct { PredicateURIBase *IRIBuilder `json:"-"` // contains filtered or unexported fields }
Resource contains all the predicates linked to a Subject
func NewResource ¶
func (*Resource) AddSimpleLiteral ¶
func (*Resource) Predicates ¶
func (*Resource) SortedPredicates ¶
func (r *Resource) SortedPredicates() []*resourcePredicate
type Subject ¶
type Subject interface { Term ValidAsSubject() }
Subject interface distiguishes which Terms are valid as a Subject of a Triple.
type Term ¶
type Term interface { // Equal returns whether this term is equal to another. Equal(Term) bool // RawValue returns the raw value of this term. RawValue() string // String returns the NTriples representation of this term. String() string // Type returns the Term type. Type() TermType // Validate returns is the Term is valid Validate() *validator.Validator }
A Term is the value of a subject, predicate or object, i.e. a IRI reference, BlankNode or Literal.
To work with the underlying concrete type, use a type assertion or a type switch.
t, ok := term.(IRI)
type TermType ¶
type TermType int
TermType describes the type of RDF term: Blank node, IRI or Literal