Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rdf-assets

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rdf-assets

A bunch of utilities to inspect RDF files, a wrapper.

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

rdf-assets

A bunch of utilities to inspect RDF files, a wrapper.

Examples

Say you have a bunch of RDF files in various formats scattered throughout a directory tree.

Bundle in TRIG

Then you can gather and bundle these files into TRIG format by utilizing a glob pattern.

import { getAssets, toFile, TRIG } from '../index.js'

const prefixes = { 'ex': 'http://example.org/' }

const assets = await getAssets({ globPattern: './examples/data/**/*' })

await toFile(assets, 'bundle.trig', { format: TRIG, prefixes })

Do SPARQL SELECT

Or you can use SPARQL to query these files:

import { createTriplestore, doSelect, getAssets } from '../index.js'

const assets = await getAssets({ globPattern: './examples/**/*.{ttl,rdf}' })

const store = await createTriplestore({ assets })

const query = `
prefix foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?s ?name
WHERE {
  graph ?g {
       ?s foaf:name ?name .
  }
}
`

const rows = doSelect({ store, query })
console.log(rows)

/**
 * Outputs
 [
     {
         s: NamedNode { value: 'http://example.org/Alice' },
         name: Literal { value: 'Alice', language: '', datatype: [NamedNode] }
     },
     {
         s: NamedNode { value: 'http://example.org/Bob' },
         name: Literal { value: 'Bob', language: '', datatype: [NamedNode] }
     }
 ]
 */

Do SPARQL CONSTRUCT

Or display the results of a CONSTRUCT serialized in turtle

import {
  createTriplestore,
  doConstruct,
  getAssets,
  prettyPrintTurtle,
} from '../index.js'

const assets = await getAssets({ globPattern: './examples/**/*' })

const store = await createTriplestore({ assets })

const query = `
prefix foaf: <http://xmlns.com/foaf/0.1/>

CONSTRUCT {
  ?s ?p ?o
}
WHERE {
  graph ?g {
       ?s a foaf:Person .
       ?s ?p ?o .
  }
}
`

const dataset = doConstruct({ store, query })
const str = await prettyPrintTurtle({ dataset })
console.log(str)

/**
 * <http://example.org/Alice> a <http://xmlns.com/foaf/0.1/Person> ;
 *         <http://xmlns.com/foaf/0.1/knows> <http://example.org/Bob> ;
 *         <http://xmlns.com/foaf/0.1/name> "Alice" .
 *
 * <http://example.org/Bob> a <http://xmlns.com/foaf/0.1/Person> ;
 *         <http://xmlns.com/foaf/0.1/name> "Bob" ;
 *         <http://example.org/likes> <http://example.org/Alice> .
 */

See examples for details

This uses RDF JavaScript Libraries and oxygraph as in-memory triplestore.

FAQs

Package last updated on 21 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc