1.5.0 • Published 6 years ago

ntriples-collection v1.5.0

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

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

Kind: global function

ParamTypeDescription
filenamestringthe n-triples filename
functioncallbackcallback

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

ParamTypeDescription
filenamestringthe n-triples filename
triplesarrayan array of triples objects
functioncallbackcallback

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

ParamTypeDescription
triplesarrayan array of triples objects (subject is ignored)
predicatestringthe uri representing the predicate
defaultValueobjectthe 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

ParamTypeDescription
triplesarrayan array of triples objects (subject is ignored)
predicatestringthe uri representing the predicate
languagestringthe requested language
altLangsarrayan array of alternative languages (max 2)
defaultValueobjectthe 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

ParamTypeDescription
triplesarrayan array of triples objects (subject is ignored)
predicatestringthe uri representing the predicate

Example

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

License

MIT © Olivier Huin