Created
August 3, 2020 00:19
-
-
Save jaxoncreed/34f09213779be9da2e929185ede7cd54 to your computer and use it in GitHub Desktop.
This file contains 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
export default async function getChatMessages(chatUrl) { | |
// ... | |
// Create RDFJS dataset | |
const dataset = await new Promise((resolve, reject) => { | |
const dataset = Dataset(); | |
const parserN3 = new ParserN3({ baseIRI: dataUrl }) | |
const input = new Readable({ | |
read: () => { | |
input.push(chatTtl) | |
input.push(null) | |
} | |
}) | |
const output = parserN3.import(input) | |
output.on('data', quad => { | |
dataset.add(quad) | |
}) | |
output.on('prefix', (prefix, ns) => { | |
// console.log(`prefix: ${prefix} ${ns.value}`) | |
}) | |
output.on('end', () => { | |
resolve(dataset) | |
}) | |
}) | |
// Use clownface to extract desired data | |
const FLOW_MESSAGE = namedNode("http://www.w3.org/2005/01/wf/flow#message"); | |
const CONTENT = namedNode("http://rdfs.org/sioc/ns#content"); | |
const MAKER = namedNode("http://xmlns.com/foaf/0.1/maker"); | |
const chatNode = cf({ dataset }).namedNode(nodeUrl); | |
const messages = chatNode.out(FLOW_MESSAGE).map((messageNode) => { | |
return { | |
nodeName: messageNode.value, | |
author: messageNode.out(MAKER).value, | |
content: messageNode.out(CONTENT).value | |
} | |
}) | |
return messages | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment