Skip to content

flarebyte/ntriples-collection

Repository files navigation

ntriples-collection

NPM version Build Status Coveralls Status Dependency Status Downloads

Utility methods for filtering n-triples

Assumptions:

  • You are using node.js n3
  • You are filtering small arrays of triples.
  • You are mostly interested in the object value.

Install

npm i -D ntriples-collection

Usage

import { readNTriplesFile,
   writeNTriplesFile,
   findObjectByPredicate,
   findLocalizedObjectByPredicate,
   findObjectsByPredicate,
  } from "ntriples-collection"

Functions

readNTriplesFile(filename, function)

Reads a n-triples file and converts it to an array of triples

writeNTriplesFile(filename, triples, function)

Saves an array of triples in a n-triples file

findObjectByPredicate(triples, predicate, defaultValue)string

Finds the first object value based on the predicate

findLocalizedObjectByPredicate(triples, predicate, language, altLangs, defaultValue)string

Finds the first object value based on the predicate and the language

findObjectsByPredicate(triples, predicate)array

Finds all object values based on the predicate

readNTriplesFile(filename, function)

Reads a n-triples file and converts it to an array of triples

Kind: global function

Param Type Description
filename string the n-triples filename
function callback callback

Example

// [
{ graph: "",
object: '"Flower corp"@en',
predicate: 'http://purl.org/dc/elements/1.1/publisher',
subject: 'http://www.site.org/version/123/'
},
]
readNTriplesFile('flowers.nt', (err, triples) => {
 console.log(triples);
});

writeNTriplesFile(filename, triples, function)

Saves an array of triples in a n-triples file

Kind: global function

Param Type Description
filename string the n-triples filename
triples array an array of triples objects
function callback callback

Example

// {count: 1}
 const triples = [
{ graph: "",
object: '"Flower corp"@en',
predicate: 'http://purl.org/dc/elements/1.1/publisher',
subject: 'http://www.site.org/version/123/'
},
]
writeNTriplesFile('flowers.nt', triples, (err, triples) => {
 console.log(triples);
});

findObjectByPredicate(triples, predicate, defaultValue) ⇒ string

Finds the first object value based on the predicate

Kind: global function
Returns: string - the string, integer, float, boolean, moment representing the literal value

Param Type Description
triples array an array of triples objects (subject is ignored)
predicate string the uri representing the predicate
defaultValue object the object/string to return if null

Example

// returns Amadeus
findObjectByPredicate(triples, 'http://purl.org/dc/elements/1.1/creator')

findLocalizedObjectByPredicate(triples, predicate, language, altLangs, defaultValue) ⇒ string

Finds the first object value based on the predicate and the language

Kind: global function
Returns: string - the string, integer, float, boolean, moment representing the literal value

Param Type Description
triples array an array of triples objects (subject is ignored)
predicate string the uri representing the predicate
language string the requested language
altLangs array an array of alternative languages (max 2)
defaultValue object the object/string to return if null

Example

// returns Amadeus
findLocalizedObjectByPredicate(triples, 'http://purl.org/dc/elements/1.1/creator', 'fr', ['en'])

findObjectsByPredicate(triples, predicate) ⇒ array

Finds all object values based on the predicate

Kind: global function
Returns: array - of string, integer, float, boolean, moment representing the literal values

Param Type Description
triples array an array of triples objects (subject is ignored)
predicate string the uri representing the predicate

Example

// returns [Amadeus, Bach]
findObjectsByPredicate(triples, 'http://purl.org/dc/elements/1.1/creator')

License

MIT © Olivier Huin

About

Utility methods for filtering n-triples

Resources

License

Stars

Watchers

Forks

Packages

No packages published