Closed charbull closed 7 years ago
Well, seems dotNetRDF has an issue. What's at the line 1 the exception mentions?
at line 1 and 2 there is, I tried to remove the space but didn't succeed.
http://www.se/Buildings/Lunda#R1 http://xmlns.com/foaf/0.1/primaryTopic http://www.se/Buildings/Lunda#R1 http://www.se/Buildings/Lunda .
http://www.se/Buildings/Lunda#R2 http://xmlns.com/foaf/0.1/primaryTopic http://www.se/Buildings/Lunda#R2 http://www.se/Buildings/Lunda .
You are trying to load a dataset into a single graph. dotNetRDF assumes it's in N-Triples format. That's why it fails when it encounters the graph URI at the end of each line.
What you need to do instead is load the NQuads file into a TripleStore
. See here
Ahh, true that - thanks @tpluscode. Indeed, there is an NTriples parser used instead of NQuads one. Thats why NTriples throws after object/value which should end up a statement. NQuads has a named graph at the end.
@alien-mcl and @tpluscode thank you for your replies.
I am trying to save the store to an rdf/xml file through the RDFXMLWriter from dotNetRdf. But store.SaveToFile takes only these 2 writers.
store.SaveToFile("C:\\output.trig", new TriGWriter());
store.SaveToFile("C:\\output.nq", new NQuadsWriter());
While the other writers require a Graph to write the output. So I was trying the load the .trig or .nq files in a Graph and then pass it to the RdfXmlWriter.
RdfXmlWriter rdfxmlwriter = new RdfXmlWriter();
rdfxmlwriter.Save(g, "C:\\output.rdf");
So by loading the NQuads file in a store I can't use the RdfXmlWriter since it requires a Graph and not a store.
Maybe I am missing something, it there is a simpler way of writing an rdf file from the store?
Thank you,
I'm not a dotNetRDF expert and I'm not sure what would you like to achieve. File with RDF statements shouldn't be considered as a store - that's why you're experiencing issues. Various serializations vary with capabilities, especially when it comes to named graphs. Some of them can have that information stored (NQuads, Trix), some of them cannot (Xml/Rdf, NTriples). That's why you need to handle this difference all by yourself as these formats are just incompatible. As for saving graphs as i.e. Xml/Rdf, I'd use dotNetRDF's merge graph which then can be used as a single graph.
@alien-mcl Thank you for your reply.
I think the merge can work but it requires an IGraph
object.
But the limitation I noticed is in the ITripleStore
, since I cannot get an IGraph
so I can use it in the merge function.
It seems that currently, in dotNetRDF there is no way to dump an ITripleStore content in an rdf/xml file.
I will post my question in the DotNetRDF.
AFAIK there was a property like Graphs on the store - this should give you access to all graphs in the store that can be then passed to the merge graph
@alien-mcl Correct ! Thank you !
I am sharing the code here, in case others are interested.
IGraph g = new Graph();
graphList = store.Graphs.ToList();
foreach(IGraph currentGraph in graphList)
{
g.Merge(currentGraph);
}
RdfXmlWriter rdfxmlwriter = new RdfXmlWriter();
rdfxmlwriter.Save(g, "C:\\output.rdf");
I am writing the output of my context into an nq file store.SaveToFile("C:\output.nq", new NQuadsWriter());
But then when I try to load it: I am having the following exception: IGraph g = new Graph(); FileLoader.Load(g, "C:\output.nq");
VDS.RDF.Parsing.RdfParseException occurred HResult=0x80131500 Message=[UriToken at Line 1 Column 113 to Line 1 Column 142] Unexpected Token 'VDS.RDF.Parsing.Tokens.UriToken' encountered, expected a Dot Line Terminator to terminate a Triple Source=dotNetRDF StackTrace: at VDS.RDF.Parsing.NTriplesParser.TryParseLineTerminator(TokenisingParserContext context) at VDS.RDF.Parsing.NTriplesParser.TryParseTriple(TokenisingParserContext context) at VDS.RDF.Parsing.NTriplesParser.Parse(TokenisingParserContext context) at VDS.RDF.Parsing.NTriplesParser.Load(IRdfHandler handler, TextReader input) at VDS.RDF.Parsing.FileLoader.Load(IRdfHandler handler, String filename, IRdfReader parser) at VDS.RDF.Parsing.FileLoader.Load(IGraph g, String filename, IRdfReader parser) at VDS.RDF.Parsing.FileLoader.Load(IGraph g, String filename) at BMSOnt.Program.Main(String[] args) in C:\Users\SESA232537\Source\Repos\RomanticWeb\BMSOnt\BMSOnt\Program.cs:line 45
Not sure where the problem is since the output.nq file seems to be valid when I run it on http://www.easyrdf.org/converter