Package 'ntriples'

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

Help Index


Create IRIs

Description

Validate absolute IRIs and assign the iri class. Identifiers are preserved exactly as supplied.

Usage

iri(x)

Arguments

x

A character vector of absolute IRIs.

Value

A character vector with class iri.

References

W3C. RDF 1.2 N-Triples.

Examples

# 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"
)

Create a single N-Triple statement

Description

Assemble a subject, predicate, and object into a single RDF statement in N-Triples syntax.

Usage

n_triple(s, p, o)

Arguments

s

Subject IRI or blank node.

p

Predicate IRI, or "a" for rdf:type.

o

Object IRI, blank node, literal, or supported R scalar.

Details

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.

Value

A single character string containing an N-Triple statement.

See Also

n_triples(), rdf_term(), iri()

Examples

n_triple(
  "https://example.org/dataset/1",
  "http://purl.org/dc/terms/title",
  "Growth of Orange Trees"
)

Create N-Triples

Description

Create RDF triple statements to annotate your dataset with standard, interoperable metadata.

Usage

n_triples(triples)

Arguments

triples

A character vector of N-Triples statements, created with n_triple().

Details

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.

Value

A character vector of unique N-Triple strings.

See Also

rdf_term(), n_triple(), iri(), person_triples()

Examples

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))

Serialize a person as RDF provenance statements

Description

Creates RDF statements describing a utils::person as an agent, using PROV-O by default or FOAF as an alternative.

Usage

person_triples(x, ontology = c("prov", "foaf"), subject = NULL)

Arguments

x

A single utils::person object.

ontology

Ontology to use: "prov" (default) or "foaf".

subject

Optional IRI or blank-node identifier for the person. Overrides any authority identifier found in x.

Details

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.

Value

A character vector containing N-Triples statements.

Examples

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")

Convert an R scalar to an RDF term

Description

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.

Usage

rdf_term(x)

Arguments

x

A single, non-missing R value or RDF term.

Details

Factors must be explicitly converted to character labels or integer category codes before serialization. Person objects and other structured entities are not supported.

Value

A character scalar containing an RDF term in N-Triples syntax.

Examples

rdf_term("Growth of Orange Trees")
rdf_term(42L)
rdf_term(iri("urn:example:dataset"))