Documentation
¶
Overview ¶
Package export serializes []message.Triple to standard RDF formats.
Supported formats:
- Turtle (.ttl) — compact, human-readable with prefix declarations and subject grouping
- N-Triples (.nt) — line-based, one triple per line, no abbreviations
- JSON-LD (.jsonld) — JSON with @context and @graph for web APIs
The package uses the existing vocabulary infrastructure for IRI resolution:
- Registered predicates map to their StandardIRI via vocabulary.GetPredicateMetadata
- Entity ID subjects are parsed via message.ParseEntityID and converted to hierarchical IRIs
- Object values are typed using XSD datatypes based on Go type inference
Basic usage:
triples := []message.Triple{
{Subject: "acme.ops.robotics.gcs.drone.001", Predicate: "robotics.battery.level", Object: 85.5},
{Subject: "acme.ops.robotics.gcs.drone.001", Predicate: "robotics.flight.armed", Object: true},
}
// Write Turtle to stdout
err := export.Serialize(os.Stdout, triples, export.Turtle)
// Get N-Triples as a string
s, err := export.SerializeToString(triples, export.NTriples)
// Custom base IRI
err = export.Serialize(w, triples, export.JSONLD, export.WithBaseIRI("https://example.org"))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Format ¶
type Format int
Format identifies an RDF serialization format.
const ( // Turtle is the Terse RDF Triple Language format (.ttl). // Compact and human-readable with prefix declarations and subject grouping. Turtle Format = iota // NTriples is the N-Triples format (.nt). // Line-based, one triple per line, fully expanded IRIs. NTriples // JSONLD is the JSON-LD format (.jsonld). // JSON with @context and @graph for web API consumption. JSONLD )
type Option ¶
type Option func(*options)
Option configures serialization behavior.
func WithBaseIRI ¶
WithBaseIRI overrides the default SemStreamsBase IRI used for generated URIs.
func WithSubjectIRIFunc ¶
WithSubjectIRIFunc provides a custom function to map entity ID strings to IRIs. When set, this replaces the default subject IRI generation logic entirely; WithBaseIRI has no effect on subjects when a custom function is provided.
Click to show internal directories.
Click to hide internal directories.