{"id":19197882,"url":"https://github.com/flarebyte/ntriples-collection","last_synced_at":"2026-06-23T18:30:18.517Z","repository":{"id":65465930,"uuid":"86624160","full_name":"flarebyte/ntriples-collection","owner":"flarebyte","description":"Utility methods for filtering n-triples","archived":false,"fork":false,"pushed_at":"2018-08-14T17:38:39.000Z","size":142,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-04T14:45:19.699Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flarebyte.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-29T20:01:24.000Z","updated_at":"2018-08-14T17:38:41.000Z","dependencies_parsed_at":"2023-01-25T08:45:29.408Z","dependency_job_id":null,"html_url":"https://github.com/flarebyte/ntriples-collection","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarebyte%2Fntriples-collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarebyte%2Fntriples-collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarebyte%2Fntriples-collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarebyte%2Fntriples-collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flarebyte","download_url":"https://codeload.github.com/flarebyte/ntriples-collection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240271540,"owners_count":19774859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T12:19:09.204Z","updated_at":"2026-06-23T18:30:18.472Z","avatar_url":"https://github.com/flarebyte.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ntriples-collection\n\n[![NPM version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Coveralls Status][coveralls-image]][coveralls-url]\n[![Dependency Status][depstat-image]][depstat-url]\n[![Downloads][download-badge]][npm-url]\n\n\u003e Utility methods for filtering n-triples\n\nAssumptions:\n* You are using [node.js n3](https://github.com/RubenVerborgh/N3.js)\n* You are filtering small arrays of triples.\n* You are mostly interested in the object value.\n\n## Install\n\n```sh\nnpm i -D ntriples-collection\n```\n\n## Usage\n\n```js\nimport { readNTriplesFile,\n   writeNTriplesFile,\n   findObjectByPredicate,\n   findLocalizedObjectByPredicate,\n   findObjectsByPredicate,\n  } from \"ntriples-collection\"\n```\n### Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#readNTriplesFile\"\u003ereadNTriplesFile(filename, function)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eReads a n-triples file and converts it to an array of triples\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#writeNTriplesFile\"\u003ewriteNTriplesFile(filename, triples, function)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eSaves an array of triples in a n-triples file\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#findObjectByPredicate\"\u003efindObjectByPredicate(triples, predicate, defaultValue)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eFinds the first object value based on the predicate\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#findLocalizedObjectByPredicate\"\u003efindLocalizedObjectByPredicate(triples, predicate, language, altLangs, defaultValue)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eFinds the first object value based on the predicate and the language\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#findObjectsByPredicate\"\u003efindObjectsByPredicate(triples, predicate)\u003c/a\u003e ⇒ \u003ccode\u003earray\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eFinds all object values based on the predicate\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"readNTriplesFile\"\u003e\u003c/a\u003e\n\n### readNTriplesFile(filename, function)\nReads a n-triples file and converts it to an array of triples\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| filename | \u003ccode\u003estring\u003c/code\u003e | the n-triples filename |\n| function | \u003ccode\u003ecallback\u003c/code\u003e | callback |\n\n**Example**  \n```js\n// [\n{ graph: \"\",\nobject: '\"Flower corp\"@en',\npredicate: 'http://purl.org/dc/elements/1.1/publisher',\nsubject: 'http://www.site.org/version/123/'\n},\n]\nreadNTriplesFile('flowers.nt', (err, triples) =\u003e {\n console.log(triples);\n});\n```\n\u003ca name=\"writeNTriplesFile\"\u003e\u003c/a\u003e\n\n### writeNTriplesFile(filename, triples, function)\nSaves an array of triples in a n-triples file\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| filename | \u003ccode\u003estring\u003c/code\u003e | the n-triples filename |\n| triples | \u003ccode\u003earray\u003c/code\u003e | an array of triples objects |\n| function | \u003ccode\u003ecallback\u003c/code\u003e | callback |\n\n**Example**  \n```js\n// {count: 1}\n const triples = [\n{ graph: \"\",\nobject: '\"Flower corp\"@en',\npredicate: 'http://purl.org/dc/elements/1.1/publisher',\nsubject: 'http://www.site.org/version/123/'\n},\n]\nwriteNTriplesFile('flowers.nt', triples, (err, triples) =\u003e {\n console.log(triples);\n});\n```\n\u003ca name=\"findObjectByPredicate\"\u003e\u003c/a\u003e\n\n### findObjectByPredicate(triples, predicate, defaultValue) ⇒ \u003ccode\u003estring\u003c/code\u003e\nFinds the first object value based on the predicate\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - the string, integer, float, boolean, moment representing the literal value  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| triples | \u003ccode\u003earray\u003c/code\u003e | an array of triples objects (subject is ignored) |\n| predicate | \u003ccode\u003estring\u003c/code\u003e | the uri representing the predicate |\n| defaultValue | \u003ccode\u003eobject\u003c/code\u003e | the object/string to return if null |\n\n**Example**  \n```js\n// returns Amadeus\nfindObjectByPredicate(triples, 'http://purl.org/dc/elements/1.1/creator')\n```\n\u003ca name=\"findLocalizedObjectByPredicate\"\u003e\u003c/a\u003e\n\n### findLocalizedObjectByPredicate(triples, predicate, language, altLangs, defaultValue) ⇒ \u003ccode\u003estring\u003c/code\u003e\nFinds the first object value based on the predicate and the language\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - the string, integer, float, boolean, moment representing the literal value  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| triples | \u003ccode\u003earray\u003c/code\u003e | an array of triples objects (subject is ignored) |\n| predicate | \u003ccode\u003estring\u003c/code\u003e | the uri representing the predicate |\n| language | \u003ccode\u003estring\u003c/code\u003e | the requested language |\n| altLangs | \u003ccode\u003earray\u003c/code\u003e | an array of alternative languages (max 2) |\n| defaultValue | \u003ccode\u003eobject\u003c/code\u003e | the object/string to return if null |\n\n**Example**  \n```js\n// returns Amadeus\nfindLocalizedObjectByPredicate(triples, 'http://purl.org/dc/elements/1.1/creator', 'fr', ['en'])\n```\n\u003ca name=\"findObjectsByPredicate\"\u003e\u003c/a\u003e\n\n### findObjectsByPredicate(triples, predicate) ⇒ \u003ccode\u003earray\u003c/code\u003e\nFinds all object values based on the predicate\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003earray\u003c/code\u003e - of string, integer, float, boolean, moment representing the literal values  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| triples | \u003ccode\u003earray\u003c/code\u003e | an array of triples objects (subject is ignored) |\n| predicate | \u003ccode\u003estring\u003c/code\u003e | the uri representing the predicate |\n\n**Example**  \n```js\n// returns [Amadeus, Bach]\nfindObjectsByPredicate(triples, 'http://purl.org/dc/elements/1.1/creator')\n```\n\n\n## License\n\nMIT © [Olivier Huin](http://github.com/flarebyte)\n\n[npm-url]: https://npmjs.org/package/ntriples-collection\n[npm-image]: https://img.shields.io/npm/v/ntriples-collection.svg?style=flat-square\n\n[travis-url]: https://travis-ci.org/flarebyte/ntriples-collection\n[travis-image]: https://img.shields.io/travis/flarebyte/ntriples-collection.svg?style=flat-square\n\n[coveralls-url]: https://coveralls.io/r/flarebyte/ntriples-collection\n[coveralls-image]: https://img.shields.io/coveralls/flarebyte/ntriples-collection.svg?style=flat-square\n\n[depstat-url]: https://david-dm.org/flarebyte/ntriples-collection\n[depstat-image]: https://david-dm.org/flarebyte/ntriples-collection.svg?style=flat-square\n\n[download-badge]: http://img.shields.io/npm/dm/ntriples-collection.svg?style=flat-square\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflarebyte%2Fntriples-collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflarebyte%2Fntriples-collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflarebyte%2Fntriples-collection/lists"}