rdf

package
v0.1.0-phase2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	XSDString   = NewNamedNode("http://www.w3.org/2001/XMLSchema#string")
	XSDInteger  = NewNamedNode("http://www.w3.org/2001/XMLSchema#integer")
	XSDDecimal  = NewNamedNode("http://www.w3.org/2001/XMLSchema#decimal")
	XSDFloat    = NewNamedNode("http://www.w3.org/2001/XMLSchema#float")
	XSDDouble   = NewNamedNode("http://www.w3.org/2001/XMLSchema#double")
	XSDBoolean  = NewNamedNode("http://www.w3.org/2001/XMLSchema#boolean")
	XSDDateTime = NewNamedNode("http://www.w3.org/2001/XMLSchema#dateTime")
	XSDDate     = NewNamedNode("http://www.w3.org/2001/XMLSchema#date")
	XSDTime     = NewNamedNode("http://www.w3.org/2001/XMLSchema#time")
	XSDDuration = NewNamedNode("http://www.w3.org/2001/XMLSchema#duration")
)

Helper functions for common XSD datatypes

View Source
var (
	RDFDirLangString = NewNamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString")
	RDFReifies       = NewNamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies")
)

RDF 1.2 vocabulary constants

Functions

func AreGraphsIsomorphic

func AreGraphsIsomorphic(expected, actual []*Triple) bool

AreGraphsIsomorphic checks if two sets of triples are isomorphic, accounting for blank node label differences. Two graphs are isomorphic if there exists a bijection between their blank nodes such that when applied, the graphs are identical.

func AreQuadsIsomorphic

func AreQuadsIsomorphic(expected, actual []*Quad) bool

AreQuadsIsomorphic checks if two sets of quads are isomorphic, accounting for blank node label differences in both triples and graph names.

func DecodeFloat64BigEndian

func DecodeFloat64BigEndian(buf []byte) float64

func DecodeInt64BigEndian

func DecodeInt64BigEndian(buf []byte) int64

func EncodeFloat64BigEndian

func EncodeFloat64BigEndian(value float64) []byte

func EncodeInt64BigEndian

func EncodeInt64BigEndian(value int64) []byte

Utility functions for encoding numeric values

func GetSupportedContentTypes

func GetSupportedContentTypes() []string

GetSupportedContentTypes returns a list of all supported content types

func SerializeQuadsCanonical

func SerializeQuadsCanonical(quads []*Quad) string

SerializeQuadsCanonical serializes quads to canonical N-Quads format (C14N) Implements RDF 1.2 canonicalization rules (escape sequences, whitespace) Note: Canonical form specifies representation, NOT ordering. Input order is preserved.

func SerializeTriplesCanonical

func SerializeTriplesCanonical(triples []*Triple) string

SerializeTriplesCanonical serializes triples to canonical N-Triples format (C14N) Implements RDF 1.2 canonicalization rules (escape sequences, whitespace) Note: Canonical form specifies representation, NOT ordering. Input order is preserved.

Types

type BlankNode

type BlankNode struct {
	ID string
}

BlankNode represents a blank node

func NewBlankNode

func NewBlankNode(id string) *BlankNode

func (*BlankNode) Equals

func (b *BlankNode) Equals(other Term) bool

func (*BlankNode) String

func (b *BlankNode) String() string

func (*BlankNode) Type

func (b *BlankNode) Type() TermType

type DefaultGraph

type DefaultGraph struct{}

DefaultGraph represents the default graph

func NewDefaultGraph

func NewDefaultGraph() *DefaultGraph

func (*DefaultGraph) Equals

func (d *DefaultGraph) Equals(other Term) bool

func (*DefaultGraph) String

func (d *DefaultGraph) String() string

func (*DefaultGraph) Type

func (d *DefaultGraph) Type() TermType

type JSONLDIOParser

type JSONLDIOParser struct{}

JSONLDIOParser parses JSON-LD format (triples, default graph)

func (*JSONLDIOParser) ContentType

func (p *JSONLDIOParser) ContentType() string

func (*JSONLDIOParser) Parse

func (p *JSONLDIOParser) Parse(reader io.Reader) ([]*Quad, error)

type JSONLDParser

type JSONLDParser struct{}

JSONLDParser parses JSON-LD format Note: This is a simplified parser that handles common JSON-LD patterns. It supports: - Simple @id and @type - Properties with string values - Properties with @value objects - Properties with @id references - @language and @type in value objects - Basic @context expansion (prefix mapping)

Not yet supported: - Full @context processing (remote contexts, nested contexts) - @graph - @list and @set - @reverse - Framing - Compaction/Expansion algorithms

func NewJSONLDParser

func NewJSONLDParser() *JSONLDParser

NewJSONLDParser creates a new JSON-LD parser

func (*JSONLDParser) Parse

func (p *JSONLDParser) Parse(reader io.Reader) ([]*Quad, error)

Parse parses JSON-LD and returns quads (all in default graph)

type Literal

type Literal struct {
	Value     string
	Language  string     // for language-tagged strings
	Direction string     // RDF 1.2: text direction ("ltr", "rtl", or "")
	Datatype  *NamedNode // for typed literals
}

Literal represents an RDF literal

func NewBooleanLiteral

func NewBooleanLiteral(value bool) *Literal

func NewDateTimeLiteral

func NewDateTimeLiteral(value time.Time) *Literal

func NewDecimalLiteral

func NewDecimalLiteral(value float64) *Literal

func NewDoubleLiteral

func NewDoubleLiteral(value float64) *Literal

func NewIntegerLiteral

func NewIntegerLiteral(value int64) *Literal

func NewLiteral

func NewLiteral(value string) *Literal

func NewLiteralWithDatatype

func NewLiteralWithDatatype(value string, datatype *NamedNode) *Literal

func NewLiteralWithLanguage

func NewLiteralWithLanguage(value, language string) *Literal

func NewLiteralWithLanguageAndDirection

func NewLiteralWithLanguageAndDirection(value, language, direction string) *Literal

NewLiteralWithLanguageAndDirection creates a literal with language and direction (RDF 1.2)

func (*Literal) Equals

func (l *Literal) Equals(other Term) bool

func (*Literal) String

func (l *Literal) String() string

func (*Literal) Type

func (l *Literal) Type() TermType

type NQuadsIOParser

type NQuadsIOParser struct{}

NQuadsIOParser parses N-Quads format (quads with optional graph)

func (*NQuadsIOParser) ContentType

func (p *NQuadsIOParser) ContentType() string

func (*NQuadsIOParser) Parse

func (p *NQuadsIOParser) Parse(reader io.Reader) ([]*Quad, error)

type NQuadsParser

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

NQuadsParser is an N-Quads parser that extends N-Triples with an optional 4th position for graphs N-Quads format: <subject> <predicate> <object> [<graph>] . Compatible with N-Triples (3 positions) - defaults to default graph

func NewNQuadsParser

func NewNQuadsParser(input string) *NQuadsParser

NewNQuadsParser creates a new N-Quads parser with strict validation

func (*NQuadsParser) Parse

func (p *NQuadsParser) Parse() ([]*Quad, error)

Parse parses the N-Quads document and returns quads

type NTriplesIOParser

type NTriplesIOParser struct{}

NTriplesIOParser parses N-Triples format (triples only, default graph)

func (*NTriplesIOParser) ContentType

func (p *NTriplesIOParser) ContentType() string

func (*NTriplesIOParser) Parse

func (p *NTriplesIOParser) Parse(reader io.Reader) ([]*Quad, error)

type NamedNode

type NamedNode struct {
	IRI string
}

NamedNode represents an IRI

func NewNamedNode

func NewNamedNode(iri string) *NamedNode

func (*NamedNode) Equals

func (n *NamedNode) Equals(other Term) bool

func (*NamedNode) String

func (n *NamedNode) String() string

func (*NamedNode) Type

func (n *NamedNode) Type() TermType

type Quad

type Quad struct {
	Subject   Term
	Predicate Term
	Object    Term
	Graph     Term
}

Quad represents an RDF quad (subject, predicate, object, graph)

func NewQuad

func NewQuad(subject, predicate, object, graph Term) *Quad

func (*Quad) String

func (q *Quad) String() string

type QuotedTriple

type QuotedTriple struct {
	Subject   Term
	Predicate Term
	Object    Term
}

QuotedTriple represents an RDF 1.2 quoted triple (triple term) Can be used as subject or object in other triples

func NewQuotedTriple

func NewQuotedTriple(subject, predicate, object Term) (*QuotedTriple, error)

NewQuotedTriple creates a new quoted triple with validation

func (*QuotedTriple) Equals

func (q *QuotedTriple) Equals(other Term) bool

func (*QuotedTriple) String

func (q *QuotedTriple) String() string

func (*QuotedTriple) Type

func (q *QuotedTriple) Type() TermType

type RDFParser

type RDFParser interface {
	// Parse parses RDF data from a reader and returns quads
	Parse(reader io.Reader) ([]*Quad, error)

	// ContentType returns the MIME type this parser handles
	ContentType() string
}

RDFParser is the interface for parsing RDF data in various formats

func NewParser

func NewParser(contentType string) (RDFParser, error)

NewParser creates an RDF parser based on the content type

type RDFXMLIOParser

type RDFXMLIOParser struct{}

RDFXMLIOParser parses RDF/XML format (triples, default graph)

func (*RDFXMLIOParser) ContentType

func (p *RDFXMLIOParser) ContentType() string

func (*RDFXMLIOParser) Parse

func (p *RDFXMLIOParser) Parse(reader io.Reader) ([]*Quad, error)

type RDFXMLParser

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

RDFXMLParser parses RDF/XML format Note: This is a simplified parser that handles common RDF/XML patterns. It supports: - rdf:Description elements - Properties as XML elements - rdf:about, rdf:resource, rdf:ID, rdf:nodeID attributes - rdf:datatype, xml:lang attributes - Nested blank nodes - RDF containers (rdf:Bag, rdf:Seq, rdf:Alt) - rdf:li auto-numbering - xml:base for base URI resolution

Not yet supported: - rdf:parseType="Collection"

func NewRDFXMLParser

func NewRDFXMLParser() *RDFXMLParser

NewRDFXMLParser creates a new RDF/XML parser

func (*RDFXMLParser) Parse

func (p *RDFXMLParser) Parse(reader io.Reader) ([]*Quad, error)

Parse parses RDF/XML and returns quads (all in default graph)

func (*RDFXMLParser) SetBaseURI

func (p *RDFXMLParser) SetBaseURI(base string)

SetBaseURI sets the document base URI (used for resolving relative URIs and rdf:ID)

type ReifiedTriple

type ReifiedTriple struct {
	Identifier Term          // The identifier (IRI or blank node) for this reified triple
	Triple     *QuotedTriple // The underlying quoted triple
}

ReifiedTriple represents a quoted triple with an explicit identifier (RDF 1.2 reification) Syntax: << s p o ~ identifier >> This is used internally during parsing to track that a quoted triple has an identifier

func (*ReifiedTriple) Equals

func (r *ReifiedTriple) Equals(other Term) bool

func (*ReifiedTriple) String

func (r *ReifiedTriple) String() string

func (*ReifiedTriple) Type

func (r *ReifiedTriple) Type() TermType

type Term

type Term interface {
	Type() TermType
	String() string
	Equals(other Term) bool
}

Term represents an RDF term (IRI, blank node, or literal)

type TermType

type TermType byte

TermType represents the type of an RDF term

const (
	// Core RDF types
	TermTypeNamedNode TermType = iota + 1
	TermTypeBlankNode
	TermTypeLiteral
	TermTypeDefaultGraph
	TermTypeQuotedTriple // RDF 1.2: Triple terms

	// Literal subtypes
	TermTypeStringLiteral
	TermTypeLangStringLiteral
	TermTypeIntegerLiteral
	TermTypeDecimalLiteral
	TermTypeDoubleLiteral
	TermTypeBooleanLiteral
	TermTypeDateTimeLiteral
	TermTypeDateLiteral
	TermTypeTimeLiteral
	TermTypeDurationLiteral
	TermTypeTypedLiteral // Custom datatype (not XSD built-in) - MUST be last to preserve existing type values
)

type TriGIOParser

type TriGIOParser struct{}

TriGIOParser parses TriG format (Turtle + named graphs, quads)

func (*TriGIOParser) ContentType

func (p *TriGIOParser) ContentType() string

func (*TriGIOParser) Parse

func (p *TriGIOParser) Parse(reader io.Reader) ([]*Quad, error)

type TriGParser

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

TriGParser parses TriG format (Turtle + named graphs)

func NewTriGParser

func NewTriGParser(input string) *TriGParser

NewTriGParser creates a new TriG parser

func (*TriGParser) Parse

func (p *TriGParser) Parse() ([]*Quad, error)

Parse parses the TriG document and returns quads

func (*TriGParser) SetBaseURI

func (p *TriGParser) SetBaseURI(baseURI string)

SetBaseURI sets the base URI for resolving relative IRIs

type Triple

type Triple struct {
	Subject   Term
	Predicate Term
	Object    Term
}

Triple represents an RDF triple (subject, predicate, object)

func NewTriple

func NewTriple(subject, predicate, object Term) *Triple

func (*Triple) String

func (t *Triple) String() string

type TripleTerm

type TripleTerm struct {
	Subject   Term
	Predicate Term
	Object    Term
}

TripleTerm represents an RDF 1.2 triple term <<( s p o )>> (N-Triples 1.2 syntax in Turtle) Triple terms are NOT automatically reified when used as subjects/objects

func (*TripleTerm) Equals

func (t *TripleTerm) Equals(other Term) bool

func (*TripleTerm) String

func (t *TripleTerm) String() string

func (*TripleTerm) Type

func (t *TripleTerm) Type() TermType

type TurtleIOParser

type TurtleIOParser struct{}

TurtleIOParser parses Turtle format (triples with prefixes, default graph)

func (*TurtleIOParser) ContentType

func (p *TurtleIOParser) ContentType() string

func (*TurtleIOParser) Parse

func (p *TurtleIOParser) Parse(reader io.Reader) ([]*Quad, error)

type TurtleParser

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

TurtleParser is a simple Turtle/N-Triples parser for loading test data

func NewNTriplesParser

func NewNTriplesParser(input string) *TurtleParser

NewNTriplesParser creates a new N-Triples parser with strict validation

func NewTurtleParser

func NewTurtleParser(input string) *TurtleParser

NewTurtleParser creates a new Turtle parser

func (*TurtleParser) Parse

func (p *TurtleParser) Parse() ([]*Triple, error)

Parse parses the Turtle document and returns triples

func (*TurtleParser) SetBaseURI

func (p *TurtleParser) SetBaseURI(baseURI string)

SetBaseURI sets the base URI for resolving relative IRIs

Jump to

Keyboard shortcuts

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