### Convert RDF Stream to Store Source: https://context7.com/jeswr/rdf-dereference-store.js/llms.txt Converts an RDFJS-compliant quad stream into an N3 Store with prefix extraction. This is useful for advanced scenarios where you have a custom quad stream. It also allows listening to stream events like discovered prefixes. ```typescript import { streamToStore } from 'rdf-dereference-store'; import { rdfDereferencer } from 'rdf-dereference'; // Get a quad stream from rdf-dereference const { data } = await rdfDereferencer.dereference('https://example.org/data.ttl'); // Convert stream to store const { store, prefixes } = await streamToStore(data); console.log(`Stream converted to store with ${store.size} triples`); console.log('Extracted prefixes:', prefixes); // Listen to stream events data.on('prefix', (prefix, namespace) => { console.log(`Prefix discovered: ${prefix} -> ${namespace}`); }); ``` -------------------------------- ### Dereference RDF from URL into N3 Store (TypeScript) Source: https://context7.com/jeswr/rdf-dereference-store.js/llms.txt Fetches an RDF document from a remote URL and loads its triples into an N3 Store. It automatically handles content negotiation and returns the populated store along with a map of namespace prefixes. No external dependencies are needed beyond the library itself. ```typescript import dereference from 'rdf-dereference-store'; // Fetch a remote RDF document const { store, prefixes } = await dereference('https://www.jeswr.org/#me'); // Access triples in the store console.log(`Store contains ${store.size} triples`); for (const quad of store) { console.log(`${quad.subject.value} ${quad.predicate.value} ${quad.object.value}`); } // Use prefixes for compact URI representation console.log('Available prefixes:', prefixes); // Output: { foaf: 'http://xmlns.com/foaf/0.1/', schema: 'http://schema.org/', ... } ``` -------------------------------- ### Dereference RDF from Local File into N3 Store (TypeScript) Source: https://context7.com/jeswr/rdf-dereference-store.js/llms.txt Loads an RDF document from a local file path into an N3 Store. This functionality is enabled by setting the `localFiles` option to true. It returns the populated store and a map of prefixes extracted from the file. Requires the file to be accessible on the local filesystem. ```typescript import dereference from 'rdf-dereference-store'; // Fetch from a local file const { store, prefixes } = await dereference('/path/to/file.ttl', { localFiles: true }); console.log(`Loaded ${store.size} triples from local file`); console.log('Prefixes:', prefixes); // Output: { ex: 'http://example.org/' } // Query the store const matches = store.getQuads(null, null, null, null); matches.forEach(quad => { console.log(quad.subject.value, quad.predicate.value, quad.object.value); }); ``` -------------------------------- ### Dereference Local RDF File to Store (JavaScript) Source: https://github.com/jeswr/rdf-dereference-store.js/blob/main/README.md Loads an RDF dataset from a local file path into a store. This option is useful for accessing local RDF data. It requires the 'rdf-dereference-store' library and the 'localFiles' option to be set to true. ```typescript import dereference from 'rdf-dereference-store'; // Fetch store from a local document const { store } = await dereference('/path/to/file.ttl', { localFiles: true }); ``` -------------------------------- ### Dereference Remote RDF Data to Store (JavaScript) Source: https://github.com/jeswr/rdf-dereference-store.js/blob/main/README.md Fetches an RDF dataset from a remote URL and loads it into a store. This method handles HTTP requests and content negotiation. It requires the 'rdf-dereference-store' library. ```typescript import dereference from 'rdf-dereference-store'; // Fetch store from a remote document const { store } = await dereference('https://www.jeswr.org/#me'); ``` -------------------------------- ### Parse RDF String to Store (JavaScript) Source: https://github.com/jeswr/rdf-dereference-store.js/blob/main/README.md Loads an RDF dataset directly from a string into a store. This is suitable for smaller RDF datasets or when data is already in memory. It requires the 'rdf-dereference-store' library and specifying the 'contentType'. ```typescript import fs from 'fs'; import { parse } from 'rdf-dereference-store'; // Fetch store from an input string const { store } = await parse(fs.readFileSync('/path/to/file.ttl').toString(), { contentType: 'text/turtle' }); ``` -------------------------------- ### Parse RDF Stream to Store (JavaScript) Source: https://github.com/jeswr/rdf-dereference-store.js/blob/main/README.md Parses an RDF dataset from an input stream into a store. This is efficient for large datasets or streaming data. It requires the 'rdf-dereference-store' library and specifying the 'contentType'. ```typescript import fs from 'fs'; import { parse } from 'rdf-dereference-store'; // Fetch store from an input stream const { store } = await parse(fs.createReadStream('/path/to/file.ttl'), { contentType: 'text/turtle' }); ``` -------------------------------- ### Dereference Multiple RDF Sources into a Combined N3 Store (TypeScript) Source: https://context7.com/jeswr/rdf-dereference-store.js/llms.txt Fetches multiple RDF documents from an array of URLs and/or local file paths simultaneously. All data is loaded into a single, merged N3 Store. The function returns the combined store and a merged map of all prefixes found across the sources. Requires the `@rdfjs/data-model` package for creating NamedNodes. ```typescript import dereference from 'rdf-dereference-store'; import path from 'path'; // Fetch multiple documents at once const { store, prefixes } = await dereference([ 'https://example.org/person1.ttl', 'https://example.org/person2.ttl', '/local/data/person3.ttl' ], { localFiles: true }); console.log(`Combined store contains ${store.size} triples from all sources`); // All prefixes from all documents are merged console.log('Merged prefixes:', prefixes); // Query across all loaded documents const namedNode = require('@rdfjs/data-model').namedNode; const matches = store.getQuads( null, namedNode('http://xmlns.com/foaf/0.1/knows'), null, null ); console.log(`Found ${matches.length} "knows" relationships`); ``` -------------------------------- ### Dereference RDF to Store using Named Export (TypeScript) Source: https://context7.com/jeswr/rdf-dereference-store.js/llms.txt Provides an alternative named export `dereferenceToStore` which offers the exact same functionality as the default export. This is useful for explicit imports or when avoiding default import syntax. It dereferences RDF data and loads it into an N3 Store, returning the store and prefixes. ```typescript import { dereferenceToStore } from 'rdf-dereference-store'; const { store, prefixes } = await dereferenceToStore( 'https://example.org/data.ttl' ); // Same functionality as default export console.log(store.size); console.log(prefixes); ``` -------------------------------- ### TypeScript Interface for RDF Data Source: https://context7.com/jeswr/rdf-dereference-store.js/llms.txt Defines the return type of dereferencing and parsing functions, providing type safety for the store and prefixes objects. This interface, StoreAndPrefixes, ensures that the structure of the returned RDF data is predictable. ```typescript import type { StoreAndPrefixes } from 'rdf-dereference-store'; import dereference from 'rdf-dereference-store'; async function loadRdfData(url: string): Promise { const result = await dereference(url); // TypeScript knows the structure const store: DatasetCore = result.store; const prefixes: Record = result.prefixes; return { store, prefixes }; } // Use in application const data = await loadRdfData('https://example.org/data.ttl'); console.log(`Loaded ${data.store.size} triples`); console.log(`With prefixes: ${Object.keys(data.prefixes).join(', ')}`); ``` -------------------------------- ### Parse RDF File Content Source: https://context7.com/jeswr/rdf-dereference-store.js/llms.txt Parses RDF content that has been read into memory. Useful for preprocessing file content before parsing or when working with RDF data from non-file sources. It supports various RDF formats based on the provided contentType. ```typescript import fs from 'fs'; import { parse } from 'rdf-dereference-store'; // Read file content and parse const fileContent = fs.readFileSync('/path/to/file.ttl').toString(); const { store, prefixes } = await parse(fileContent, { contentType: 'text/turtle' }); console.log(`Loaded ${store.size} triples`); console.log('Prefixes:', prefixes); // Supports various RDF formats const rdfXmlContent = fs.readFileSync('/path/to/file.rdf').toString(); const xmlResult = await parse(rdfXmlContent, { contentType: 'application/rdf+xml' }); console.log(`RDF/XML: ${xmlResult.store.size} triples`); ``` -------------------------------- ### Parse RDF from Stream or String into N3 Store (TypeScript) Source: https://context7.com/jeswr/rdf-dereference-store.js/llms.txt Parses RDF data directly from a readable stream or a string without performing dereferencing. This requires explicit specification of the content type. It's ideal for handling RDF data already available in memory or from a stream. Returns the populated N3 Store and a map of prefixes. ```typescript import fs from 'fs'; import { parse } from 'rdf-dereference-store'; // Parse from a readable stream const { store, prefixes } = await parse( fs.createReadStream('/path/to/file.ttl'), { contentType: 'text/turtle' } ); console.log(`Parsed ${store.size} triples`); console.log('Prefixes:', prefixes); // Parse from a string const rdfString = ` @prefix ex: . ex:subject ex:predicate ex:object . `; const result = await parse(rdfString, { contentType: 'text/turtle' }); console.log(`String parsing: ${result.store.size} triples`); // Output: String parsing: 1 triples ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.