Documentation
¶
Overview ¶
Package curie implements the type for compact URI. It defines a generic syntax for expressing URIs by abbreviated literal as defined by the W3C. https://www.w3.org/TR/2010/NOTE-curie-20101216/
Package curie The type `curie` ("Compact URI") defines a generic syntax for expressing URIs by abbreviated literal as defined by the W3C. https://www.w3.org/TR/2010/NOTE-curie-20101216/.
The type supports type safe domain driven design using aspects of hierarchical linked-data.
Inspiration ¶
Linked-Data are used widely by Semantic Web to publish structured data so that it can be interlinked by applications. Internationalized Resource Identifiers (IRIs) are key elements to cross-link data structure and establish references (pointers) to data elements. These IRIs may be written as relative, absolute or compact IRIs. The `curie` type is just a formal definition of compact IRI (superset of XML QNames). Another challenge solved by `curie` is a formal mechanism to permit the use of hierarchical extensible name collections and its serialization. All-in-all CURIEs expand to any IRI.
CURIE format ¶
Compact URI is superset of XML QNames. It is comprised of two components: a prefix and a suffix, separated by `:`. Omit prefix to declare a relative URI; omit suffix to declare namespace only; omit both components to declare empty URI. See W3C CURIE Syntax 1.0 https://www.w3.org/TR/2010/NOTE-curie-20101216/
safe_curie := '[' curie ']' curie := [ [ prefix ] ':' ] reference prefix := NCName reference := irelative-ref (as defined in IRI)
CURIE algebra ¶
The type defines a simple algebra for manipulating instances of compact URI ¶
↣ zero: empty compact URI
↣ transform: string ⟼ CURIE
↣ binary compose: CURIE × CURIE ⟼ CURIE
↣ unary decompose: CURIE ⟼ CURIE
↣ rank: |CURIE| ⟼ Int
↣ binary ordering: CURIE ≼ CURIE ⟼ bool
Linked data ¶
Cross-linking of structured data is an essential part of type safe domain driven design. The library helps developers to model relations between data instances using familiar data type:
type Person struct { curie.ID Father *curie.IRI Mother *curie.IRI Friends []curie.IRI }
`curie.ID` and `curie.IRI` are sibling, equivalent CURIE data type. `ID` is only used as primary key, `IRI` is a "pointer" to linked-data.
CURIE type is core type to organize hierarchies. An application declares `A ⟼ B` hierarchical relation using path at suffix. For example, the root is `curie.New("some:a")`, 2nd rank node `curie.New("some:a/b")` and so on `curie.New("some:a/b/c/e/f")`.
Index ¶
- Constants
- func Decode(uri string) string
- func Eq(a, b IRI) bool
- func IsEmpty(iri IRI) bool
- func Lt(a, b IRI) bool
- func Prefix(iri IRI) string
- func Rank(iri IRI) int
- func Reference(iri IRI) string
- func Seq(iri IRI) (string, string)
- func URI(prefixes Prefixes, iri IRI) string
- func URL(prefixes Prefixes, iri IRI) (*url.URL, error)
- type IRI
- type Namespaces
- type Prefixes
Constants ¶
const ( EMPTY = iota PREFIX REFERENCE )
Built-in CURIE ranks
Variables ¶
This section is empty.
Functions ¶
func Decode ¶ added in v1.8.2
Decode converts URIs to IRIs as defined by RFC 3987 https://www.rfc-editor.org/rfc/rfc3987#section-3.2
func Lt ¶ added in v1.2.0
Lt compares two CURIEs, return true if left element is less than supplied one.
func Rank ¶ added in v1.2.0
Rank of CURIE, number of elements Rank is an alias of len(curie.Seq(iri))
func Reference ¶ added in v1.7.0
Reference decomposes CURIE and return its reference as string value.
func Seq ¶ added in v1.2.0
Seq Returns CURIE segments
a: ⟼ [ a ] b ⟼ [ , b ] a:b ⟼ [a, b] a:b/c/d ⟼ [a, b/c/d ]
Types ¶
type IRI ¶
type IRI string
IRI is compact URI, defined as superset of XML QNames, with the modification that the format of the strings after the colon is looser.
safe_curie := '[' curie ']' curie := [ [ prefix ] ':' ] reference prefix := NCName reference := irelative-ref (as defined in IRI, RFC 3987)
func FromURI ¶ added in v1.8.0
URI converts fully qualified URL to CURIE
http://en.wikipedia.org/wiki/CURIE ⟼ wikipedia:CURIE
func Join ¶ added in v1.2.0
Join composes segments into new descendant CURIE.
a:b × [c, d, e] ⟼ a:b/c/d/e
func (IRI) MarshalJSON ¶
MarshalJSON `IRI ⟼ "[prefix:suffix]"`
func (*IRI) UnmarshalJSON ¶
UnmarshalJSON `"[prefix:suffix]" ⟼ IRI`
type Namespaces ¶ added in v1.7.1
Namespaces is constant in-memory collection of prefixes defined by the application
func (Namespaces) Create ¶ added in v1.8.0
func (ns Namespaces) Create(uri string) IRI
Create new URI using prefix table