rdf

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 11 Imported by: 2

Documentation

Overview

Package rdf implements functions for serializing/deserializing to/from ttl and json-ld as well as conversion of triples to a graph structure.

Index

Constants

This section is empty.

Variables

View Source
var (
	// XsdString string
	XsdString = "http://www.w3.org/2001/XMLSchema#string"
	// XsdBoolean bool
	XsdBoolean = "http://www.w3.org/2001/XMLSchema#boolean"
	// XsdDecimal float
	XsdDecimal = "http://www.w3.org/2001/XMLSchema#decimal"
	// XsdInteger int
	XsdInteger = "http://www.w3.org/2001/XMLSchema#integer"
	// XsdDouble float
	XsdDouble = "http://www.w3.org/2001/XMLSchema#double"

	// XsdTime time
	XsdTime = "http://www.w3.org/2001/XMLSchema#time"
	// XsdDate time
	XsdDate = "http://www.w3.org/2001/XMLSchema#date"
	// XsdDateTime time
	XsdDateTime = "http://www.w3.org/2001/XMLSchema#dateTime"
	// XsdDateTimeStamp time
	XsdDateTimeStamp = "http://www.w3.org/2001/XMLSchema#dateTimeStamp"
	// XsdYear time
	XsdYear = "http://www.w3.org/2001/XMLSchema#gYear"
	// XsdMonth time
	XsdMonth = "http://www.w3.org/2001/XMLSchema#gMonth"
	// XsdDay time
	XsdDay = "http://www.w3.org/2001/XMLSchema#gDay"
	// XsdYearMonth time
	XsdYearMonth = "http://www.w3.org/2001/XMLSchema#gYearMonth"
	// XsdDuration time
	XsdDuration = "http://www.w3.org/2001/XMLSchema#Duration"

	// XsdByte byte
	XsdByte = "http://www.w3.org/2001/XMLSchema#byte"
)

IRIs of different literal datatype

Functions

func EncodeJSONLD

func EncodeJSONLD(triple []Triple, output io.Writer) (err error)

EncodeJSONLD encodes triples in json ld format

func EncodeTTL

func EncodeTTL(triple []Triple, output io.Writer) (err error)

EncodeTTL serializes triples in ttl format

Types

type BlankNode

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

BlankNode is a possible RDF term

func NewBlankNode

func NewBlankNode(name string) (blank BlankNode)

NewBlankNode returns an blanknode object with specified name

func (BlankNode) SerializeTTL

func (blank BlankNode) SerializeTTL(prefix map[string]string) (ret string)

SerializeTTL serializes blank node in ttl format

func (BlankNode) String

func (blank BlankNode) String() (str string)

String prints the name

func (BlankNode) Type

func (blank BlankNode) Type() (typ TermType)

Type denotes the term type

type Edge

type Edge struct {
	Pred    Predicate
	Subject *Node
	Object  *Node
}

Edge is a edge (predicate) in a rdf graph

type Graph

type Graph struct {
	Nodes map[string]*Node
	Edges []*Edge
}

Graph is a rdf grapgh containing nodes and edges

func NewGraph

func NewGraph(triple []Triple) (graph Graph, err error)

NewGraph creates a graph from an rdf triple slice

func (*Graph) Merge

func (graph *Graph) Merge(gIn *Graph) (err error)

Merge merges gIn into graph (nodes and edges are copied)

func (*Graph) String

func (graph *Graph) String() (ret string)

Print prints all nodes of the graph

func (*Graph) SubGraph

func (graph *Graph) SubGraph(nodes ...*Node) (g Graph)

SubGraph returns a graph containing the specified nodes and all transitive objects

func (*Graph) ToGraphvizDot

func (graph *Graph) ToGraphvizDot(output io.Writer, replace map[string]string,
	nodeShape map[string]string) (err error)

ToGraphvizDot exports a graph to the graphviz dot format

func (*Graph) ToTriples

func (graph *Graph) ToTriples() (ret []Triple)

ToTriples extracts triples from a graph

type IRI

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

IRI is a possible RDF term

func NewIRI

func NewIRI(name string) (iri IRI)

NewIRI returns an IRI object with specified name

func (IRI) SerializeTTL

func (iri IRI) SerializeTTL(prefix map[string]string) (ret string)

SerializeTTL serializes IRI in ttl format

func (IRI) String

func (iri IRI) String() (str string)

String prints the IRI

func (IRI) Type

func (iri IRI) Type() (typ TermType)

Type denotes the term type

type Literal

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

Literal is a possible RDF term

func NewLiteral

func NewLiteral(val interface{}, typ string) (lit Literal, err error)

NewLiteral returns a literal

func (Literal) SerializeTTL

func (lit Literal) SerializeTTL(prefix map[string]string) (ret string)

SerializeTTL serializes Literal in ttl format

func (Literal) String

func (lit Literal) String() (str string)

String prints the literal string

func (Literal) ToDuration

func (lit Literal) ToDuration() (d time.Duration, err error)

ToDuration converts a literal to time.Duration if possible

func (Literal) ToTime

func (lit Literal) ToTime() (t time.Time, err error)

ToTime converts a xsd literal to time.Time if possible

func (Literal) Type

func (lit Literal) Type() (typ TermType)

Type denotes the term type

type Node

type Node struct {
	Term        Term
	Edge        []*Edge
	InverseEdge []*Edge
}

Node is a node (subject and/or object) in a rdf graph

type Object

type Object interface {
	Term
}

Object represents the object of a rdf triple

type Predicate

type Predicate interface {
	Term
}

Predicate represents the predicate of a rdf triple

type Subject

type Subject interface {
	Term
}

Subject represents the subject of a rdf triple

type Term

type Term interface {
	Type() (typ TermType)
	String() (str string)
	SerializeTTL(prefix map[string]string) (str string)
}

Term represents an RDF term. possible types: Blank node, Literal and IRI.

type TermType

type TermType int

TermType is the type of a RDF term (IRI, Literal, BlankNode)

const (
	TermBlankNode TermType = iota
	TermLiteral
	TermIRI
)

possible RDF term types

type Triple

type Triple struct {
	Sub  Subject
	Pred Predicate
	Obj  Object
}

Triple is one rdf triple consisting of Subject, Predicate and Object

func DecodeJSONLD

func DecodeJSONLD(input io.Reader) (trip []Triple, err error)

DecodeJSONLD decodes a jsonld input to rdf triples

func DecodeTTL

func DecodeTTL(input io.Reader) (trip []Triple, err error)

DecodeTTL decodes a ttl input to rdf triples

func (Triple) SerializeTTL

func (trip Triple) SerializeTTL(prefix map[string]string) (ret string)

SerializeTTL serializes a single Triple in ttl format

Jump to

Keyboard shortcuts

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