rdf

package
v1.7.0-gts Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdSpec                = "@id"
	IdActivityStreamsSpec = "id"
	ContainerSpec         = "@container"
	IndexSpec             = "@index"
)
View Source
const (
	JSON_LD_CONTEXT = "@context"
	JSON_LD_TYPE    = "@type"
	JSON_LD_TYPE_AS = "type"
)
View Source
const (
	ALIAS_DELIMITER = ":"
	HTTP            = "http"
	HTTPS           = "https"
	ID              = "@id"
)

Variables

This section is empty.

Functions

func DeserializeValueFunction

func DeserializeValueFunction(pkg, valueName string,
	concreteType jen.Code,
	impl []jen.Code) *codegen.Function

DeserializeValueFunction is a helper for creating a value's Deserialize function.

func IsKeyApplicable

func IsKeyApplicable(key, spec, alias, name string) bool

IsKeyApplicable returns true if the key has a spec or alias prefix and the property is equal to the desired name.

If 'alias' is an empty string, it is ignored.

func LessFunction

func LessFunction(pkg, valueName string,
	concreteType jen.Code,
	impl []jen.Code) *codegen.Function

LessFunction is a helper for creating a value's Less function.

func SerializeValueFunction

func SerializeValueFunction(pkg, valueName string,
	concreteType jen.Code,
	impl []jen.Code) *codegen.Function

SerializeValueFunction is a helper for creating a value's Serialize function.

func SplitAlias

func SplitAlias(s string) []string

SplitAlias splits a possibly-aliased string, without splitting on the colon if it is part of the http or https spec.

func ToHttpAndHttps

func ToHttpAndHttps(s string) (http, https string, err error)

ToHttpAndHttps converts a URI to both its http and https versions.

Types

type AliasedDelegate

type AliasedDelegate struct {
	Spec     string
	Alias    string
	Name     string
	Delegate RDFNode
}

AliasedDelegate will call the delegated RDFNode if the passed in keys conform to either the spec or alias.

func (*AliasedDelegate) Apply

func (a *AliasedDelegate) Apply(key string, value interface{}, ctx *ParsingContext) (bool, error)

Apply calls the Delegate's Apply if the key conforms to the Spec or Alias.

func (*AliasedDelegate) Enter

func (a *AliasedDelegate) Enter(key string, ctx *ParsingContext) (bool, error)

Enter calls the Delegate's Enter if the key conforms to the Spec or Alias.

func (*AliasedDelegate) Exit

func (a *AliasedDelegate) Exit(key string, ctx *ParsingContext) (bool, error)

Exit calls the Delegate's Exit if the key conforms to the Spec or Alias.

type ContainerLD

type ContainerLD struct {
	ContainsNode RDFNode
}

ContainerLD is an RDFNode that delegates to an RDFNode but only at this next level.

func (*ContainerLD) Apply

func (c *ContainerLD) Apply(key string, value interface{}, ctx *ParsingContext) (bool, error)

Apply does nothing.

func (*ContainerLD) Enter

func (c *ContainerLD) Enter(key string, ctx *ParsingContext) (bool, error)

Enter sets OnlyApplyThisNodeNextLevel on the ParsingContext.

Returns an error if this is the second time Enter is called in a row.

func (*ContainerLD) Exit

func (c *ContainerLD) Exit(key string, ctx *ParsingContext) (bool, error)

Exit clears OnlyApplyThisNodeNextLevel on the ParsingContext.

Returns an error if this is the second time Exit is called in a row.

type ExampleAdder

type ExampleAdder interface {
	AddExample(*VocabularyExample)
}

ExampleAdder is a utility interface for the rdf Vocabulary types.

type IndexLD

type IndexLD struct{}

IndexLD does nothing.

It could try to manage human-defined indices, but the machine doesn't care.

func (*IndexLD) Apply

func (i *IndexLD) Apply(key string, value interface{}, ctx *ParsingContext) (bool, error)

Apply does nothing.

func (*IndexLD) Enter

func (i *IndexLD) Enter(key string, ctx *ParsingContext) (bool, error)

Enter does nothing.

func (*IndexLD) Exit

func (i *IndexLD) Exit(key string, ctx *ParsingContext) (bool, error)

Exit does nothing.

type JSONLD

type JSONLD map[string]interface{}

JSONLD is an alias for the generic map of keys to interfaces, presumably parsed from a JSON-encoded context definition file.

type NameGetter

type NameGetter interface {
	GetName() string
}

NameGetter is a utility interface for the rdf Vocabulary types.

type NameSetter

type NameSetter interface {
	SetName(string)
}

NameSetter is a utility interface for the rdf Vocabulary types.

type NotesSetter

type NotesSetter interface {
	SetNotes(string)
}

NotesSetter is a utility interface for the rdf Vocabulary types.

type Ontology

type Ontology interface {
	// SpecURI refers to the URI location of this ontology.
	SpecURI() string

	// Load loads the entire ontology.
	Load() ([]RDFNode, error)
	// LoadAsAlias loads the entire ontology with a specific alias.
	LoadAsAlias(s string) ([]RDFNode, error)
	// LoadSpecificAsAlias loads a specific element of the ontology by
	// being able to handle the specific alias as its name instead.
	LoadSpecificAsAlias(alias, name string) ([]RDFNode, error)
	// LoadElement loads a specific element of the ontology based on the
	// object definition.
	LoadElement(name string, payload map[string]interface{}) ([]RDFNode, error)

	// GetByName returns an RDFNode associated with the given name. Note
	// that the name may either be fully-qualified (in the case it was not
	// aliased) or it may be just the element name (in the case it was
	// aliased).
	GetByName(name string) (RDFNode, error)
}

Ontology returns different RDF "actions" or "handlers" that are able to interpret the schema definitions as actions upon a set of data, specific for this ontology.

type ParsedVocabulary

type ParsedVocabulary struct {
	Vocab      Vocabulary
	References map[string]*Vocabulary
	Order      []string
}

ParsedVocabulary is the internal data structure produced after parsing the definition of an ActivityStream vocabulary. It is the intermediate understanding of the specification in the context of certain ontologies.

At the end of parsing, the ParsedVocabulary is not guaranteed to be semantically valid, just that the parser resolved all important ontological details.

Note that the Order field contains the order in which parsed specs were understood and resolved. Kinds added as references (such as XML, Schema.org, or rdfs types) are not included in Order. It is expected that the last element of Order must be the vocabulary in Vocab.

func ParseVocabularies

func ParseVocabularies(registry *RDFRegistry, inputs []JSONLD) (vocabulary *ParsedVocabulary, err error)

ParseVocabularies parses the provided inputs in order as an ActivityStreams context that specifies one or more extension vocabularies.

func (ParsedVocabulary) Clone

Clone creates a copy of this ParsedVocabulary. Note that the cloned vocabulary does not copy References, so the original and clone both have pointers to the same referenced vocabularies.

func (*ParsedVocabulary) GetReference

func (p *ParsedVocabulary) GetReference(uri string) (*Vocabulary, error)

GetReference looks up a reference based on its URI.

func (ParsedVocabulary) Size

func (p ParsedVocabulary) Size() int

Size returns the number of types, properties, and values in the parsed vocabulary.

func (ParsedVocabulary) String

func (p ParsedVocabulary) String() string

String returns a printable version of this ParsedVocabulary for debugging.

type ParsingContext

type ParsingContext struct {
	// Result contains the final ParsedVocabulary from a file.
	Result *ParsedVocabulary
	// Current item to operate upon. A call to Push or Pop will overwrite
	// this field.
	Current interface{}
	// Name of the Current item. A call to Push or Pop will modify this
	// field.
	Name string
	// The Stack of Types, Properties, References, Examples, and other
	// items being analyzed. A call to Push or Pop will modify this field.
	//
	// Do not use directly, instead use Push and Pop.
	Stack []interface{}
	// Applies the node only for the next level of processing.
	//
	// Do not touch, instead use the accessor methods.
	OnlyApplyThisNodeNextLevel RDFNode
	// OnlyApplied keeps track if OnlyApplyThisNodeNextLevel has applied
	// once.
	OnlyApplied bool
	// Applies the node once, for the rest of the data. This skips the
	// recursive parsing, and the node's Apply is given an empty string
	// for a key.
	//
	// Do not touch, instead use the accessor methods.
	OnlyApplyThisNode RDFNode
}

ParsingContext contains the results of the parsing as well as scratch space required for RDFNodes to be able to statefully apply changes.

func (*ParsingContext) GetNextNodes

func (p *ParsingContext) GetNextNodes(n []RDFNode) (r []RDFNode, clearFn func())

GetNextNodes is given the list of nodes a parent process believes should be applied, and returns the list of nodes that actually should be used.

If there is node that should only apply or should only apply at the next level (and hasn't yet), then the passed in list will not match the resulting list.

func (*ParsingContext) GetResultReferenceWithDefaults

func (p *ParsingContext) GetResultReferenceWithDefaults(spec, name string) (*Vocabulary, error)

GetResultReferenceWithDefaults will fetch the spec and set the Vocabulary Name and URI values as well. Helper function when getting a reference in order to populate known value types.

func (*ParsingContext) IsReset

func (p *ParsingContext) IsReset() bool

IsReset determines if the Context's Current is nil and Name is empty. Note

func (*ParsingContext) Pop

func (p *ParsingContext) Pop()

Pop puts the top item on the Stack into Current, and sets Name as appropriate.

func (*ParsingContext) Push

func (p *ParsingContext) Push()

Push puts the Current onto the Stack.

func (*ParsingContext) Reset

func (p *ParsingContext) Reset()

Reset sets Current to nil and Name to empty string.

func (*ParsingContext) ResetOnlyAppliedThisNodeNextLevel

func (p *ParsingContext) ResetOnlyAppliedThisNodeNextLevel()

ResetOnlyAppliedThisNodeNextLevel clears the node that should have been applied for the next level of depth only.

func (*ParsingContext) ResetOnlyApplyThisNode

func (p *ParsingContext) ResetOnlyApplyThisNode()

ResetOnlyApplyThisNode clears the only node to apply, if set.

func (*ParsingContext) SetOnlyApplyThisNode

func (p *ParsingContext) SetOnlyApplyThisNode(n RDFNode)

SetOnlyApplyThisNode sets the provided node to be the only one applied until ResetOnlyApplyThisNode is called.

func (*ParsingContext) SetOnlyApplyThisNodeNextLevel

func (p *ParsingContext) SetOnlyApplyThisNodeNextLevel(n RDFNode)

SetOnlyApplyThisNodeNExtLevel will apply the next node only for the next level.

type RDFNode

type RDFNode interface {
	// Enter is called when the RDFNode is a label for an array of values or
	// a key within a JSON object, and the parser is about to examine its
	// value(s). Exit is guaranteed to be called afterwards.
	Enter(key string, ctx *ParsingContext) (bool, error)
	// Exit is called after the parser examines the node's value(s).
	Exit(key string, ctx *ParsingContext) (bool, error)
	// Apply is called by the parser on nodes when they appear as values.
	Apply(key string, value interface{}, ctx *ParsingContext) (bool, error)
}

RDFNode is able to operate on a specific key if it applies towards its ontology (determined at creation time). It applies the value in its own specific implementation on the context.

type RDFOntology

type RDFOntology struct {
	Package string
	// contains filtered or unexported fields
}

RDFOntology is an Ontology for the RDF namespace.

func (*RDFOntology) GetByName

func (o *RDFOntology) GetByName(name string) (RDFNode, error)

GetByName returns a raw, unguarded node by name.

func (*RDFOntology) Load

func (o *RDFOntology) Load() ([]RDFNode, error)

Load loads the ontology with no alias set.

func (*RDFOntology) LoadAsAlias

func (o *RDFOntology) LoadAsAlias(s string) ([]RDFNode, error)

LoadAsAlias loads the ontology with an alias.

func (*RDFOntology) LoadElement

func (o *RDFOntology) LoadElement(name string, payload map[string]interface{}) ([]RDFNode, error)

LoadElement does nothing.

func (*RDFOntology) LoadSpecificAsAlias

func (o *RDFOntology) LoadSpecificAsAlias(alias, name string) ([]RDFNode, error)

LoadSpecificAsAlias loads a specific RDFNode with the given alias.

func (*RDFOntology) SpecURI

func (o *RDFOntology) SpecURI() string

SpecURI returns the RDF URI spec.

type RDFRegistry

type RDFRegistry struct {
	// contains filtered or unexported fields
}

RDFRegistry manages the different ontologies needed to determine the generated Go code.

func NewRDFRegistry

func NewRDFRegistry() *RDFRegistry

NewRDFRegistry returns a new RDFRegistry.

func (*RDFRegistry) AddOntology

func (r *RDFRegistry) AddOntology(o Ontology) error

AddOntology adds an RDF ontology to the registry.

func (*RDFRegistry) ResolveAlias

func (r *RDFRegistry) ResolveAlias(alias string) (url string, e error)

resolveAlias turns an alias into its full qualifier for the ontology.

If passed in a valid URI, it returns what was passed in.

type ReferenceOntology

type ReferenceOntology struct {
	// contains filtered or unexported fields
}

ReferenceOntology wraps a previously-parsed spec so it can be made known to the registry.

func (*ReferenceOntology) GetByName

func (r *ReferenceOntology) GetByName(name string) (RDFNode, error)

GetByName returns a raw, unguarded node by name.

Values cannot be loaded because their serialization and deserialization types are not known at runtime if not embedded in the go-fed tool. If the error is generated when running the tool, then file a bug so that the tool can properly "know" about this particular value and how to serialize and deserialize it properly.

func (*ReferenceOntology) Load

func (r *ReferenceOntology) Load() ([]RDFNode, error)

Load loads the ontology without an alias.

func (*ReferenceOntology) LoadAsAlias

func (r *ReferenceOntology) LoadAsAlias(s string) ([]RDFNode, error)

LoadAsAlias loads the vocabulary ontology with an alias.

Values cannot be loaded because their serialization and deserialization types are not known at runtime if not embedded in the go-fed tool. If the error is generated when running the tool, then file a bug so that the tool can properly "know" about this particular value and how to serialize and deserialize it properly.

func (*ReferenceOntology) LoadElement

func (r *ReferenceOntology) LoadElement(name string, payload map[string]interface{}) ([]RDFNode, error)

LoadElement does nothing.

func (*ReferenceOntology) LoadSpecificAsAlias

func (r *ReferenceOntology) LoadSpecificAsAlias(alias, name string) ([]RDFNode, error)

LoadSpecificAsAlias loads a specific RDFNode with the given alias.

Values cannot be loaded because their serialization and deserialization types are not known at runtime if not embedded in the go-fed tool. If the error is generated when running the tool, then file a bug so that the tool can properly "know" about this particular value and how to serialize and deserialize it properly.

func (*ReferenceOntology) SpecURI

func (r *ReferenceOntology) SpecURI() string

SpecURI returns the URI for this specification

type URISetter

type URISetter interface {
	SetURI(string) error
}

URISetter is a utility interface for the rdf Vocabulary types.

type Vocabulary

type Vocabulary struct {
	Name           string
	WellKnownAlias string // Hack.
	URI            *url.URL
	Types          map[string]VocabularyType
	Properties     map[string]VocabularyProperty
	Values         map[string]VocabularyValue
	Registry       *RDFRegistry
}

Vocabulary contains the type, property, and value definitions for a single ActivityStreams or extension vocabulary.

func (Vocabulary) GetName

func (v Vocabulary) GetName() string

GetName returns the vocabulary's name.

func (Vocabulary) GetWellKnownAlias

func (v Vocabulary) GetWellKnownAlias() string

GetWellKnownAlias returns the vocabulary's name.

func (*Vocabulary) SetName

func (v *Vocabulary) SetName(s string)

SetName sets the vocabulary's name.

func (*Vocabulary) SetProperty

func (v *Vocabulary) SetProperty(name string, a *VocabularyProperty) error

SetProperty sets a property keyed by its name. Returns an error if a property is already set for that name.

func (*Vocabulary) SetType

func (v *Vocabulary) SetType(name string, a *VocabularyType) error

SetType sets a type keyed by its name. Returns an error if a type is already set for that name.

func (*Vocabulary) SetURI

func (v *Vocabulary) SetURI(s string) error

SetURI sets the value's URI.

func (*Vocabulary) SetValue

func (v *Vocabulary) SetValue(name string, a *VocabularyValue) error

SetValue sets a value keyed by its name. Returns an error if the value is already set for that name.

func (Vocabulary) Size

func (v Vocabulary) Size() int

Size returns the number of types, properties, and values in this vocabulary.

func (Vocabulary) String

func (v Vocabulary) String() string

String returns a printable version of this Vocabulary for debugging.

type VocabularyExample

type VocabularyExample struct {
	Name    string
	URI     *url.URL
	Example interface{}
}

VocabularyExample documents an Example for an ActivityStream type or property in the vocabulary.

func (VocabularyExample) GetName

func (v VocabularyExample) GetName() string

GetName returns the name of this example.

func (*VocabularyExample) SetName

func (v *VocabularyExample) SetName(s string)

SetName sets the name on this example.

func (*VocabularyExample) SetURI

func (v *VocabularyExample) SetURI(s string) error

SetURI sets the URI of this example, returning an error if it cannot be parsed.

func (VocabularyExample) String

func (v VocabularyExample) String() string

String returns a printable string used for debugging.

type VocabularyProperty

type VocabularyProperty struct {
	Name           string
	URI            *url.URL
	Notes          string
	Domain         []VocabularyReference
	Range          []VocabularyReference
	DoesNotApplyTo []VocabularyReference
	Examples       []VocabularyExample
	// SubpropertyOf is ignorable as long as data is set up correctly
	SubpropertyOf      VocabularyReference // Must be a VocabularyProperty
	Functional         bool
	NaturalLanguageMap bool
}

VocabularyProperty represents a single ActivityStream property type in a vocabulary.

func (*VocabularyProperty) AddExample

func (v *VocabularyProperty) AddExample(e *VocabularyExample)

AddExample adds an example for this property.

func (VocabularyProperty) GetName

func (v VocabularyProperty) GetName() string

GetName returns the name of this property.

func (VocabularyProperty) PropertyName

func (v VocabularyProperty) PropertyName() string

PropertyName returns the name of this property.

Used to satisfy an interface.

func (*VocabularyProperty) SetName

func (v *VocabularyProperty) SetName(s string)

SetName sets the name on this property.

func (*VocabularyProperty) SetNotes

func (v *VocabularyProperty) SetNotes(s string)

SetNotes sets notes on this Property.

func (*VocabularyProperty) SetURI

func (v *VocabularyProperty) SetURI(s string) error

SetURI sets the URI for this property, returning an error if it cannot be parsed.

func (VocabularyProperty) String

func (v VocabularyProperty) String() string

String returns a printable version of this property for debugging.

type VocabularyReference

type VocabularyReference struct {
	Name  string
	URI   *url.URL
	Vocab string // If present, must match key in ParsedVocabulary.References
}

VocabularyReference refers to another Vocabulary reference, either a VocabularyType, VocabularyValue, or a VocabularyProperty. It may refer to another Vocabulary's type or property entirely.

func (VocabularyReference) GetName

func (v VocabularyReference) GetName() string

GetName returns the name of this reference.

func (*VocabularyReference) SetName

func (v *VocabularyReference) SetName(s string)

SetName sets the name of this reference.

func (*VocabularyReference) SetURI

func (v *VocabularyReference) SetURI(s string) error

SetURI sets the URI for this reference. Returns an error if the URI cannot be parsed.

func (VocabularyReference) String

func (v VocabularyReference) String() string

String returns a printable string for this reference, used for debugging.

type VocabularyType

type VocabularyType struct {
	Name              string
	Typeless          bool // Hack
	URI               *url.URL
	Notes             string
	DisjointWith      []VocabularyReference
	Extends           []VocabularyReference
	Examples          []VocabularyExample
	Properties        []VocabularyReference
	WithoutProperties []VocabularyReference
}

VocabularyType represents a single ActivityStream type in a vocabulary.

func (*VocabularyType) AddExample

func (v *VocabularyType) AddExample(e *VocabularyExample)

AddExample adds an example on this type.

func (VocabularyType) GetName

func (v VocabularyType) GetName() string

SetName returns the name of this type.

func (*VocabularyType) IsTypeless

func (v *VocabularyType) IsTypeless() bool

IsTypeless determines if this type is, in fact, typeless

func (*VocabularyType) SetName

func (v *VocabularyType) SetName(s string)

SetName sets the name of this type.

func (*VocabularyType) SetNotes

func (v *VocabularyType) SetNotes(s string)

SetNotes sets the notes on this type.

func (*VocabularyType) SetURI

func (v *VocabularyType) SetURI(s string) error

SetURI sets the URI of this type, returning an error if it cannot parse the URI.

func (VocabularyType) String

func (v VocabularyType) String() string

String returns a printable version of this type, for debugging.

func (VocabularyType) TypeName

func (v VocabularyType) TypeName() string

TypeName returns the name of this type.

Used to satisfy an interface.

type VocabularyValue

type VocabularyValue struct {
	Name           string
	URI            *url.URL
	DefinitionType *jen.Statement
	Zero           string
	IsNilable      bool
	IsURI          bool
	SerializeFn    *codegen.Function
	DeserializeFn  *codegen.Function
	LessFn         *codegen.Function
}

VocabularyValue represents a value type that properties can take on.

func (VocabularyValue) GetName

func (v VocabularyValue) GetName() string

GetName returns the value's name.

func (*VocabularyValue) SetName

func (v *VocabularyValue) SetName(s string)

SetName sets the value's name.

func (*VocabularyValue) SetURI

func (v *VocabularyValue) SetURI(s string) error

SetURI sets the value's URI.

func (VocabularyValue) String

func (v VocabularyValue) String() string

String returns a printable version of this value for debugging.

Directories

Path Synopsis
Package RFC contains ontology values that are defined in RFCs, BCPs, and other miscellaneous standards.
Package RFC contains ontology values that are defined in RFCs, BCPs, and other miscellaneous standards.

Jump to

Keyboard shortcuts

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