| Title: | N-Triples Serialization and RDF Utility Functions |
|---|---|
| Description: | Provides lightweight, dependency-minimal tools for serializing RDF N-Triples in R. Supports IRI validation, typed RDF literals, date-time serialization, and provenance statements for `utils::person` objects using PROV-O or FOAF. Designed for reuse by packages implementing higher-level RDF data models and provenance workflows. |
| Authors: | Daniel Antal [aut, cre] (ORCID: <https://orcid.org/0000-0001-7513-6760>) |
| Maintainer: | Daniel Antal <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-12-02 11:32:11 UTC |
| Source: | https://github.com/dataobservatory-eu/ntriples |
Validate absolute IRIs and assign the iri class.
Identifiers are preserved exactly as supplied.
iri(x)iri(x)
x |
A character vector of absolute IRIs. |
A character vector with class iri.
W3C. RDF 1.2 N-Triples.
# IRI from the W3C N-Triples specification subject <- iri("http://one.example/subject1") subject # Use the IRI in an N-Triples statement n_triple( subject, "http://one.example/predicate1", "http://one.example/object1" )# IRI from the W3C N-Triples specification subject <- iri("http://one.example/subject1") subject # Use the IRI in an N-Triples statement n_triple( subject, "http://one.example/predicate1", "http://one.example/object1" )
Assemble a subject, predicate, and object into a single RDF statement in N-Triples syntax.
n_triple(s, p, o)n_triple(s, p, o)
s |
Subject IRI or blank node. |
p |
Predicate IRI, or |
o |
Object IRI, blank node, literal, or supported R scalar. |
This function converts individual values using rdf_term() and
validates their positions in the statement. Subjects must be IRIs or
blank nodes, predicates must be IRIs, and objects may also be literals.
Use n_triples() as the main entry point for collecting statements
into a unique set of N-Triples.
A single character string containing an N-Triple statement.
n_triples(), rdf_term(), iri()
n_triple( "https://example.org/dataset/1", "http://purl.org/dc/terms/title", "Growth of Orange Trees" )n_triple( "https://example.org/dataset/1", "http://purl.org/dc/terms/title", "Growth of Orange Trees" )
Create RDF triple statements to annotate your dataset with standard, interoperable metadata.
n_triples(triples)n_triples(triples)
triples |
A character vector of N-Triples statements, created with
|
N-Triples is a line-based serialization format for RDF. It is easy to parse and widely supported. For details, see the W3C RDF 1.2 N-Triples specification.
Use rdf_term() to serialize individual R values as RDF terms,
n_triple() to assemble a subject, predicate, and object into a
statement, and n_triples() to collect statements and remove duplicates.
A character vector of unique N-Triple strings.
rdf_term(), n_triple(), iri(),
person_triples()
triple_1 <- n_triple( "http://example.org/show/218", "http://www.w3.org/2000/01/rdf-schema#label", "That Seventies Show" ) triple_2 <- n_triple( "http://example.org/show/218", "http://example.org/show/localName", '"Cette Série des Années Septante"@fr-be' ) n_triples(c(triple_1, triple_2, triple_1))triple_1 <- n_triple( "http://example.org/show/218", "http://www.w3.org/2000/01/rdf-schema#label", "That Seventies Show" ) triple_2 <- n_triple( "http://example.org/show/218", "http://example.org/show/localName", '"Cette Série des Années Septante"@fr-be' ) n_triples(c(triple_1, triple_2, triple_1))
Creates RDF statements describing a utils::person as an agent,
using PROV-O by default or FOAF as an alternative.
person_triples(x, ontology = c("prov", "foaf"), subject = NULL)person_triples(x, ontology = c("prov", "foaf"), subject = NULL)
x |
A single |
ontology |
Ontology to use: |
subject |
Optional IRI or blank-node identifier for the person.
Overrides any authority identifier found in |
Uses an ORCID, ISNI, VIAF, or Wikidata identifier when available.
Otherwise, a blank-node identifier must be supplied through subject.
Person roles are deliberately ignored; role serialization belongs
to a separate function.
A character vector containing N-Triples statements.
author <- utils::person( given = "Jane", family = "Doe", comment = c(ORCID = "0000-0002-1825-0097") ) person_triples(author) # Use a blank node when no authority identifier is available contributor <- utils::person(given = "John", family = "Smith") person_triples(contributor, subject = "_:john")author <- utils::person( given = "Jane", family = "Doe", comment = c(ORCID = "0000-0002-1825-0097") ) person_triples(author) # Use a blank node when no authority identifier is available contributor <- utils::person(given = "John", family = "Smith") person_triples(contributor, subject = "_:john")
Serialize a scalar R value as an RDF term in N-Triples syntax. Character values are serialized as XSD string literals, numeric and logical values as appropriately typed literals, and IRIs as RDF resources. Already serialized RDF terms are preserved.
rdf_term(x)rdf_term(x)
x |
A single, non-missing R value or RDF term. |
Factors must be explicitly converted to character labels or integer category codes before serialization. Person objects and other structured entities are not supported.
A character scalar containing an RDF term in N-Triples syntax.
rdf_term("Growth of Orange Trees") rdf_term(42L) rdf_term(iri("urn:example:dataset"))rdf_term("Growth of Orange Trees") rdf_term(42L) rdf_term(iri("urn:example:dataset"))