turtle

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Example (Example1)
package main

import (
	"embed"
	"fmt"

	_ "embed"
	ttl "github.com/0x51-dev/rdf/turtle"
)

var example1 string

func main() {
	doc, _ := ttl.ParseDocument(example1)
	fmt.Println(doc)
}
Output:

@base <http://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rel: <http://www.perceive.net/schemas/relationship/> .
<#green-goblin> a foaf:Person ; foaf:name "Green Goblin" ; rel:enemyOf <#spiderman> .
<#spiderman> a foaf:Person ; foaf:name "Spiderman", "Человек-паук"@ru ; rel:enemyOf <#green-goblin> .

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvaluateDocument

func EvaluateDocument(doc Document, cwd string) (nt.Document, error)

func ValidateDocument

func ValidateDocument(doc Document) bool

Types

type A

type A struct{}

func (A) Equal

func (a A) Equal(v any) bool

func (A) String

func (a A) String() string

type Base

type Base string

func ParseBase

func ParseBase(n *parser.Node) (*Base, error)

func (Base) Equal

func (b Base) Equal(v any) bool

func (Base) String

func (b Base) String() string

type BlankNode

type BlankNode string

func ParseBlankNode

func ParseBlankNode(n *parser.Node) (*BlankNode, error)

func (BlankNode) Equal

func (b BlankNode) Equal(v any) bool

func (BlankNode) String

func (b BlankNode) String() string

type BlankNodePropertyList

type BlankNodePropertyList PredicateObjectList

BlankNodePropertyList may appear in the subject or object position of a triple. That subject or object is a fresh RDF blank node. This blank node also serves as the subject of the triples produced by matching the predicateObjectList production embedded in a blankNodePropertyList.

func ParseBlankNodePropertyList

func ParseBlankNodePropertyList(n *parser.Node) (BlankNodePropertyList, error)

func (BlankNodePropertyList) Equal

func (b BlankNodePropertyList) Equal(v any) bool

func (BlankNodePropertyList) String

func (b BlankNodePropertyList) String() string

type BooleanLiteral

type BooleanLiteral bool

func (BooleanLiteral) Equal

func (bl BooleanLiteral) Equal(v any) bool

func (BooleanLiteral) String

func (bl BooleanLiteral) String() string

type Collection

type Collection []Object

Collection represents a rdf:first/rdf:rest list structure with the sequence of objects of the rdf:first statements being the order of the terms enclosed by (). It appears in the subject or object position of a triple. The blank node at the head of the list is the subject or object of the containing triple.

func ParseCollection

func ParseCollection(n *parser.Node) (Collection, error)

func (Collection) Equal

func (c Collection) Equal(v any) bool

func (Collection) String

func (c Collection) String() string

type Context

type Context struct {
	Base     string
	Prefixes map[string]string

	BnIndex, ElIndex int
}

func NewContext

func NewContext() *Context

func (*Context) EvaluateBlankNodePropertyList

func (ctx *Context) EvaluateBlankNodePropertyList(pl BlankNodePropertyList) ([]nt.Object, []nt.Triple, error)

func (*Context) EvaluateBooleanLiteral

func (ctx *Context) EvaluateBooleanLiteral(o *BooleanLiteral) (*nt.Literal, error)

func (*Context) EvaluateCollection

func (ctx *Context) EvaluateCollection(c Collection) (nt.Object, []nt.Triple, error)

func (*Context) EvaluateIRI

func (ctx *Context) EvaluateIRI(iri *IRI) (*nt.IRIReference, error)

func (*Context) EvaluateNumericLiteral

func (ctx *Context) EvaluateNumericLiteral(o *NumericLiteral) (*nt.Literal, error)

func (*Context) EvaluateObject

func (ctx *Context) EvaluateObject(o Object) ([]nt.Object, []nt.Triple, error)

func (*Context) EvaluateObjectList

func (ctx *Context) EvaluateObjectList(os ObjectList) ([]nt.Object, []nt.Triple, error)

EvaluateObjectList evaluates a list of objects.

func (*Context) EvaluatePredicateObject

func (ctx *Context) EvaluatePredicateObject(po PredicateObject) (nt.IRIReference, []nt.Object, []nt.Triple, error)

func (*Context) EvaluateStringLiteral

func (ctx *Context) EvaluateStringLiteral(o *StringLiteral) (*nt.Literal, error)

func (*Context) EvaluateTriple

func (ctx *Context) EvaluateTriple(t *Triple) ([]nt.Triple, error)

func (*Context) ValidateCollection

func (ctx *Context) ValidateCollection(c Collection) bool

func (*Context) ValidateIRI

func (ctx *Context) ValidateIRI(i *IRI) bool

func (*Context) ValidatePredicateObjectList

func (ctx *Context) ValidatePredicateObjectList(p PredicateObjectList) bool

func (*Context) ValidateTriple

func (ctx *Context) ValidateTriple(t *Triple) bool

type Directive

type Directive interface {
	Equal(v any) bool
	fmt.Stringer
	// contains filtered or unexported methods
}

func ParseDirective

func ParseDirective(n *parser.Node) (Directive, error)

type Document

type Document []Statement

func ParseDocument

func ParseDocument(doc string) (Document, error)

func (Document) Equal

func (d Document) Equal(other Document) bool

func (Document) Len

func (d Document) Len() int

func (Document) Less

func (d Document) Less(i, j int) bool

func (Document) String

func (d Document) String() string

func (Document) SubjectMap

func (d Document) SubjectMap() (map[string]*Triple, error)

func (Document) Swap

func (d Document) Swap(i, j int)

type IRI

type IRI struct {
	Prefixed bool
	Value    string
}

IRI can be written as a relative/absolute IRI or prefixed name.

func ParseIRI

func ParseIRI(n *parser.Node) (*IRI, error)

func (IRI) Equal

func (i IRI) Equal(v any) bool

func (IRI) String

func (i IRI) String() string

type Literal

type Literal interface {
	Object

	Equal(v any) bool
	fmt.Stringer
	// contains filtered or unexported methods
}

Literal is either StringLiteral, NumericLiteral or BooleanLiteral.

func ParseBooleanLiteral

func ParseBooleanLiteral(n *parser.Node) (Literal, error)

func ParseDecimal

func ParseDecimal(n *parser.Node) (Literal, error)

func ParseDouble

func ParseDouble(n *parser.Node) (Literal, error)

func ParseInteger

func ParseInteger(n *parser.Node) (Literal, error)

func ParseLiteral

func ParseLiteral(n *parser.Node) (Literal, error)

func ParseNumericLiteral

func ParseNumericLiteral(n *parser.Node) (Literal, error)

func ParseRDFLiteral

func ParseRDFLiteral(n *parser.Node) (Literal, error)

type NumericLiteral

type NumericLiteral struct {
	Type  NumericType
	Value string
}

func (NumericLiteral) Equal

func (nl NumericLiteral) Equal(v any) bool

func (NumericLiteral) String

func (nl NumericLiteral) String() string

type NumericType

type NumericType int
const (
	Decimal NumericType = iota
	Double
	Integer
)

type Object

type Object interface {
	Equal(v any) bool
	fmt.Stringer
	// contains filtered or unexported methods
}

func ParseObject

func ParseObject(n *parser.Node) (Object, error)

type ObjectList

type ObjectList Collection

ObjectList matches a series of objects separated by ',' following a predicate. This expresses a series of RDF Triples with the corresponding subject and predicate and each object allocated to one triple.

func ParseObjectList

func ParseObjectList(n *parser.Node) (ObjectList, error)

func (ObjectList) Equal

func (ol ObjectList) Equal(v any) bool

func (ObjectList) Len

func (ol ObjectList) Len() int

func (ObjectList) Less

func (ol ObjectList) Less(i, j int) bool

func (ObjectList) String

func (ol ObjectList) String() string

func (ObjectList) Swap

func (ol ObjectList) Swap(i, j int)

type PredicateObject

type PredicateObject struct {
	Verb       Verb
	ObjectList ObjectList
}

func ParsePredicateObject

func ParsePredicateObject(n *parser.Node) (*PredicateObject, error)

func (PredicateObject) Equal

func (po PredicateObject) Equal(v any) bool

func (PredicateObject) String

func (po PredicateObject) String() string

type PredicateObjectList

type PredicateObjectList []PredicateObject

PredicateObjectList matches a series of predicates and objects, separated by ';', following a subject. This expresses a series of RDF Triples with that subject and each predicate and object allocated to one triple.

func ParsePredicateObjectList

func ParsePredicateObjectList(n *parser.Node) (PredicateObjectList, error)

func (PredicateObjectList) Equal

func (pol PredicateObjectList) Equal(v any) bool

func (PredicateObjectList) Len

func (pol PredicateObjectList) Len() int

func (PredicateObjectList) Less

func (pol PredicateObjectList) Less(i, j int) bool

func (PredicateObjectList) String

func (pol PredicateObjectList) String() string

func (PredicateObjectList) Swap

func (pol PredicateObjectList) Swap(i, j int)

type Prefix

type Prefix struct {
	Name string
	IRI  string
}

func ParsePrefix

func ParsePrefix(n *parser.Node) (*Prefix, error)

func (Prefix) Equal

func (p Prefix) Equal(v any) bool

func (Prefix) Less

func (p Prefix) Less(other any) bool

func (Prefix) String

func (p Prefix) String() string

type Statement

type Statement interface {
	Equal(v any) bool
	fmt.Stringer
	// contains filtered or unexported methods
}

type StringLiteral

type StringLiteral struct {
	Value       string
	Multiline   bool
	SingleQuote bool
	LanguageTag string
	DatatypeIRI *IRI
}

func ParseStringLiteral

func ParseStringLiteral(n *parser.Node) (*StringLiteral, error)

func (StringLiteral) Equal

func (sl StringLiteral) Equal(v any) bool

func (StringLiteral) String

func (sl StringLiteral) String() string

type Subject

type Subject interface {
	Equal(v any) bool
	fmt.Stringer
	// contains filtered or unexported methods
}

func ParseSubject

func ParseSubject(n *parser.Node) (Subject, error)

type Triple

type Triple struct {
	Subject               Subject
	BlankNodePropertyList BlankNodePropertyList
	PredicateObjectList   PredicateObjectList
}

func ParseTripleBlankNodePropertyList

func ParseTripleBlankNodePropertyList(n *parser.Node) (*Triple, error)

func ParseTripleSubject

func ParseTripleSubject(n *parser.Node) (*Triple, error)

func ParseTriples

func ParseTriples(n *parser.Node) (*Triple, error)

func (Triple) Equal

func (t Triple) Equal(v any) bool

func (Triple) PredicateObjectMap

func (t Triple) PredicateObjectMap() (map[string]ObjectList, error)

func (Triple) String

func (t Triple) String() string

type Verb

type Verb interface {
	Equal(v any) bool
	fmt.Stringer
	// contains filtered or unexported methods
}

func ParseVerb

func ParseVerb(n *parser.Node) (Verb, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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