namespace

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package namespace provides support for managing namespaces for RDF or XML URIs.

Index

Examples

Constants

View Source
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

func SplitURI(uri string) (base string, name string)

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 Error

type Error string

Error represents a Namespace error.

func (Error) Error

func (e Error) Error() string

Error returns the error message.

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

func (ns *NameSpace) AddBase(base string) error

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

func (ns *NameSpace) AddPrefix(prefix string) error

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

func (ns NameSpace) BaseURIs() []string

BaseURIs returns all namespace base-URIs linked to this NameSpace. This includes the default Base and all alternative base-URIs.

func (*NameSpace) GetID

func (ns *NameSpace) GetID() string

GetID returns a string representation of a UUID. When no UUID is sit, this function will generate it and update the NameSpace.

func (*NameSpace) Merge

func (ns *NameSpace) Merge(other *NameSpace) error

Merge merges the values of two NameSpace objects. The prefixes and alternative base URIs of the other NameSpace are merged into ns.

func (NameSpace) Prefixes

func (ns NameSpace) Prefixes() []string

Prefixes returns all namespace prefix linked to this NameSpace. This includes the default Prefix and all alternative prefixes.

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

func (s *Service) Add(prefix, base string) error

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) Len

func (s *Service) Len() int

Len returns the number of namespaces in the Service

func (*Service) SearchLabel

func (s *Service) SearchLabel(uri string) (string, error)

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

func (s *Service) Set(ns *NameSpace) error

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

type ServiceOptionFunc func(*Service) error

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.

type URI

type URI string

URI represents a NameSpace URI.

func (URI) String

func (uri URI) String() string

String returns a string representation of URI

Jump to

Keyboard shortcuts

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