{
const etl = new Etl()
etl.use(
// Step 1. Assert some linked data into the internal store.
executeRules(Source.file('static/model.trig')), // Step 2
// Step 3. Do something with the linked data, e.g. publish it to TriplyDB.
)
return etl
}
```
--------------------------------
### wkt.addPoint() example: resulting linked data assertion
Source: https://docs.triply.cc/triply-etl/transform/ratt
The linked data assertion produced by the wkt.addPoint() example. It shows the WKT literal as the object of the geo:asWKT property.
```turtle
city:Amstedam geo:asWKT "Point (52.37308 4.89245)"^^geo:wktLiteral
```
--------------------------------
### addValue() example: resulting linked data assertion
Source: https://docs.triply.cc/triply-etl/transform/ratt
The linked data assertion produced by the previous addValue() example, showing the person:johndoe foaf:age 22 triple.
```turtle
person:johndoe foaf:age 22.
```
--------------------------------
### Example desired tree structure
Source: https://docs.triply.cc/generics/JSON-LD-frames
Shows the desired tree-shaped JSON structure with cities as keys and inhabitants as arrays, illustrating the framing goal.
```json
{
"amsterdam": {
"inhabitants": [
"john"
]
},
"berlin": {
"inhabitants": [
"jane",
"tim"
]
}
}
```
--------------------------------
### Example CSV file values
Source: https://docs.triply.cc/triply-db-getting-started/uploading-data
A sample CSV file content that can be uploaded to TriplyDB. It is used to illustrate the simple representation for tabular data.
```csv
product_id,name,category,price,in_stock
P001,Laptop Stand,Office Equipment,49.99,true
P002,Ergonomic Keyboard,Peripherals,89.50,true
```
--------------------------------
### Markdown inline code example
Source: https://docs.triply.cc/triply-db-getting-started/reference
Shows how to use inline code with single backticks inside a sentence.
```markdown
Use `code` inside a sentence.
```
--------------------------------
### loadRdf() base IRI fix example
Source: https://docs.triply.cc/triply-etl/generic/changelog
Example showing the previous incorrect base IRI behavior when using `loadRdf()` with a string source. The snippet uses `Source.string('.')` and `logQuads()` to display the resulting quads.
```typescript
import { logQuads } from '@triplyetl/etl/debug'
import { Etl, loadRdf, Source } from '@triplyetl/etl/generic'
export default async function (): Promise {
const etl = new Etl()
etl.use(
loadRdf(Source.string('.')),
logQuads(),
)
return etl
}
```
```turtle
{
}
```
```turtle
{
}
```
--------------------------------
### Publish to TriplyDB with toTriplyDb()
Source: https://docs.triply.cc/triply-etl/publish
Uploads pipeline output to a TriplyDB dataset. If no account is given, the user account tied to the current API Token is used. The second and third examples specify an account and optionally set the overwrite option.
```javascript
toTriplyDb({dataset: 'my-dataset'})
toTriplyDb({account: 'my-account', dataset: 'my-dataset'})
toTriplyDb({account: 'my-account', dataset: 'my-dataset', opts:{ overwrite: true }})
```
--------------------------------
### Sample data with nested countries and labels
Source: https://docs.triply.cc/triply-etl/generic/control-structures
Example data used to illustrate nested forEach() calls. Contains an outer list of countries and an inner list of labels.
```json
{
"data": {
"countries": [
{
"id": "NL",
"labels": [
{
"name": "The Netherlands",
"locale": "en-us"
},
{
"name": "Nederland",
"locale": "nl-nl"
}
]
},
{
"id": "EN",
"labels": [
{
"name": "England",
"locale": "en-gb"
}
]
}
]
}
}
```
--------------------------------
### Example: statement reification
Source: https://docs.triply.cc/triply-etl/transform/ratt
Uses addHashedIri() to create a unique identifier for each reified statement, along with the resulting linked data.
```turtle
fromJson([{ id: '1', name: 'John Doe' }]),
// Step 1. Create the subject, predicate, and object terms.
addIri({ prefix: prefix.person, content: 'id', key: 'subject' }),
addIri({ prefix: prefix.def, content: str('name'), key: 'predicate' }),
addLiteral({ content: 'name', key: 'object' }),
// Step 2. Create the triple statement.
triple('subject', 'predicate', 'object'),
// Step 3. Create the reified statement.
addHashedIri({
prefix: prefix.statement,
content: ['subject', 'predicate', 'object'],
key: 'statement',
}),
pairs('statement',
[a, rdf.Statement],
[rdf.subject, 'subject'],
[rdf.predicate, 'predicate'],
[rdf.object, 'object'],
),
```
```turtle
person:1 def:name 'John Doe'.
statement:549decc4c44204a907aa32b4cc9bfaba
a rdf:Statement;
rdf:subject person:1;
rdf:predicate def:name;
rdf:object 'John Doe'.
```
--------------------------------
### Using loadRdf() with XSLT stylesheet
Source: https://docs.triply.cc/triply-etl/transform/xslt
Example of using loadRdf() middleware in TriplyETL to load and transform XML to RDF, specifying the stylesheet parameter and content type.
```javascript
loadRdf(Source.file(xml), {
contentType: 'application/rdf+xml',
stylesheet: Source.file(xsl),
}),
```
--------------------------------
### Example JSON-LD graph data
Source: https://docs.triply.cc/generics/JSON-LD-frames
Shows a JSON-LD array representing a graph with three persons and their cities. This is the input to be framed.
```json
[
{
"@id": "john",
"livesIn": { "@id": "amsterdam" }
},
{
"@id": "jane",
"livesIn": { "@id": "berlin" }
},
{
"@id": "tim",
"livesIn": { "@id": "berlin" }
}
]
```
--------------------------------
### Validate usage example
Source: https://docs.triply.cc/triply-etl/transform/ratt
Asserts a triple with an email address validated in the object position. Throws an error for invalid email addresses.
```triply-etl
fromJson([{ name: "John", email: 'john.appleseed@example.com' }, {name: 'NA', email: 'notAnEmail' } ]),
addLiteral({
content: 'email',
validate: isEmail(),
key: '_email',
}),
triple(iri(prefix.person, 'name'), foaf.mbox, '_email'),
```
```text
ERROR (Record #2) String "notAnEmail" is not an email address.
```
```triply-etl
fromJson([{ name: "John", email: 'john.appleseed@example.com' }, { name: "Lisa", email: 'lisa.appleseed@example.com' } ]),
addLiteral({
content: 'email',
validate: isEmail(),
key: '_email',
}),
triple(iri(prefix.person, 'name'), foaf.mbox, '_email'),
```
```turtle
person:John foaf:mbox "john.appleseed@example.com"
person:Lisa foaf:mbox "lisa.appleseed@example.com"
```
--------------------------------
### addValue() example: adding an array to a record
Source: https://docs.triply.cc/triply-etl/transform/ratt
Starts with an empty source record and adds a 'data' key containing an array with a string and a number. The triple assertion extracts elements using 'data[0]' and 'data[1]'.
```triply
fromJson([{}]),
addValue({
content: ['johndoe', 22],
key: 'data',
}),
triple(iri(prefix.person, 'data[0]'), foaf.age, 'data[1]'),
```
--------------------------------
### addTag() example: creating a Dutch language tag
Source: https://docs.triply.cc/triply-etl/transform/ratt
Creates a language tag for Dutch as spoken in the Netherlands and uses it in a triple assertion. The content 'nl-nl' must follow the IANA language subtag registry format.
```triply
fromJson([{ label: 'Amsterdam' }]),
addTag({
content: 'nl-nl',
key: 'lang',
}),
triple(iri(prefix.city, 'label'), rdfs.label, literal('label', 'lang')),
```
--------------------------------
### Linked data assertions output
Source: https://docs.triply.cc/triply-etl/generic/changelog
The resulting linked data assertions from the nestedPairs() example, showing the generated triples.
```turtle
product:1
sdo:height
[ qudt:unit unit:CentiM;
rdf:value 15 ].
```
--------------------------------
### Run SHACL SPARQL rule using external files
Source: https://docs.triply.cc/triply-etl/enrich/shacl/sparql-rules
Same TriplyETL script as Step 1C but loads instance data and information model from separate files (`static/instances.trig` and `static/model.trig`) instead of inline strings, keeping the script concise.
```typescript
import { logQuads } from '@triplyetl/etl/debug'
import { Etl, Source, loadRdf } from '@triplyetl/etl/generic'
import { executeRules } from '@triplyetl/etl/shacl'
export default async function (): Promise {
const etl = new Etl()
etl.use(
loadRdf(Source.file('static/instances.trig')),
executeRules(Source.file('static/model.trig')),
logQuads(),
)
return etl
}
```
--------------------------------
### nestedPairs() with fromJson() and addSkolemIri()
Source: https://docs.triply.cc/triply-etl/generic/changelog
Example of nestedPairs() used with fromJson() and addSkolemIri() to create linked data assertions with a Skolem IRI for the subject.
```typescript
fromJson([{ id: '1', height: 15 }]),
addSkolemIri({
prefix: prefix.skolem,
key: '_height',
}),
nestedPairs(iri(prefix.product, 'id'), sdo.height,
[qudt.unit, unit.CentiM],
[rdf.value, 'height'],
),
```
--------------------------------
### Navigate to target folder
Source: https://docs.triply.cc/triply-etl/generic/getting-started
Change into the target folder you specified during project creation.
```bash
cd my-etl
```
--------------------------------
### Alternative to nestedPairs() using triple() and pairs()
Source: https://docs.triply.cc/triply-etl/assert/ratt/statements
Shows how the geometry example can be rewritten without nestedPairs(), requiring the nested node to be specified twice, which is a maintenance burden.
```typescript
fromJson([{ id: '1', geometry: 'Point(1.1 2.2)' }]),
triple(iri(prefix.feature, 'id'), geo.hasGeometry, iri(prefix.geometry, 'id')),
pairs(iri(prefix.geometry, 'id'),
[a, geo.Geometry],
[geo.asWKT, literal('geometry', geo.wktLiteral)],
),
```
--------------------------------
### IRI prefix tree example with base IRI and prefix object
Source: https://docs.triply.cc/triply-etl/generic/declarations
Declares a base IRI, internal prefix nodes, and leaf prefixes in an object. This consolidates the IRI strategy for a dataset in one place.
```typescript
import { Iri } from '@triplyetl/etl/generic'
const baseIri = Iri('https://triplydb.com/my-account/my-dataset/')
const prefix_id = baseIri.concat('id/')
const prefix_model = baseIri.concat('model/')
const prefix = {
city: prefix_id.concat('city/'),
def: prefix_model.concat('def/'),
person: prefix_id.concat('person/'),
}
```
--------------------------------
### Resulting linked data assertions
Source: https://docs.triply.cc/triply-etl/assert/ratt/statements
Shows the 4 linked data assertions produced by the example above, with city:New%20York as subject and skos:altLabel predicates.
```turtle
city:New%20York
skos:altLabel
'The Big Apple'@en.
'The Capital of the World'@en,
'The City of Dreams'@en,
'The City That Never Sleeps'@en.
```
--------------------------------
### TriG graph notation equivalent
Source: https://docs.triply.cc/triply-etl/assert/ratt/statements
Shows the TriG notation that is structurally similar to the triples() example. It uses graph:metadata and graph:data blocks to assert the same statements.
```text
graph:metadata {
dataset:flowers a dcat:Dataset.
...
}
graph:data {
flower:123 a def:Flower.
...
}
```
--------------------------------
### Insert Data example with logQuads
Source: https://docs.triply.cc/triply-etl/enrich/sparql/update
Adds one triple to the Internal Store using SPARQL Update. The `logQuads()` function prints the store content to standard output.
```typescript
import { logQuads } from '@triplyetl/etl/debug'
import { Etl } from '@triplyetl/etl/generic'
import { update } from '@triplyetl/etl/sparql'
export default async function (): Promise {
const etl = new Etl()
etl.use(
update(`
base
insert data { . }`),
logQuads(),
)
return etl
}
```
```text
base
.
```
--------------------------------
### CSV example with quoted fields and empty values
Source: https://docs.triply.cc/triply-etl/extract/csv
Example CSV snippet showing quoted fields with commas and an empty trailing cell.
```CSV
ID,Name,Age
1,"Doe, John",32
2,"D., Jane ",
```
--------------------------------
### Run ETL with TriplyETL Runner
Source: https://docs.triply.cc/triply-etl/generic/getting-started
Use this command to run the ETL project with the TriplyETL Runner.
```bash
npx etl
```
--------------------------------
### uppercase() example: resulting linked data assertion
Source: https://docs.triply.cc/triply-etl/transform/ratt
The linked data assertion produced by the uppercase() example. It shows the transformed value 'NL' as the object of the triple.
```turtle
city:Amsterdam geonames:countryCode "NL"
```
--------------------------------
### Import external vocabularies (FOAF, OWL, PREMIS)
Source: https://docs.triply.cc/triply-etl/generic/declarations
Imports the FOAF, OWL, and PREMIS vocabularies from the TriplyETL vocabulary library. Required before using terms like foaf.Person or premis.File.
```typescript
import { foaf, owl, premis } from '@triplyetl/vocabularies'
```
--------------------------------
### Example JSON-LD from Wikipedia page of Ada Lovelace
Source: https://docs.triply.cc/triply-etl/extract/rdf
Example of JSON-LD linked data found on the Wikipedia page of Ada Lovelace. It includes schema.org context, type Article, and properties such as name, url, sameAs, author, publisher, and dates.
```json
{
"@context": "https://schema.org",
"@type": "Article",
"name": "Ada Lovelace",
"url": "https://en.wikipedia.org/wiki/Ada_Lovelace",
"sameAs": "http://www.wikidata.org/entity/Q7259",
"mainEntity": "http://www.wikidata.org/entity/Q7259",
"author": {
"@type": "Organization",
"name": "Contributors to Wikimedia projects"
},
"publisher": {
"@type": "Organization",
"name": "Wikimedia Foundation, Inc.",
"logo": {
"@type": "ImageObject",
"url": "https://www.wikimedia.org/static/images/wmf-hor-googpub.png"
}
},
"datePublished": "2001-05-20T14:57:05Z",
"dateModified": "2023-03-17T21:28:23Z",
"image": "https://upload.wikimedia.org/wikipedia/commons/0/0b/Ada_Byron_daguerreotype_by_Antoine_Claudet_1843_or_1850.jpg",
"headline": "1815-1852 British mathematician, considered the first computer programmer"
}
```
--------------------------------
### Destination.TriplyDb.rdf() with 'me' account
Source: https://docs.triply.cc/triply-etl/generic/changelog
Uses Destination.TriplyDb.rdf() with the 'me' account name.
```typescript
Destination.TriplyDb.rdf("me", datasetName)
```
--------------------------------
### Source data inline JSON
Source: https://docs.triply.cc/triply-etl/validate/shacl
The source data used in the example, recording the age of a person as a string.
```json
{
"age": "twelve",
"id": "id"
}
```
--------------------------------
### Key with dot
Source: https://docs.triply.cc/triply-etl/extract/json
Example key containing a dot. This key requires escaping when used in path expressions.
```json
"country.id"
```
--------------------------------
### Check for new TriplyETL versions with npm outdated
Source: https://docs.triply.cc/triply-etl/generic/maintenance
Prints the latest available TriplyETL version and other outdated dependencies.
```bash
npm outdated
```
--------------------------------
### Extract and log records from local XML file using fromXml()
Source: https://docs.triply.cc/triply-etl/generic/record
Uses the fromXml() extractor with Source.file('example.xml') to read the XML file and logRecord() to print each record. The output records are identical to those from the JSON source, demonstrating the generic Record format.
```TypeScript
import { Etl, fromXml, logRecord } from '@triplyetl/etl/generic'
export default async function (): Promise {
const etl = new Etl()
etl.use(
fromXml(Source.file('example.xml')),
logRecord(),
)
return etl
}
```
```JSON
{
"id": "123",
"name": "John",
"$recordId": 1,
"$environment": "Development"
}
{
"id": "456",
"name": "Jane",
"$recordId": 2,
"$environment": "Development"
}
```
--------------------------------
### when() with condition and multiple statements
Source: https://docs.triply.cc/triply-etl/generic/control-structures
Shows the general syntax of when() with a condition and multiple statements. The condition determines whether the remaining parameters are called.
```text
when('{condition}',
'{statement-1}',
'{statement-2}',
'{statement-3}',
// etc
),
```
--------------------------------
### Language-tagged string example
Source: https://docs.triply.cc/triply-etl/transform/ratt
Asserts a triple with a language-tagged string in the object position. The literal is created with a language tag and used in the triple.
```triply-etl
fromJson([{ name: 'London' }]),
addLiteral({
content: 'name',
language: language.en,
key: '_name',
}),
triple(iri(prefix.city, 'name'), skos.prefLabel, '_name'),
```
```turtle
city:London skos:prefLabel 'London'@en.
```
```triply-etl
fromJson([{ name: 'London' }]),
triple(iri(prefix.city, 'name'), skos.prefLabel, literal('name', lang['en'])),
```
--------------------------------
### Invalid literal with xsd:nonNegativeInteger
Source: https://docs.triply.cc/triply-etl/validate/shacl
An example of an invalid literal that TriplyETL will not allow to be asserted, as it would create incorrect linked data.
```turtle
'twelve'^^xsd:nonNegativeInteger
```
--------------------------------
### Validate with Source.string()
Source: https://docs.triply.cc/triply-etl/validate/shacl
Uses validate() with an in-line SHACL model via Source.string(). The model is the same as the previous example but embedded in a template literal.
```typescript
validate(Source.string(`
prefix foaf:
prefix rdf:
prefix sh:
prefix shp:
prefix xsd:
shp:Person
a sh:NodeShape;
sh:closed true;
sh:ignoredProperties ( rdf:type );
sh:property shp:Person_age;
sh:targetClass foaf:Person.
shp:Person_age
a sh:PropertyShape;
sh:datatype xsd:nonNegativeInteger;
sh:maxCount 1;
sh:minCount 1;
sh:path foaf:age.`
)),
```
--------------------------------
### Publish to local file with Destination.file()
Source: https://docs.triply.cc/triply-etl/publish
Use Destination.file() to write RDF output to a local file. This is useful when you lack an active Internet connection, though local files do not support browsing, querying, metadata, or prefix declarations like TriplyDB destinations do.
```javascript
toRdf(Destination.file('my-file.trig')),
```
--------------------------------
### Target data (informal) in Turtle
Source: https://docs.triply.cc/triply-etl/validate/shacl
The intended linked data output for the example, showing a foaf:Person with foaf:age 'twelve'.
```turtle
id:123
a foaf:Person;
foaf:age 'twelve'.
```
--------------------------------
### Publish to TriplyDB with toRdf()
Source: https://docs.triply.cc/triply-etl/publish
Legacy way to upload to TriplyDB using toRdf() with Destination.TriplyDb.rdf(). Still supported but simplified by toTriplyDb().
```javascript
toRdf(Destination.TriplyDb.rdf('my-account', 'my-dataset', {triplyDb: etl.triplyDb}))
```
--------------------------------
### nestedPairs() example: Geometry
Source: https://docs.triply.cc/triply-etl/assert/ratt/statements
Asserts a GeoSPARQL geometry using nestedPairs() with an explicit nested node. The geometry is created as a separate node.
```typescript
fromJson([{ id: '1', geometry: 'Point(1.1 2.2)' }]),
nestedPairs(iri(prefix.feature, 'id'), geo.hasGeometry, iri(prefix.geometry, 'id'),
[a, geo.Geometry],
[geo.asWKT, literal('geometry', geo.wktLiteral)],
),
```
--------------------------------
### forEach with logRecord() to observe $parent
Source: https://docs.triply.cc/triply-etl/generic/control-structures
Prints the iterated elements to the terminal using logRecord(). The output shows the $parent key containing the parent record.
```triply-etl
forEach('data.countries',
logRecord(),
),
```
--------------------------------
### Configure Comunica engine for construct()
Source: https://docs.triply.cc/triply-etl/generic/changelog
Explicitly configures the Comunica SPARQL engine for the construct() function. Use this to restore the previous default engine if the new Speedy engine causes issues in your ETL pipeline.
```TypeScript
import { construct } from '@triplyetl/etl/sparql'
construct(Source.TriplyDb.query('my-query'), { sparqlEngine: 'comunica' }),
```
--------------------------------
### String literal example
Source: https://docs.triply.cc/triply-etl/transform/ratt
Asserts a triple with a string literal in the object position. The literal is created from a record field and used directly in the triple.
```triply-etl
fromJson([{name: 'London'}]),
addLiteral({
content: 'name',
key: '_name',
}),
triple(iri(prefix.city, '_name'), skos.prefLabel, '_name')
```
```turtle
city:London sdo:name 'London'.
```
```triply-etl
fromJson([{ name: 'London' }]),
triple(iri(prefix.city, 'name'), skos.prefLabel, 'name'),
```
--------------------------------
### Records with $recordId special key
Source: https://docs.triply.cc/triply-etl/generic/record
Example records from a source table with no unique properties, showing the automatically added $recordId special key.
```json
{
"First name": "John",
"Last name": "Doe",
"$recordId": 1
}
{
"First name": "Jane",
"Last name": "Doe",
"$recordId": 2
}
{
"First name": "John",
"Last name": "Doe",
"$recordId": 3
}
```
--------------------------------
### Import fromXlsx and Source
Source: https://docs.triply.cc/triply-etl/extract/xlsx
Imports the fromXlsx extractor and Source class from the TriplyETL generic module.
```typescript
import { fromXlsx, Source } from '@triplyetl/etl/generic'
```