https://github.com/flarebyte/ntriples-collection
Utility methods for filtering n-triples
https://github.com/flarebyte/ntriples-collection
Last synced: over 1 year ago
JSON representation
Utility methods for filtering n-triples
- Host: GitHub
- URL: https://github.com/flarebyte/ntriples-collection
- Owner: flarebyte
- License: other
- Created: 2017-03-29T20:01:24.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-14T17:38:39.000Z (almost 8 years ago)
- Last Synced: 2025-02-04T14:45:19.699Z (over 1 year ago)
- Language: JavaScript
- Size: 139 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ntriples-collection
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coveralls Status][coveralls-image]][coveralls-url]
[![Dependency Status][depstat-image]][depstat-url]
[![Downloads][download-badge]][npm-url]
> Utility methods for filtering n-triples
Assumptions:
* You are using [node.js n3](https://github.com/RubenVerborgh/N3.js)
* You are filtering small arrays of triples.
* You are mostly interested in the object value.
## Install
```sh
npm i -D ntriples-collection
```
## Usage
```js
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**
```js
// [
{ 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**
```js
// {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**
```js
// 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**
```js
// 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**
```js
// returns [Amadeus, Bach]
findObjectsByPredicate(triples, 'http://purl.org/dc/elements/1.1/creator')
```
## License
MIT © [Olivier Huin](http://github.com/flarebyte)
[npm-url]: https://npmjs.org/package/ntriples-collection
[npm-image]: https://img.shields.io/npm/v/ntriples-collection.svg?style=flat-square
[travis-url]: https://travis-ci.org/flarebyte/ntriples-collection
[travis-image]: https://img.shields.io/travis/flarebyte/ntriples-collection.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/flarebyte/ntriples-collection
[coveralls-image]: https://img.shields.io/coveralls/flarebyte/ntriples-collection.svg?style=flat-square
[depstat-url]: https://david-dm.org/flarebyte/ntriples-collection
[depstat-image]: https://david-dm.org/flarebyte/ntriples-collection.svg?style=flat-square
[download-badge]: http://img.shields.io/npm/dm/ntriples-collection.svg?style=flat-square