Skip to content
Switch branches/tags
Go to file

Welcome to NxParser

NxParser is a Java open source, streaming, non-validating parser for the Nx format, where x = Triples, Quads, or any other number. For more details see the specification for the NQuads format, a extension for the N-Triples RDF format. Note that the parser handles any combination (cf. generalised triples) or number of N-Triples syntax terms on each line (the number of terms per line can also vary).

It ate 2 mil. quads (~4GB, (~240MB GZIPped)) on a T60p (Win7, 2.16 GHz) in ~1 min 35 s (1:18min). Overall, it's more than twice as fast as the previous version when it comes to reading Nx.

The NxParser is non-validating, meaning that, e.g., it will happily eat non-conformant N-Triples. Also, the NxParser will not parse certain valid N-Triples files where the RDF terms are not separated by whitespace. We pass all positive W3C N-Triples test cases except one, where the RDF terms are not separated by whitespace (surprise!).

Other formats

The NxParser Parser family also includes a RDF/XML and a Turtle parser. Moreover, we attached a JSON-LD parser (jsonld-java) and a RDFa parser (semargl) such that they emit Triples in the NxParser API.


Compiles are available on Maven Central. The groupId is org.semanticweb.yars. Depending on what part you need, you have to choose the artifactId accordingly: For example, if you only want to use the data model, use nxparser-model. If you want to make use of the parsers, use nxparser-parsers. If you want to use the RDF support for JAX-RS, use nxparser-jax-rs. The modules are linked as required.


Legacy binaries

Find old compiles in the repository on Google Code, which we do not maintain any more. To use it nevertheless, add


to your pom.xml.

Code Examples

Read Nx from a file

FileInputStream is = new FileInputStream("path/to/file.nq");

NxParser nxp = new NxParser();

for (Node[] nx : nxp)
  // prints the subject, eg. <>

Use a blank node

// true means you are supplying proper N-Triples RDF terms that do not need to be processed
Resource subjRes = new Resource("<>", true);
Resource predRes = new Resource("<>", true);
BNode bn = new BNode("_:bnodeId", true);

Node[] triple = new Node[]{subjRes, predRes, bn};
// yields <> <> _:bnodeId

Use Unicode-characters

String japaneseString = ("祝福は、チーズのメーカーです。");
Literal japaneseLiteral = new Literal(japaneseString, "ja");

// yields "\u795D\u798F\u306F\u3001\u30C1\u30FC\u30BA\u306E\u30E1\u30FC\u30AB\u30FC\u3067\u3059\u3002"@ja

// yields 祝福は、チーズのメーカーです。

Use datatyped literals

Example: Get a Calendar object from an xsd:dateTime-typed Literal

Literal dtl; // parser-generated
XSDDateTime dt = (XSDDateTime)DatatypeFactory.getDatatype(dtl); 
GregorianCalendar cal = dt.getValue();

Use from Python

Provided you use the Jython implementation (thanks to Uldis Bojars, this is saved from his now offline blog).

import sys
from org.semanticweb.yars.nx.parser import *
from import FileInputStream
from import GZIPInputStream
def all_triples(fname, use_gzip=False):
  in_file = FileInputStream(fname)
  if use_gzip:
      in_file = GZIPInputStream(in_file)
  nxp = NxParser()
  while nxp.hasNext():
    triple =
    n3 = ([i.toString() for i in triple])
    yield n3

The code above defines a generator function which will yield a stream of NQuad records. We can now add some demo code in order to see it in action:

def main():
  gzfname = "sioc-btc-2009.gz"
  for line in all_triples(gzfname, use_gzip=True):
    print line
  if __name__ == "__main__":

results in:

[u'<>', u'<>', u'<>', u'<>']
[u'<>', u'<>', u'"We\'ve created a map showing the main places of interest (event locations, restaurants, pubs, shopping locations and tourist sights) during BlogTalk 2008.  The conference venue is shown on the left-hand side of the map.  We will also have a hardcopy for all attendees. View Larger Map"', u'<>']

issues with Eclipse

we had an issue with eclipse not being able to create his folder structure for nxparser-parsers, mvn eclipse:eclipse did the trick.


Java parsers for different RDF serialisations + API + tools + JAX-RS integration




No packages published