Code Monkey home page Code Monkey logo

n3.js's People

Contributors

alxflam avatar bergos avatar dependabot[bot] avatar dhurlburtusa avatar elf-pavlik avatar gremid avatar hzuo avatar iddan avatar jacoscaz avatar jeswr avatar jimsmart avatar jitsedesmet avatar laurensrietveld avatar martinmaillard avatar mimfa avatar mpvharmelen avatar noeldemartin avatar pheyvaer avatar pietercolpaert avatar royludo avatar rubensworks avatar rubenverborgh avatar rubenw avatar simonvbrae avatar sroze avatar svirgilgood avatar tpt avatar vinnl avatar warpr avatar westurner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

n3.js's Issues

Problem with lang tag?

Regular expressions contain U+FFFD (encoding issue?)

The regular expressions in lib/n3lexer.js contain a number of U+FFFD REPLACEMENT CHARACTER symbols that aren’t supposed to be there (at least not as far as I can tell).

You can easily confirm the issue using a hex viewer or even on the GitHub website itself: Look for the “�” marks.

I’m guessing something went wrong when copying/pasting the regular expressions from inimino’s tool, or perhaps the file was at some point saved using a non-UTF-8 encoding, or perhaps Git/GitHub messed it up at some point…

Anyway, a solution could be to use escape sequences for those characters so that they don’t get replaced by U+FFFD, so that the original symbol isn’t lost.

"constructor" for RDF terms

N3.Util already provides utility functions to unfold the internal representation for RDF terms.

It would be very useful to have their counterparts, so that we could construct such elements e.g. makeLiteral("3", "http://www.w3.org/2001/XMLSchema#integer"), makeLiteral(3), makeUri("http://example.org/cartoons#Mickey"), etc.

Add version number inside compiled source files

Please add the version number inside the library files. Can be very help full for debugging purposes.
Either as simple comment on top of the file. Or also as an property which can be accessed inside the JavaScript context.

Resolve URLs with parent paths (../)

URLs with parent paths are not correctly resolved:

var parser = require('n3').Parser();
parser.parse('@base <http://example.org/foo/bar/../foo/bar/>.\n<#a> <b> <../c/d/e>.',
             function (error, triple) { triple && console.log(triple); });

Can not parse some IRIs which contain whitespace

Hi RubenVerborgh,

I found another problem maybe.
When I parse the following turtle

<http://xxx.com/res/font/weblysleekui/WeblySleek UI Normal.ttf> <http://xxx.com/Predicate#cacheControl> "private, max-age=604800" .

I get this error

[Error: Syntax error: unexpected "<http://collectit.invend.eu/res/font/weblysleekui/WeblySleek" on line 1.]

I think it's the reason that IRI of subject has a whitespace. However, I'm sure the whitespace is allowed in json-ld

Could you also test with that case?

Bg,
Kevin

Parse error when using browser version of N3.js

Hello Ruben,

I ran into an issue today where the browserified version of N3.js fails to parse a file, but the "normal" N3.js has no trouble with that file.

The browserified version of N3 fails to parse this in Firefox, Chrome and under node.js, so it doesn't seem like a browser specific issue.

I'm testing with a reasonably large file (64577 triples). Could this be a bug or am I running into a limitation of the browserify environment?

The stack trace I get is:

Syntax error: unexpected ""To" on line 9873.
    at Object.N3Lexer._syntaxError (/home/warp/www/n3/node_modules/n3/browser/n3-browser.js:415:12)
    at reportSyntaxError (/home/warp/www/n3/node_modules/n3/browser/n3-browser.js:382:54)
    at Object.N3Lexer._tokenizeToEnd (/home/warp/www/n3/node_modules/n3/browser/n3-browser.js:230:20)
    at Object._onImmediate (/home/warp/www/n3/node_modules/n3/browser/n3-browser.js:430:38)
    at processImmediate [as _immediateCallback] (timers.js:336:15)

I have a test case at https://gist.github.com/warpr/c4da9a48b9cb8f11a550 , "test.html" shows the bug in a browser, "test.js" shows it under node.js.

If I truncate the licensedb.2014-01-19.ttl file slightly before the syntax error there is no trouble and I can query the N3 Store as I'd expect.

missing breaks in switches

908   _readPunctuation: function (token) {
909     var next, subject = this._subject, graph = this._graph;
910     switch (token.type) {
911     // A closing brace ends a graph
912     case '}':
913       if (this._graph === null)
914         return this._error('Unexpected graph closing', token);
915       this._graph = null;
916     // A dot just ends the statement, without sharing anything with the next.
917     case '.':

I'm still investigating, but I think there should be a 'break' after 915, and that the effect of falling through may be a null triple getting sent to parse()'s callback.

There are some other cases of unexpected fallthroughs too, like this:

    930     case 'IRI':
    931       if (this._supportsQuads && this._graph === null) {
...
    938         break;
    939       }
    941     case 'prefixed':

If 938/939 are really in the right order, I recommend a comment noting that you meant that logic.

Removing angular brackets from types causes module error

Hello,

I recently found you made an update for removing angular brackets from types in this commit
70fff5d

I do not understand why it must be done like this. It's the new literal syntax from turtle or n3? I think this modification will be incompatible with lots of other modules.

Bg,
Kevin

Counting the number of individuals/entities

Hi Ruben,

This is very much secondary but while putting my nose into the lib's code for the removal of triples, I was looking at the index mapping entities to numbers and I thought it could be nice to have another kind of size public method to get the number of individuals in the store. It's an info I often need. So far, I am using the following code to get it:

var uu = require('underscore');
countTypedIndividuals : function() {
    /* return the number of unique typed (with rdf:type) individuals in the store */
    return uu.uniq(store.find(null, 'rdf:type', null)).length;
}

But I feel this could be done much faster internally to N3.js by returning the length of the entities index. I am not sure about this though. What do you think?

Update or remove triples

Hi Ruben,

I'm finally working on integrating N3.js to our framework. Just wondering if there are ways to update and/or remove triples from the store? Can't seem to find that...

Thanks,
Thibaut.

Node.js stream support

I am trying to "wire" this library into LevelGraph, but I am facing a big issue regarding the 'streaming' interface.
In fact, most of LeveGraph is built on top node's streams and I finding extremely difficult to pipe the parse method into another stream. I am using: https://github.com/mcollina/node-levelgraph#putting-and-deleting-through-streams

In order to be compliant to node's stream, the parser should be exposed with Transform or with Through. The first requires the https://github.com/isaacs/readable-stream package to be run on node v0.8.x.

I am also linking the Stream Handbook for reference.

This is the behaviour we might want to achieve:

fs.createReadStream("a file").pipe(new n3.ParserStream()).pipe(someOtherStream)

Perform prefix expansion in writer

The writer supports prefixes in its output, but the addTriple method expects full IRIs. It would be nice if the writer also accepted prefixed names (like the store currently does).

Raised by @iherman.

Allow synchronous string parsing

Hi,

It is not really an issue, but I didn't find better place to ask. I'm going to ask very stupid question, but maybe you have any suggestions :)

Is it possible to parse turtle with N3.js synchronously? I'm trying to use ES6 taged template strings for turtle parsing. E.g something like this:

const res = turtle`<http://example.com/A> a <http://example.com/B> .`

so turtle function needs to parse content in synchronous way.

LevelGraph

I have recently released LevelGraph, which is a graph database built on Hexastore.

The interesting thing about it is that in can be persisted on disk using LevelDB, and in a near future on top of IndexedDB.

Do you think it might be hard to integrate it with node-n3?

Add utility for writing URLs through prefixes

Instead of

var hydra = 'http://www.w3.org/ns/hydra/core#';

var triple = { subject: 'x', object: hydra + 'property', predicate: hydra + 'freetextQuery' }

we could have

var hydra = N3Util.prefix('http://www.w3.org/ns/hydra/core#');

var triple = { subject: 'x', object: hydra('property'), predicate: hydra('freetextQuery') };

in which each of the generated URLs would be cached.

Furthermore, we could have

var prefixes = N3Util.prefixes();
prefixes('hydra', 'http://www.w3.org/ns/hydra/core#');

var hydra = prefixes('hydra');
var property1 = hydra('property');
var property2 = prefixes('hydra')('property');

where

N3Util.prefix = function (uri) { return N3Util.prefixes({ '': uri })(''); }

Make browserify-compatible

From @sandhawke:

When I browserify my code, which require's './n3', the result doesn't include N3Parser because of your 'lazy' inclusion technique in N3.js. As a workaround for now I changed that file to...

module.exports.Parser = require('./lib/N3Parser');
module.exports.Lexer = require('./lib/N3Lexer');
module.exports.Util = require('./lib/N3Util');

...and now it works for me.

C implementation of rdf2hdt fails when reading triples from N3.Writer

This is actually a bug of the C implementation, rather than the N3.Writer; but maybe we can make a small change in the N3.Writer and get rid of the problem.
Basically, rdf2hdt fails whenever the final dot in each triple in N-triples format does not have a space before it.

e.g.: The following line errors out:

<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://purl.org/dc/terms/title> "N-Triples"@en-us.

While the following one doesn't:

<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://purl.org/dc/terms/title> "N-Triples"@en-us .

Note the whitespace between the object and the finishing ..
Would you want to add it? I can make a pull request with it, if you think it's fine.
Best

P.

`setImmediate` shim causes performance degradation with many invocations of parse

I have an application where a great many ttl fragments are read from file and parsed one after the other. Each parse call runs through the setImmediate shim in the browser version:
var immediately = typeof setImmediate === 'function' ? setImmediate :
function setImmediate(func) { setTimeout(func, 0);};
However, even though the timeout is set to 0 this does not mean that func is evaluated immediately. In my case, with thousands of fragments thus handled, this adds up to many seconds of idleness. There are faster ways of doing this, see e.g. http://ajaxian.com/archives/settimeout-delay, which depends on window.postmessage. Using this reduced the load time in my application from about 25 to 5 seconds (load time is not just N3 parsing).
And to satisfy my curiosity: what is the reason for including this source of asynchronicity?
Thanks,
Joop

Add browser compatibility

Hi Ruben and thanks for this work.

Until now i was able to use node-n3 directly in the browser with just a few modifications.
But as now you use node.js stream, ...
I think it is not possible anymore.

What do you think about using node-n3 in the browser ?

Many thanks,

Samuel

Add Turtle serializer

In the first release of LevelGraph-N3 I have written a Stream for generating N3. It is far from being perfect, but if you need it we can move it in this package.

vows fail on node 0.10.x

When running "npm test" the vows test is failing.

Running vows with verbose shows:

vows bin argv []
vows bin options {
    reporter: 'dot-matrix',
    matcher: /.*/
}
vows bin discovering folder structure
vows bin discovered ./test
vows runner loading [ '/home/warp/code/node-n3/test/n3lexer-test', '/home/warp/code/node-n3/test/n3parser-test', '/home/warp/code/node-n3/test/n3store-test' ]
vows runner running N3Lexer ✗ Errored » 1 errored

Parallel N3 parsing with parser as singleton can result in input 'null' in N3 lexer, exception

I am parsing large N3 files in parallel. I've noticed that sometimes when two files are being parsed in parallel or close to at the same time, I will get the following unhandled error:

          firstChar = input[0], match = null, matchLength = 0, unescaped, inco
                           ^
TypeError: Cannot read property '0' of null
    at Object.N3Lexer._tokenizeToEnd (/devhomes/wboyd/atk-proxy/node_modules/n3/lib/N3Lexer.js:98:28)
    at Immediate._onImmediate (/devhomes/wboyd/atk-proxy/node_modules/n3/lib/N3Lexer.js:331:38)
    at processImmediate [as _immediateCallback] (timers.js:358:17)

I believe this happens because this._input inside the N3Lexer can change to null after parsing. I think this is only happening because I am using the N3Parser as a singleton instead of creating an N3Parser for each parsing job. I am not sure if this is a bug, since the workaround is just to create an instance of the N3Parser for each parsing job, which is fine for my case, but I figured I would report it.

License

Please add a license file and/or licensing information to readme. Thanks!

Extend prefix usage in N3Writer

Apparently, N3 does not support the complete set of allowed characters in prefix handling.
For example if we have the URL http://example.org/graphs#_0, we expect it to shorten it to g:_0 if we have the prefix g: <http://example.org/graphs#>.
Unfortunately, it does not do this, while the Turtle spec says that it should, including support for a bunch of other special characters.

In my fork, I added full support for this with the purpose of sending a PR, but while executing the tests I ran into an interesting issue.

The Turtle spec shows that prefixed entities like g:123 are not allowed, they should start with a character or something similar, and there are unit tests in this repo to confirm this behaviour.
Then I discovered that the nameStartChar also allows a character from the range [#x10000-#xEFFFF], and apparently this range includes a lot of characters.

If you would open up a node console and execute

/[\u10000-\uEFFFF]/.test("1")

You would see that it accepts all numbers (including a lot of other special characters as well).
So I am not sure if this specific range is intended to include numbers, if so, this would require some changes in the unit tests.
I assume this is a mistake in the spec, because for example the term nameChar explicitly accepts the range [0-9], even though it was already accepted by the range [#x10000-#xEFFFF].

Possible issue with dot

I tried updating levelgraph-n3 to latest version of n3.js, when running this test
https://github.com/mcollina/levelgraph-n3/blob/3d3b6d64ea0b028dc9195633d6553e2920252237/test/putStream_spec.js

I started getting

 1) n3.putStream should store some triples:
     Error: Expected punctuation to follow "http://example.org/cartoons#Cat.c:Jerry" at line 1.
      at Object.N3Parser._error (/cache/code/maintain/levelgraph-n3/node_modules/n3/lib/N3Parser.js:457:20)
      at Object.N3Parser._readPunctuation (/cache/code/maintain/levelgraph-n3/node_modules/n3/lib/N3Parser.js:382:19)
...

Adding in test fixture a white space before . (after c:Cat) fixed those symptoms but I don't think (couldn't find in spec) that Turtle requires this white space before .

N3Parser should allow literal subjects

Hi Ruben,

It seems that the store accepts literals only for objects, it will refuse them for subjects right? This made my application crash when loading the store with triples parsed from EYE inference results using the following rule.

{?P rdfs:range ?C. ?X ?P ?Y} => {?Y a ?C}.

I have solved it by modifying the rule to

{?P rdfs:range ?C. ?X ?P ?Y. ?Y log:rawType ?T. ?T owl:differentFrom rdfs:Literal} => {?Y a ?C}.

I was wondering whether it would be better to make the store more permissive on this aspect. What do you think?

Thibaut.

Writing a large amount of triples seems slow

Hi, all~

When doing writer.addTriple, it seems that only one tripple a time. And that would be deadly slow (say 300000 tripples would cost about 10 min) when dealing with large numbers of tripples.

As what i asked, i'm trying to do it like this:

writer.addTriple({
subject: fullNameUrl,
predicate: 'http://example.org/property/contact#FN',
object: '"' + 'FN' + i + '"'
}, {
subject: fullNameUrl,
predicate: 'http://example.org/property/contact#name',
object: '"' + 'Name' + i + '"'
}, {
subject: fullNameUrl,
predicate: 'http://example.org/property/contact#sex',
object: '"' + 'sex' + '"'
}, {
subject: fullNameUrl,
predicate: 'http://example.org/property/contact#Email',
object: '"' + 'EmailAddr' + '"'
}
)

But somehow, it only works with the first tripple there.
If anyone could give me some advice or clue about it and that would be realy helpful.

Thanks, all~

Parsing strange characters

I get this error when parsing an N3:
"Syntax error: unexpected "ns3:Juliane_Köhler" on line 13."

The original data definitely include funny characters.

So who to blame?
The DB for returning badly formatted data?
Or N3.js for crashing on a (perfectly valid?) UTF-something character?

Language tag after store.find function

Hi Ruben

Problem

I'm working on a DCAT validator for oSoc15 and I seem to have a problem with the language tag after finding a triple his object in the store.

The problem is that if i try to find a certain triple with the find function and I console.log the triple his object i get:
De DataTank Demo"^^http://www.w3.org/1999/02/22-rdf-syntax-ns#langString

While the triple i inserted was:
http://demo.thedatatank.com/api/dcat dc:title "De DataTank Demo"@nl ;

There is an "nl" tag behind the object of the triple when i insert it in the store but I can't get it when I use the find function.

How I've tried to solve the problem

I've looked through your documentation and saw that there is a function:
N3Util.getLiteralLanguage('"Mickey Mouse"@en');

But the triple object I get back from the find function doesn't return the literal with the language tag so concrete the find function would return: "Mickey Mouse" without @en.

Is there a way to solve this issue, if there is i'll be happy to hear it. Thanks in advance!!

Btw: you can find my DCAT validator project here: https://github.com/oSoc15/dcat-validator.js

Bower package

Problem

Currently, if you want to use N3 in the browser, you need to clone this repository, build a js file use browserify and use that in your project.

Solution

Let's make a bower package for N3: http://bower.io/ (a package manager for browser applications).

[N3Util] rdf:PlainLiteral vs xsd:string vs rdf:langString

N3Util.getLiteralType() for all untyped strings returns http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral

while i read in: http://www.w3.org/TR/2013/CR-turtle-20130219/#literals

[...] If there is no datatype IRI and no language tag, the datatype is xsd:string

also the way i understand: http://www.w3.org/TR/rdf11-concepts/#dfn-literal

A literal is a language-tagged string if and only if its datatype IRI is http://www.w3.org/1999/02/22-rdf-syntax-ns#langString [...]

N3Util.getLiteralType('"That Seventies Show"@en')

should return http://www.w3.org/1999/02/22-rdf-syntax-ns#langString

Add literal type expansion in find()

Hi Ruben,

Seems that N3Store.find() does not expand the type of literals before searching for a match. E.g. executing

store.find(null, null, '"true"^^xsd:boolean')

won't find anything whereas

store.find(null, null, '"true"^^<http://www.w3.org/2001/XMLSchema#boolean>')

will. Any idea? Am I doing anything wrong or is that a bug?

Thanks,
Thibaut.

Parallelization

Hi Ruben,

thank you for your great Parser! I'm parsing a big file and writing the output to a file. It is really fast and I would like to parse even faster by executing it in parallel. My idea was the following:

  1. assuming the machine has N-cores, split the file to parse into n parts, say file1, file2, file3, ..., fileN ;

  2. add to file2 all lines of file1 beginning with @ ,
    add to file3 all lines of file1 and file1 beginning with @,
    and so on .... (this way prefixes will not be lost)

  3. launch N-times the parser using N child processing on files1, ..., fileN respectively.

Then I would be able to parse N-time faster. Now my problem. How can I split the files instep 1) such that data that belongs to one turtle entry is not split up. Do you have an idea? Do you see some other problems using this strategy?

Thank you
Dennis

Add helper method for list creation

Lists are common structures; in RDF, their represented by rdf:first, rdf:rest, and rdf:nil. It would be handy if there as a helper method to create the relevant triples from a JavaScript array.
This could be implemented in N3.Util, but also in N3.Writer.

Raised by @iherman.

Not all triples being parsed.

When I try to parse the contents of this URI http://dbpedia.org/resource/Henry's_Crime I only get owl:sameAs triples as an output of the parser. Not the others.

Here's the code I'm using (I have CORS enabled by default):

$.ajax({
    url: "http://dbpedia.org/resource/Henry's_Crime",
    headers: { 'Accept': 'text/turtle' }
}).done(function(data) {
    console.log(data) // outputs the actual Turtle data
    var parser = N3.Parser();
    parser.parse(data, function(err, triple, prefixes) {
        console.log(triple) // many triples are not logged
    })
})

Unable to parse a valid turtle ressource

Hi,

Today we worked with Antonio Garrote author of RDFStore which uses under the hood your n3 parser.

It works fine but for the following foaf profile (which seems to be valid turtle according to an online validator) we got an error.
The foaf profile is here: http://bblfish.net/people/henry/card#me

The error was:
"Expected punctuation to follow "[object Object]" at line 44."

Do you have any idea? thanks?

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.