Documentation ¶
Overview ¶
Package namespace provides support for managing namespaces for RDF or XML URIs.
Index ¶
Examples ¶
Constants ¶
const ( ErrNameSpaceNotFound = Error("namespace not found") ErrNameSpaceDuplicateEntry = Error("prefix and base stored in different entries") )
Namespace errors.
Variables ¶
This section is empty.
Functions ¶
func SplitURI ¶
SplitURI takes a given URI and splits it into a base-URI and a localname. When the URI can't be split, the full URI is returned as the label with an empty base.
Example ¶
package main import ( "fmt" "github.com/delving/hub3/hub3/namespace" ) func main() { fmt.Println(namespace.SplitURI("http://purl.org/dc/elements/1.1/title")) }
Output: http://purl.org/dc/elements/1.1/ title
Types ¶
type NameSpace ¶
type NameSpace struct { // UUID is the unique identifier of a namespace UUID string `json:"uuid"` // Base is the default base-URI for a namespace Base string `json:"base"` // Prefix is the default short version that identifies the base-URI Prefix string `json:"prefix"` // BaseAlt are alternative base-URI for the same prefix. // Sometimes historically the base-URIs for a namespace changes and we still // have to correctly resolve both. BaseAlt []string `json:"baseAlt"` // PrefixAlt are altenative prefixes for the default base URI. // Different content-providers and organisations have at time selected alternative // prefixes for the same base URI. We need to support both entry entry-points. PrefixAlt []string `json:"prefixAlt"` // Schema is an URL to the RDFS or OWL definition of namespace Schema string `json:"schema"` }
NameSpace is a container for URI conversions for RDF- and XML-namespaces.
func (*NameSpace) AddBase ¶
AddBase adds a base-URI to the list of base alternatives.
When the base-URI is already present in BaseAlt no error is thrown.
func (*NameSpace) AddPrefix ¶
AddPrefix adds a prefix to the list of prefix alternatives.
When the prefix is already present in PrefixAlt no error is thrown.
func (NameSpace) BaseURIs ¶
BaseURIs returns all namespace base-URIs linked to this NameSpace. This includes the default Base and all alternative base-URIs.
func (*NameSpace) GetID ¶
GetID returns a string representation of a UUID. When no UUID is sit, this function will generate it and update the NameSpace.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides functionality to query and persist namespaces.
func NewService ¶
func NewService(options ...ServiceOptionFunc) (*Service, error)
NewService creates a new client to work with namespaces.
NewService, by default, is meant to be long-lived and shared across your application.
The caller can configure the new service by passing configuration options to the func.
Example:
service, err := elastic.NewService( namespace.WithDefaults(), )
If no Store is configured, Service uses a in-memory store by default.
An error is also returned when some configuration option is invalid.
func (*Service) Add ¶
Add adds the prefix and base-URI to the namespace service. When either the prefix or the base-URI is already present in the service the unknown is stored as an alternative. If neither is present a new NameSpace is created.
func (*Service) SearchLabel ¶
SearchLabel returns the URI in a short namespaced form. The string is formatted as namespace prefix and label joined with an underscore, e.g. "dc_title".
The underscore is used instead of the more common colon because it mainly used as the search field in Lucene-based search engine, where it would conflict with the separator between the query-field and value.
func (*Service) Set ¶
Set sets the default prefix and base-URI for a namespace. When the namespace is already present it will be overwritten. When the NameSpace contains an unknown prefix and base-URI pair but one of them is found in the NameSpace service, the current default is stored in PrefixAlt or BaseAlt and the new default set.
type ServiceOptionFunc ¶
ServiceOptionFunc is a function that configures a Service. It is used in NewService.
func SetStore ¶
func SetStore(store Store) ServiceOptionFunc
SetStore sets the persistence store for the namespace.Service.
func WithDefaults ¶
func WithDefaults() ServiceOptionFunc
WithDefaults enables the namespace.Store to be initialise with default namespaces
type Store ¶
type Store interface { // Set persists the NameSpace object. // // When the object already exists it is overwritten. Set(ns *NameSpace) error // Add either the Base and Prefix alternatives depending on which one // is found first. When neither is found a new NameSpace is created. Add(prefix, base string) (*NameSpace, error) // Delete removes the NameSpace from the store. // // Delete matches by the Prefix of the Namespace. Delete(ns *NameSpace) error // Len returns the number of stored namespaces Len() int // GetWithPrefix returns the NameSpace for a given prefix. // When the prefix is not found, an ErrNameSpaceNotFound error is returned. GetWithPrefix(prefix string) (ns *NameSpace, err error) // GetWithBase returns the NameSpace for a given base-URI. // When the base-URI is not found, an ErrNameSpaceNotFound error is returned. GetWithBase(base string) (ns *NameSpace, err error) }
Store provides functionality to query and persist namespaces.