public void ParsingStoreHandlerBlankNodesTriGActual()
        {
            EnsureTestData("test-bnodes.trig");

            TriGParser parser = new TriGParser();
            TripleStore store = new TripleStore();
            parser.Load(store, new StreamParams("test-bnodes.trig"));

            EnsureTestResults(store);
        }
        private void EnsureTestData(String testFile)
        {
            if (!File.Exists(testFile))
            {
                TriGParser parser = new TriGParser();
                TripleStore store = new TripleStore();
                parser.Load(store, new TextReaderParams(new StringReader(TestFragment)));

                store.SaveToFile(testFile);
            }
        }
Ejemplo n.º 3
0
        public void ParsingTriGCollectionSyntax4()
        {
            const String data   = @"@prefix : <http://example/> .
:graph
{
    :resource :predicate1 ( true 1 12.3 123e4 ).
}";
            TriGParser   parser = new TriGParser();
            TripleStore  store  = new TripleStore();

            parser.Load(store, new StringReader(data));

            Assert.Equal(1, store.Graphs.Count);
            Assert.Equal(9, store.Triples.Count());
        }
Ejemplo n.º 4
0
        public void ParsingTriGCollectionSyntax2()
        {
            const String data   = @"@prefix : <http://example/> .
:graph
{
    :resource :predicate1 ( ""a"" ""b""@en ""c""^^:datatype ).
    :resource :predicate2 ( :a :b :c ).
}";
            TriGParser   parser = new TriGParser();
            TripleStore  store  = new TripleStore();

            parser.Load(store, new StringReader(data));

            Assert.Equal(1, store.Graphs.Count);
            Assert.Equal(14, store.Triples.Count());
        }
Ejemplo n.º 5
0
        public static Object LoadFromFile(java.io.File f, string baseUri, org.openrdf.rio.RDFFormat rdff)
        {
            Object obj;

            if (rdff == dotSesameFormats.RDFFormat.N3)
            {
                obj = new Graph();
                if (baseUri != null) ((IGraph)obj).BaseUri = new Uri(baseUri);
                FileLoader.Load((IGraph)obj, f.getPath(), new Notation3Parser());
            }
            else if (rdff == dotSesameFormats.RDFFormat.NTRIPLES)
            {
                obj = new Graph();
                if (baseUri != null) ((IGraph)obj).BaseUri = new Uri(baseUri);
                FileLoader.Load((IGraph)obj, f.getPath(), new NTriplesParser());
            }
            else if (rdff == dotSesameFormats.RDFFormat.RDFXML)
            {
                obj = new Graph();
                if (baseUri != null) ((IGraph)obj).BaseUri = new Uri(baseUri);
                FileLoader.Load((IGraph)obj, f.getPath(), new RdfXmlParser());
            }
            else if (rdff == dotSesameFormats.RDFFormat.TRIG)
            {
                obj = new TripleStore();
                TriGParser trig = new TriGParser();
                trig.Load((ITripleStore)obj, new StreamParams(f.getPath()));
            }
            else if (rdff == dotSesameFormats.RDFFormat.TRIX)
            {
                obj = new TripleStore();
                TriXParser trix = new TriXParser();
                trix.Load((ITripleStore)obj, new StreamParams(f.getPath()));
            }
            else if (rdff == dotSesameFormats.RDFFormat.TURTLE)
            {
                obj = new Graph();
                if (baseUri != null) ((IGraph)obj).BaseUri = new Uri(baseUri);
                FileLoader.Load((IGraph)obj, f.getPath(), new TurtleParser());
            }
            else
            {
                throw new RdfParserSelectionException("The given Input Format is not supported by dotNetRDF");
            }

            return obj;
        }
Ejemplo n.º 6
0
        public void ParsingTriGCollectionSyntax3()
        {
            const String data   = @"@prefix : <http://example/> .
:graph
{
    :resource :predicate1 ( 
                            ( ""a"" ) # 2 triples
                            [] 
                            _:blank 
                            (
                                ""b""@en-us
                                ( ""c""^^:datatype ) # 2 triples
                            ) # 4 triples
                          ) . # 8 triples
}";
            TriGParser   parser = new TriGParser();
            TripleStore  store  = new TripleStore();

            parser.Load(store, new StringReader(data));

            Assert.Equal(1, store.Graphs.Count);
            Assert.Equal(17, store.Triples.Count());
        }
Ejemplo n.º 7
0
        private static ITripleStore TestParsing(String data, TriGSyntax syntax, bool shouldParse)
        {
            TriGParser   parser = new TriGParser(syntax);
            ITripleStore store  = new TripleStore();

            try
            {
                parser.Load(store, new StringReader(data));

                if (!shouldParse)
                {
                    Assert.True(false, "Parsed using syntax " + syntax.ToString() + " when an error was expected");
                }
            }
            catch (Exception ex)
            {
                if (shouldParse)
                {
                    throw new RdfParseException("Error parsing using syntax " + syntax.ToString() + " when success was expected", ex);
                }
            }

            return(store);
        }
Ejemplo n.º 8
0
        private void ParsingStoreHandlerTriGCountingActual()
        {
            this.EnsureTestData("test.trig");

            StreamParams ps = new StreamParams("test.trig", Encoding.ASCII);

            TriGParser parser = new TriGParser();
            StoreCountHandler counter = new StoreCountHandler();
            parser.Load(counter, ps);

            Graph configOrig = new Graph();
            configOrig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            Graph lvnOrig = new Graph();
            lvnOrig.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.Functions.LeviathanFunctionLibrary.ttl");

            Assert.AreEqual(2, counter.GraphCount, "Expected 2 Graphs to be counted");
            Assert.AreEqual(configOrig.Triples.Count + lvnOrig.Triples.Count, counter.TripleCount, "Expected Triple Count to be sum of Triple Counts in two input Graphs");
        }
Ejemplo n.º 9
0
        private void ParsingStoreHandlerTriGExplicitActual()
        {
            this.EnsureTestData("test.trig");

            TripleStore store = new TripleStore();
            StreamParams ps = new StreamParams("test.trig", Encoding.ASCII);

            TriGParser parser = new TriGParser();
            parser.Load(new StoreHandler(store), ps);

            Assert.IsTrue(store.HasGraph(new Uri("http://www.dotnetrdf.org/configuration#")), "Configuration Vocab Graph should have been parsed from Dataset");
            Graph configOrig = new Graph();
            configOrig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            IGraph config = store.Graph(new Uri("http://www.dotnetrdf.org/configuration#"));
            Assert.AreEqual(configOrig, config, "Configuration Vocab Graphs should have been equal");

            Assert.IsTrue(store.HasGraph(new Uri("http://www.dotnetrdf.org/leviathan#")), "Leviathan Function Library Graph should have been parsed from Dataset");
            Graph lvnOrig = new Graph();
            lvnOrig.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.Functions.LeviathanFunctionLibrary.ttl");
            IGraph lvn = store.Graph(new Uri("http://www.dotnetrdf.org/leviathan#"));
            Assert.AreEqual(lvnOrig, lvn, "Leviathan Function Library Graphs should have been equal");

        }
Ejemplo n.º 10
0
        public static void Main(String[] args)
        {
            StreamWriter output = new StreamWriter("TriGTestSuite.txt");
            Console.SetOut(output);

            Console.WriteLine("## TriG Test Suite");
            Console.WriteLine();

            try
            {

                foreach (String file in Directory.GetFiles("trig_tests"))
                {
                    if (Path.GetExtension(file) == ".trig")
                    {
                        Console.WriteLine("## Testing File " + Path.GetFileName(file));

                        try
                        {
                            //Parse in
                            TriGParser parser = new TriGParser();
                            TripleStore store = new TripleStore();
                            //parser.TraceTokeniser = true;
                            parser.Load(store, new StreamParams(file));

                            //Output the Triples
                            Console.WriteLine("# Parsed OK");
                            Console.WriteLine();
                            foreach (Triple t in store.Triples)
                            {
                                Console.WriteLine(t.ToString() + " from Graph <" + t.GraphUri.ToString() + ">");
                            }
                            Console.WriteLine();

                            //Write out
                            TriGWriter writer = new TriGWriter();
                            writer.HighSpeedModePermitted = false;
                            writer.Save(store, new StreamParams(file + ".out"));

                            //Parse back in again
                            TripleStore store2 = new TripleStore();
                            parser.Load(store2, new StreamParams(file + ".out"));

                            Console.WriteLine("# Parsed back in again");
                            if (store.Graphs.Count == store2.Graphs.Count)
                            {
                                Console.WriteLine("Correct number of Graphs");
                            }
                            else
                            {
                                Console.WriteLine("Incorrect number of Graphs - Expected " + store.Graphs.Count + " - Actual " + store2.Graphs.Count);
                            }
                            if (store.Triples.Count() == store2.Triples.Count())
                            {
                                Console.WriteLine("Correct number of Triples");
                            }
                            else
                            {
                                Console.WriteLine("Incorrect number of Triples - Expected " + store.Triples.Count() + " - Actual " + store2.Triples.Count());
                            }
                        }
                        catch (RdfParseException parseEx)
                        {
                            HandleError("Parser Error", parseEx);
                        }
                        catch (RdfException rdfEx)
                        {
                            HandleError("RDF Error", rdfEx);
                        }
                        catch (Exception ex)
                        {
                            HandleError("Other Error", ex);
                        }
                        finally
                        {
                            Console.WriteLine();
                        }
                    }
                }
            }
            catch (RdfParseException parseEx)
            {
                HandleError("Parser Error", parseEx);
            }
            catch (Exception ex)
            {
                HandleError("Other Error", ex);
            }
            finally
            {
                output.Close();
            }
        }
Ejemplo n.º 11
0
        public static void Main(String[] args)
        {
            StreamWriter output = new StreamWriter("NQuadsTestSuite.txt");
            Console.SetOut(output);

            Console.WriteLine("## NQuads Test Suite");
            Console.WriteLine();

            try
            {
                //Make sure Test Directory exists
                if (!Directory.Exists("nquads_tests"))
                {
                    Directory.CreateDirectory("nquads_tests");
                }

                //First read in the TriG tests and serialize to NQuads
                Console.WriteLine("# Reading in TriG files and serializing to NQuads");
                foreach (String file in Directory.GetFiles("trig_tests"))
                {
                    if (Path.GetExtension(file) == ".trig")
                    {
                        //Skip the Bad Syntax tests
                        if (Path.GetFileName(file).StartsWith("bad")) continue;

                        Console.WriteLine("Reading File " + Path.GetFileName(file));

                        try
                        {
                            TriGParser parser = new TriGParser();
                            TripleStore store = new TripleStore();
                            parser.Load(store, new StreamParams(file));

                            Console.WriteLine("Parsed OK");

                            NQuadsWriter writer = new NQuadsWriter();
                            String outfile = "nquads_tests/" + Path.GetFileNameWithoutExtension(file) + ".nq";
                            writer.Save(store, new StreamParams(outfile));

                            Console.WriteLine("Serialized OK");

                            NQuadsParser nqparser = new NQuadsParser();
                            nqparser.TraceTokeniser = true;
                            TripleStore store2 = new TripleStore();
                            nqparser.Load(store2, new StreamParams(outfile));

                            Console.WriteLine("Parsed serialized NQuads OK");

                            if (store.Graphs.Count != store2.Graphs.Count)
                            {
                                Console.WriteLine("ERROR: Wrong number of Graphs when parsed back in");
                            }
                            else if (store.Triples.Count() != store2.Triples.Count())
                            {
                                Console.WriteLine("ERROR: Wrong number of Triples when parsed back in");
                            }

                        }
                        catch (RdfParseException parseEx)
                        {
                            HandleError("Parser Error", parseEx);
                        }
                        catch (RdfException rdfEx)
                        {
                            HandleError("RDF Error", rdfEx);
                        }
                        catch (Exception ex)
                        {
                            HandleError("Other Error", ex);
                        }
                        finally
                        {
                            Console.WriteLine();
                        }
                    }
                }
            }
            catch (RdfParseException parseEx)
            {
                HandleError("Parser Error", parseEx);
            }
            catch (Exception ex)
            {
                HandleError("Other Error", ex);
            }
            finally
            {
                output.Close();
            }
        }