GithubHelp home page GithubHelp logo

Prefix events about rdf-parse.js HOT 4 CLOSED

pietercolpaert avatar pietercolpaert commented on June 26, 2024 1
Prefix events

from rdf-parse.js.

Comments (4)

rubensworks avatar rubensworks commented on June 26, 2024

Good idea, should be easy to implement.
In theory the only thing that we'd need to do is forward the prefix events from Comunica's quad stream and delegate it to our readable.

from rdf-parse.js.

fvitali avatar fvitali commented on June 26, 2024

I am not sure what is going on: if it is my implementation error, or there is still something missing: I can already get working callbacks for the "prefix" and the "context" events (json+ld of course), but they seem to have no parameters specified:

rdfParser.parse(textStream, { contentType: syntax }) 
		.on('prefix', (a) => { console.log(a) })
		.on('context', (b) => {  console.log(b) })
		.on('data', (quad) => { data.push(quad) })
		.on('error', (e) => { reject({ error: e} ) })
		.on('end', () => { resolve({quads: data}) 

both functions get executed, and both print "undefined" on the console.

Can you help?

from rdf-parse.js.

rubensworks avatar rubensworks commented on June 26, 2024

@fvitali I'm surprised that prints anything to be honest.
In any case, this feature is not implemented yet, so it's normal that it's not working as intended.

You're welcome to submit a PR though! :-)

from rdf-parse.js.

fvitali avatar fvitali commented on June 26, 2024

I submitted two separate Pull requests, one here and another on N3.js, to fully enable support for prefix and context callbacks.

I am not really sure about the N3.js, as I was not able to fully follow the complex chain of required module. Anyway, this now works for me.

Working code:

	async function parseRDF(text, syntax) {			
			const textStream = streamify(text+"");

			try {
				var d = await new Promise( (resolve, reject) => {
					var data = []
					rdfParser.parse(textStream, { 
						contentType: syntax })
							.on('prefix', (prefix,iri) => {
								console.log(prefix)
							})
							.on('context', (c) => { 
								console.log(c)
							 })
							.on('data', (quad) => { data.push(quad) })
							.on('error', (e) => { 
								reject( e ) 
							})
							.on('end', () => { 
								resolve({quads: data}) 
							} );

				})
				return d
			} catch (e) {
				return { error: e}
			}
	}

from rdf-parse.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.