Created
January 11, 2025 19:26
-
-
Save benjaminaaron/222b041967973f62bb00a37bea2a110c to your computer and use it in GitHub Desktop.
prefixes in rdf.io.dataset.toText
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import rdf from "rdf-ext" | |
| import formatsPretty from "@rdfjs/formats/pretty.js" | |
| rdf.formats.import(formatsPretty) | |
| const person = rdf.namedNode('http://example.org/Person1') | |
| const name = rdf.namedNode('http://schema.org/name') | |
| const ds = rdf.dataset([ | |
| rdf.quad(person, name, rdf.literal('John')) | |
| ]) | |
| const prefixesMap = new Map([ | |
| ['ex', 'http://example.org/'], | |
| ['schema', 'http://schema.org/'] | |
| ]) | |
| let ttl = await rdf.io.dataset.toText('text/turtle', ds, { prefixes: prefixesMap }) | |
| console.log(ttl) | |
| const prefixesArr = [ | |
| ['ex', 'http://example.org/'], | |
| ['schema', 'http://schema.org/'] | |
| ] | |
| ttl = await rdf.io.dataset.toText('text/turtle', ds, { prefixes: prefixesArr }) | |
| console.log(ttl) | |
| /* | |
| The result does not have prefixes applied in both cases: | |
| <http://example.org/Person1> | |
| <http://schema.org/name> "John". | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "dependencies": { | |
| "rdf-ext": "^2.5.2" | |
| } | |
| } |
Author
This works:
const prefixesArr = [
['ex', rdf.namedNode('http://example.org/')],
['schema', rdf.namedNode('http://schema.org/')]
]
Author
Great, thanks a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with
node index.mjs