Exemplo n.º 1
0
        public void ParsingN3Variables()
        {
            String TestFragment = "@prefix rdfs: <" + NamespaceMapper.RDFS + ">. { ?s a ?type } => { ?s rdfs:label \"This has a type\" } .";
            Notation3Parser parser = new Notation3Parser();
            Graph g = new Graph();
            StringParser.Parse(g, TestFragment, parser);

            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString());
            }

            StringWriter.Write(g, new Notation3Writer());
        }
Exemplo n.º 2
0
        static private Graph LoadN3(string path)
        {
            var g = new Graph();
            var parser = new Notation3Parser();

            try
            {
                parser.Load(g, path);
                return g;
            }
            catch 
            {
                return null;
            }
        }
Exemplo n.º 3
0
        public void ParsingN3VariableContexts()
        {
            String prefixes = "@prefix rdf: <" + NamespaceMapper.RDF + ">. @prefix rdfs: <" + NamespaceMapper.RDFS + ">.";
            List<String> tests = new List<string>()
            {
                prefixes + "@forAll :x :type . { :x a :type } => {:x rdfs:label \"This has a type\" } .",
                prefixes + "@forSome :x :type . { :x a :type } => {:x rdfs:label \"This has a type\" } .",
                prefixes + "@forAll :h . @forSome :g . :g :loves :h .",
                prefixes + "@forSome :h . @forAll :g . :g :loves :h .",
                prefixes + "{@forSome :a . :Joe :home :a } a :Formula . :Joe :phone \"555-1212\" ."
            };

            Notation3Parser parser = new Notation3Parser();
            Notation3Writer writer = new Notation3Writer();
            foreach (String test in tests)
            {
                Graph g = new Graph();
                g.BaseUri = new Uri("http://example.org/n3rules");
                StringParser.Parse(g, test, parser);
                Console.WriteLine(StringWriter.Write(g, writer));

                Console.WriteLine();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Internal Method which performs multi-threaded reading of data
        /// </summary>
        private void LoadGraphs(FolderStoreParserContext context)
        {
            //Create the relevant Parser
            IRdfReader parser;
            switch (context.Format)
            {
                case FolderStoreFormat.Turtle:
                    parser = new TurtleParser();
                    break;
                case FolderStoreFormat.Notation3:
                    parser = new Notation3Parser();
                    break;
                case FolderStoreFormat.RdfXml:
                    parser = new RdfXmlParser();
                    break;
                default:
                    parser = new TurtleParser();
                    break;
            }

            try
            {
                String file = context.GetNextFilename();
                while (file != null)
                {
                    //Read from Disk
                    Graph g = new Graph();
                    String sourceFile = Path.Combine(context.Folder, file);
                    parser.Load(g, sourceFile);

                    //Add to Graph Collection
                    foreach (Triple t in g.Triples)
                    {
                        if (context.Terminated) break;
                        if (!context.Handler.HandleTriple(t)) ParserHelper.Stop();
                    }

                    if (context.Terminated) break;

                    //Get the Next Filename
                    file = context.GetNextFilename();
                }
            }
            catch (ThreadAbortException)
            {
                //We've been terminated, don't do anything
#if !SILVERLIGHT
                Thread.ResetAbort();
#endif
            }
            catch (RdfParsingTerminatedException)
            {
                context.Terminated = true;
                context.ClearFilenames();
            }
            catch (Exception ex)
            {
                throw new RdfStorageException("Error in Threaded Reader in Thread ID " + Thread.CurrentThread.ManagedThreadId, ex);
            }
        }
        public static void Main(string[] args)
        {
            StreamWriter output = new StreamWriter("Notation3TestSuite.txt");
            String[] wantTrace = { };
            bool traceAll = false;
            String[] wantOutput = { "path2.n3" };
            bool outputAll = false;
            String[] skipTests = { };

            Console.SetOut(output);

            try
            {
                int testsPassed = 0;
                int testsFailed = 0;
                String[] files = Directory.GetFiles("n3_tests");
                Notation3Parser parser = new Notation3Parser(TokenQueueMode.QueueAllBeforeParsing);//new Notation3Parser(TokenQueueMode.QueueAllBeforeParsing);
                parser.Warning += reportWarning;
                bool passed, passDesired;
                Graph g = new Graph();

                foreach (String file in files)
                {
                    if (skipTests.Contains(Path.GetFileName(file)))
                    {
                        output.WriteLine("## Skipping Test of File " + Path.GetFileName(file));
                        output.WriteLine();
                        continue;
                    }

                    if (Path.GetExtension(file) != ".n3")
                    {
                        continue;
                    }

                    Debug.WriteLine("Testing File " + Path.GetFileName(file));
                    output.WriteLine("## Testing File " + Path.GetFileName(file));
                    output.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));

                    passed = false;
                    passDesired = true;

                    try
                    {
                        g = new Graph();
                        g.BaseUri = new Uri(TestSuiteBaseUri);
                        if (Path.GetFileNameWithoutExtension(file).StartsWith("bad"))
                        {
                            passDesired = false;
                            output.WriteLine("# Desired Result = Parsing Failed");
                        }
                        else
                        {
                            output.WriteLine("# Desired Result = Parses OK");
                        }

                        if (wantTrace.Contains(Path.GetFileName(file)) || traceAll)
                        {
                            parser.TraceTokeniser = true;
                        }
                        else
                        {
                            parser.TraceTokeniser = false;
                        }

                        parser.Load(g, file);

                        passed = true;
                        output.WriteLine("Parsed OK");

                        if (outputAll || wantOutput.Contains(Path.GetFileName(file)))
                        {
                            if (!outputAll)
                            {
                                foreach (Triple t in g.Triples)
                                {
                                    Console.WriteLine(t.ToString());
                                }
                            }
                            NTriplesWriter writer = new NTriplesWriter();
                            writer.Save(g, "n3_tests\\" + Path.GetFileNameWithoutExtension(file) + ".out");
                        }

                    }
                    catch (IOException ioEx)
                    {
                        reportError(output, "IO Exception", ioEx);
                    }
                    catch (RdfParseException parseEx)
                    {
                        reportError(output, "Parsing Exception", parseEx);
                    }
                    catch (RdfException rdfEx)
                    {
                        reportError(output, "RDF Exception", rdfEx);
                    }
                    catch (Exception ex)
                    {
                        reportError(output, "Other Exception", ex);
                    }
                    finally
                    {
                        if (passed && passDesired)
                        {
                            //Passed and we wanted to Pass
                            testsPassed++;
                            output.WriteLine("# Result = Test Passed");
                        }
                        else if (!passed && passDesired)
                        {
                            //Failed when we should have Passed
                            testsFailed++;
                            output.WriteLine("# Result = Test Failed");
                        }
                        else if (passed && !passDesired)
                        {
                            //Passed when we should have Failed
                            testsFailed++;
                            output.WriteLine("# Result = Test Failed");
                        }
                        else
                        {
                            //Failed and we wanted to Fail
                            testsPassed++;
                            output.WriteLine("# Result = Test Passed");
                        }

                        output.WriteLine("# Triples Generated = " + g.Triples.Count());
                        output.WriteLine("# Test Ended at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    }

                    output.WriteLine();
                }

                output.WriteLine(testsPassed + " Tests Passed");
                output.WriteLine(testsFailed + " Tests Failed");

            }
            catch (Exception ex)
            {
                reportError(output, "Other Exception", ex);
            }

            Console.SetOut(Console.Out);
            Console.WriteLine("Done");
            Debug.WriteLine("Finished");

            output.Close();

        }
Exemplo n.º 6
0
        public static Object LoadFromReader(Reader r, 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);
                Notation3Parser parser = new Notation3Parser();
                parser.Load((IGraph)obj, r.ToDotNetReadableStream());
            }
            else if (rdff == dotSesameFormats.RDFFormat.NTRIPLES)
            {
                obj = new Graph();
                if (baseUri != null) ((IGraph)obj).BaseUri = new Uri(baseUri);
                NTriplesParser parser = new NTriplesParser();
                parser.Load((IGraph)obj, r.ToDotNetReadableStream());
            }
            else if (rdff == dotSesameFormats.RDFFormat.RDFXML)
            {
                obj = new Graph();
                if (baseUri != null) ((IGraph)obj).BaseUri = new Uri(baseUri);
                RdfXmlParser parser = new RdfXmlParser();
                parser.Load((IGraph)obj, r.ToDotNetReadableStream());
            }
            else if (rdff == dotSesameFormats.RDFFormat.TRIG)
            {
                obj = new TripleStore();
                TriGParser trig = new TriGParser();
                trig.Load((ITripleStore)obj, new StreamParams(r.ToDotNetReadableStream().BaseStream));
            }
            else if (rdff == dotSesameFormats.RDFFormat.TRIX)
            {
                obj = new TripleStore();
                TriXParser trix = new TriXParser();
                trix.Load((ITripleStore)obj, new StreamParams(r.ToDotNetReadableStream().BaseStream));
            }
            else if (rdff == dotSesameFormats.RDFFormat.TURTLE)
            {
                obj = new Graph();
                if (baseUri != null) ((IGraph)obj).BaseUri = new Uri(baseUri);
                TurtleParser parser = new TurtleParser();
                parser.Load((IGraph)obj, r.ToDotNetReadableStream());
            }
            else
            {
                throw new RdfParserSelectionException("The given Input Format is not supported by dotNetRDF");
            }

            return obj;
        }
Exemplo n.º 7
0
        public static void Main(String[] args)
        {
            StreamWriter output  = new StreamWriter("AllegroGraphTest.txt");
            Console.SetOut(output);
            try
            {
                Console.WriteLine("## AllegroGraph Test");
                Console.WriteLine();

                //Load the Graph we want to use as a Test
                Graph g = new Graph();
                TurtleParser ttlparser = new TurtleParser();
                ttlparser.Load(g, "InferenceTest.ttl");
                Console.WriteLine("Test Graph contains the following Triples:");
                ShowGraph(g);
                Console.WriteLine();

                //Load another Graph
                Graph h = new Graph();
                h.BaseUri = new Uri("http://example.org/test");
                Notation3Parser n3parser = new Notation3Parser();
                n3parser.Load(h, "test.n3");
                Console.WriteLine("Second Test Graph contains the following Triples:");
                ShowGraph(h);
                Console.WriteLine();

                Console.WriteLine("Trying to create a test store in the test catalog");
                AllegroGraphConnector agraph = new AllegroGraphConnector("http://localhost:9875/", "test", "test");
                Console.WriteLine("Store Created OK");
                Console.WriteLine();

                Console.WriteLine("Trying to add data to the Store");
                agraph.SaveGraph(g);
                agraph.SaveGraph(h);
                Console.WriteLine("Saved OK");
                Console.WriteLine();

                Console.WriteLine("Trying to load data from the Store");
                Graph i = new Graph();
                agraph.LoadGraph(i, String.Empty);
                ShowGraph(i);
                Console.WriteLine();
                i = new Graph();
                agraph.LoadGraph(i, new Uri("http://example.org/test"));
                ShowGraph(i);
                Console.WriteLine("Loaded OK");
                Console.WriteLine();

                Console.WriteLine("Trying to update data in the Store");
                List<Triple> toRemove = g.GetTriplesWithPredicate(g.CreateUriNode("rdf:type")).ToList();
                Triple toAdd = new Triple(g.CreateUriNode(new Uri("http://example.org/")), g.CreateUriNode("rdf:type"), g.CreateLiteralNode("Added Triple Test"));
                agraph.UpdateGraph(String.Empty, new List<Triple>() { toAdd }, toRemove);
                Console.WriteLine("Updated OK");
                Console.WriteLine();

                Console.WriteLine("Trying a SPARQL ASK query against the store");
                Object results = agraph.Query("ASK WHERE {?s ?p ?o}");
                Console.WriteLine("Got results OK");
                ShowResults(results);
                Console.WriteLine();

                Console.WriteLine("Trying a SPARQL SELECT query against the store");
                results = agraph.Query("SELECT * WHERE {?s ?p ?o}");
                Console.WriteLine("Got results OK");
                ShowResults(results);
                Console.WriteLine();

            }
            catch (RdfStorageException storeEx)
            {
                reportError(output, "RDF Storage Error", storeEx);
            }
            catch (RdfParseException parseEx)
            {
                reportError(output, "RDF Parsing Error", parseEx);
            }
            catch (RdfQueryException queryEx)
            {
                reportError(output, "RDF Query Error", queryEx);
            }
            catch (RdfException rdfEx)
            {
                reportError(output, "RDF Error", rdfEx);
            }
            catch (WebException webEx)
            {
                reportError(output, "HTTP Error", webEx);
            }
            catch (Exception ex)
            {
                reportError(output, "Error", ex);
            }
            finally
            {
                output.Close();
            }
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            StreamWriter output = new StreamWriter("LocalSPARQLTests.txt");
            try
            {
                //Set Output
                Console.SetOut(output);

                Console.WriteLine("## Local SPARQL Test Suite");

                //Create a directory for the Output
                if (!Directory.Exists("localsparql_tests"))
                {
                    Directory.CreateDirectory("localsparql_test");
                }

                //Get a Triple Store
                IInMemoryQueryableStore store = new TripleStore();

                Console.WriteLine();
                Console.WriteLine("Loading two Graphs into the Triple Store");
            
                //Load it with Data
                Graph g = new Graph();
                g.BaseUri = new Uri("http://example.org/1");
                TurtleParser ttlparser = new TurtleParser();
                ttlparser.Load(g, "InferenceTest.ttl");
                store.Add(g);

                Notation3Parser n3parser = new Notation3Parser();
                Graph h = new Graph();
                h.BaseUri = new Uri("http://example.org/2");
                n3parser.Load(h, "test.n3");
                store.Add(h);

                Console.WriteLine("# Triple Store Loading Done");
                Console.WriteLine();

                //Show the Triples
                Console.WriteLine("# Following Triples are in the Store");
                foreach (Triple t in store.Triples)
                {
                    Console.WriteLine(t.ToString(true) + " from Graph " + t.GraphUri.ToString());
                }
                Console.WriteLine();
                Console.WriteLine(new String('-', 150));
                Console.WriteLine();

                //Create the Test Queries
                String stdprefixes = "PREFIX rdf: <" + NamespaceMapper.RDF + ">\nPREFIX rdfs: <" + NamespaceMapper.RDFS + ">\n";
                String xsdprefix = "PREFIX xsd: <" + NamespaceMapper.XMLSCHEMA + ">\n";
                String exprefix = "PREFIX eg: <http://example.org/vehicles/>\n";
                String vdsprefixes = "PREFIX vds: <http://www.vdesign-studios.com/dotNetRDF#>\nPREFIX ecs: <http://id.ecs.soton.ac.uk/person/>";
                String fnprefix = "PREFIX fn: <http://www.w3.org/2005/xpath-functions#>\n";
                String afnprefix = "PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>\n";

                //Simple SELECT and ASK
                TestQueries.Add("SELECT * WHERE {?s ?p ?o}");
                TestQueries.Add("ASK WHERE {?s ?p ?o}");
                TestQueries.Add("SELECT ?s WHERE { }");
                TestQueries.Add("ASK WHERE { }");
                TestQueries.Add(stdprefixes + "ASK WHERE { ?s rdf:type rdf:NoSuchType }");

                //Simple DESCRIBE
                TestQueries.Add("DESCRIBE <http://wwww.nosuchthing.org>");
                TestQueries.Add(exprefix + "DESCRIBE eg:FordFiesta");
                TestQueries.Add(stdprefixes + exprefix + "DESCRIBE ?car WHERE {?car rdf:type eg:Car}");
                TestQueries.Add(stdprefixes + exprefix + "DESCRIBE eg:FordFiesta eg:AirbusA380 ?plane WHERE {?plane rdf:type eg:Plane}");
                TestQueries.Add("DESCRIBE ?s WHERE {?s ?p ?o FILTER(isBlank(?s))}");

                //Simple CONSTRUCT
                TestQueries.Add("CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}");
                TestQueries.Add(stdprefixes + "CONSTRUCT {?s ?p ?o} WHERE {?s rdf:type rdfs:Class . ?s ?p ?o}");
                TestQueries.Add(stdprefixes + exprefix + "CONSTRUCT {?s ?p ?o} WHERE {?s rdf:type eg:Car . ?s ?p ?o}");
                TestQueries.Add(stdprefixes + exprefix + "CONSTRUCT {_:bnodeTest rdfs:label ?s; a eg:Car; eg:Speed ?o} WHERE {?s rdf:type eg:Car . ?s eg:Speed ?o}");
                TestQueries.Add(stdprefixes + exprefix + "CONSTRUCT {[rdfs:label ?s; a eg:Car; eg:Speed ?o]} WHERE {?s rdf:type eg:Car . ?s eg:Speed ?o}");

                //DISTINCT and REDUCED
                TestQueries.Add("SELECT DISTINCT ?s WHERE {?s ?p ?o}");
                TestQueries.Add("SELECT DISTINCT ?s WHERE {?s ?p ?o} LIMIT 10");
                TestQueries.Add("SELECT REDUCED ?s WHERE {?s ?p ?o}");
                TestQueries.Add("SELECT REDUCED ?s WHERE {?s ?p ?o} LIMIT 10");

                //ORDER BY
                TestQueries.Add("SELECT ?s WHERE {?s ?p ?o} ORDER BY ?s LIMIT 10");
                TestQueries.Add("SELECT DISTINCT ?s WHERE {?s ?p ?o} ORDER BY ?s LIMIT 10");
                TestQueries.Add("SELECT ?s ?p ?o WHERE {?s ?p ?o} ORDER BY ?s ?p LIMIT 10");
                TestQueries.Add(stdprefixes + "SELECT ?o WHERE {?s ?p ?o FILTER IsLiteral(?o)} ORDER BY ASC(?o)");
                TestQueries.Add(stdprefixes + "SELECT ?o WHERE {?s ?p ?o FILTER IsLiteral(?o)} ORDER BY DESC(?o)");
                TestQueries.Add(stdprefixes + "SELECT ?o WHERE {?s ?p ?o FILTER IsLiteral(?o)} ORDER BY ASC(STR(?o))");
                TestQueries.Add(stdprefixes + exprefix + "SELECT * {?vehicle rdf:type ?vehicleclass OPTIONAL {?vehicle eg:Speed ?speed}} ORDER BY BOUND(?speed)");
                TestQueries.Add(stdprefixes + exprefix + "SELECT * {?vehicle rdf:type ?vehicleclass OPTIONAL {?vehicle eg:Speed ?speed}} ORDER BY DESC(BOUND(?speed))");
                TestQueries.Add(exprefix + "SELECT * {?vehicle eg:Speed ?speed} ORDER BY (STR(?speed))");
                TestQueries.Add(stdprefixes + exprefix + "SELECT * {?vehicle rdf:type ?vehicleclass OPTIONAL {?vehicle eg:Speed ?speed}} ORDER BY DATATYPE(?speed)");

                //More complex SELECTS
                TestQueries.Add(stdprefixes + "SELECT ?s WHERE {?s rdf:type rdfs:Class}");
                TestQueries.Add(stdprefixes + "SELECT ?class ?subclass WHERE {?class rdf:type rdfs:Class . ?subclass rdfs:subClassOf ?class .}");
                TestQueries.Add(stdprefixes + "SELECT ?class ?subclass WHERE {?subclass rdfs:subClassOf ?class . ?class rdf:type rdfs:Class .}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?plane WHERE {?planes rdfs:subClassOf eg:Plane . ?plane rdf:type ?planes}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass . ?vehicle eg:Speed ?speed}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?prop ?value WHERE {?prop rdfs:range eg:Vehicle . ?vehicle ?prop ?value}");
                TestQueries.Add(stdprefixes + "SELECT * {?subclass rdfs:subClassOf ?class . ?subclass1 rdfs:subClassOf ?class1 } ORDER BY ?subclass ?subclass1");
                //The next one takes a long time to execute, it should error due to Execution Timeout
                //TestQueries.Add(stdprefixes + "SELECT * {?subclass rdfs:subClassOf ?class . ?subclass1 rdfs:subClassOf ?class1 . ?subclass2 rdfs:subClassOf ?class2} ORDER BY ?subclass ?subclass1 ?subclass2");
                TestQueries.Add(stdprefixes + exprefix + "SELECT * {_:a rdf:type eg:Car . _:a ?p ?o }");

                //LIMIT and OFFSET
                TestQueries.Add(stdprefixes + "SELECT ?vehicle {?vehicle rdf:type ?vehicleclass}");
                TestQueries.Add(stdprefixes + "SELECT ?vehicle {?vehicle rdf:type ?vehicleclass} LIMIT 5");
                TestQueries.Add(stdprefixes + "SELECT ?vehicle {?vehicle rdf:type ?vehicleclass} LIMIT 5 OFFSET 5");
                TestQueries.Add(stdprefixes + "SELECT ?vehicle {?vehicle rdf:type ?vehicleclass} OFFSET 10 LIMIT 5");
                TestQueries.Add(stdprefixes + "SELECT ?vehicle {?vehicle rdf:type ?vehicleclass} LIMIT 0");
                TestQueries.Add(stdprefixes + "SELECT ?vehicle {?vehicle rdf:type ?vehicleclass} LIMIT 10 OFFSET 15");
                TestQueries.Add(stdprefixes + "SELECT ?vehicle {?vehicle rdf:type ?vehicleclass} LIMIT 10 OFFSET 25");

                //FROM and FROM Named
                TestQueries.Add(stdprefixes + "SELECT DISTINCT ?class FROM <http://example.org/1> WHERE {?class rdf:type rdfs:Class}");
                TestQueries.Add(stdprefixes + "SELECT DISTINCT ?class FROM NAMED <http://example.org/food/> WHERE {?class rdf:type rdfs:Class}");

                //OPTIONAL
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed}}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER (!BOUND(?speed))}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed ?passengers WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} OPTIONAL { ?vehicle eg:PassengerCapacity ?passengers}}");

                //FILTER
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER BOUND(?speed)}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass . ?vehicle eg:Speed ?speed FILTER (?speed > 500)}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass . ?vehicle eg:Speed ?speed FILTER (?speed > 100 && ?speed < 200)}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass . ?vehicle eg:Speed ?speed FILTER (?speed < 100 || ?speed > 200)}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass . ?vehicle eg:Speed ?speed FILTER (?speed + 50 >= 200)}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass . ?vehicle eg:Speed ?speed FILTER (?speed + (50 * 3) >= 200)}");
                TestQueries.Add(stdprefixes + "SELECT ?o WHERE {?s ?p ?o FILTER(<http://what>)}");
                TestQueries.Add(stdprefixes + "SELECT ?o WHERE {?s ?p ?o FILTER IsLiteral(?o)}");
                TestQueries.Add(stdprefixes + "SELECT DISTINCT ?o WHERE {?s ?p ?o FILTER IsURI(?o)}");
                TestQueries.Add(stdprefixes + "SELECT * WHERE {?s ?p ?o FILTER (STR(?o) = \"150\")}");
                TestQueries.Add(stdprefixes + xsdprefix + "SELECT * WHERE {?s ?p ?o FILTER (DATATYPE(?o) = xsd:integer)}");
                TestQueries.Add(stdprefixes + "SELECT ?subclass ?subclass1 {?subclass rdfs:subClassOf ?class . ?subclass1 rdfs:subClassOf ?class1 FILTER SAMETERM(?subclass,?subclass1)}");
                TestQueries.Add("SELECT * {?s ?p ?o FILTER(LANG(?o) = \"\")}");
                TestQueries.Add("SELECT * {?s ?p ?o FILTER(LANGMATCHES(?o,\"*\"))}");
                TestQueries.Add("SELECT * {?s ?p ?o FILTER(LANGMATCHES(?o,\"en\"))}");
                TestQueries.Add("SELECT * {?s ?p ?o FILTER(LANGMATCHES(?o,\"fr\"))}");
                TestQueries.Add("SELECT * {?s ?p ?o FILTER(LANGMATCHES(?o,\"\"))}");
                TestQueries.Add(exprefix + "SELECT * {?vehicle eg:Speed ?speed FILTER REGEX(?speed,\"1\\d+\")}");
                TestQueries.Add(exprefix + "SELECT * {?vehicle eg:Speed ?speed FILTER(REGEX(?speed,\"1\\d+\"))}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed . FILTER(?speed < 200)}}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?vehicle ?speed ?passengers WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed . FILTER(?speed < 200) OPTIONAL {?vehicle eg:PassengerCapacity ?passengers}}}");

                //XPath Casting
                TestQueries.Add(stdprefixes + xsdprefix + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER(xsd:boolean(?speed))}");
                TestQueries.Add(stdprefixes + xsdprefix + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER(xsd:dateTime(?speed))}");
                TestQueries.Add(stdprefixes + xsdprefix + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER(xsd:decimal(?speed))}");
                TestQueries.Add(stdprefixes + xsdprefix + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER(xsd:double(?speed))}");
                TestQueries.Add(stdprefixes + xsdprefix + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER(xsd:float(?speed))}");
                TestQueries.Add(stdprefixes + xsdprefix + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER(xsd:integer(?speed))}");
                TestQueries.Add(stdprefixes + xsdprefix + exprefix + "SELECT ?vehicle ?speed WHERE {?vehicle rdf:type ?vehicleclass OPTIONAL { ?vehicle eg:Speed ?speed} FILTER(xsd:string(?speed))}");

                //GRAPH
                TestQueries.Add(stdprefixes + "SELECT ?class FROM NAMED <http://example.org/1> WHERE {?class rdf:type rdfs:Class}");
                TestQueries.Add(stdprefixes + "SELECT ?class FROM NAMED <http://example.org/1> WHERE {GRAPH <http://example.org/1> {?class rdf:type rdfs:Class}}");
                TestQueries.Add(stdprefixes + vdsprefixes + "SELECT * FROM NAMED <http://example.org/1> FROM NAMED <http://example.org/2> WHERE {GRAPH <http://example.org/1> {?class rdf:type rdfs:Class} GRAPH <http://example.org/2> {?supervisor vds:supervises ?student}}");
                TestQueries.Add("SELECT DISTINCT ?s ?src WHERE {GRAPH ?src {?s ?p ?o}}");
                TestQueries.Add("SELECT * FROM NAMED <http://example.org/1> FROM NAMED <http://example.org/2> WHERE { GRAPH ?src {?s ?p ?o}} ORDER BY ?src ?s ?p");
                TestQueries.Add(stdprefixes + "SELECT ?s ?p ?o FROM NAMED <http://example.org/1> FROM NAMED <http://example.org/2> WHERE {GRAPH <http://example.org/2> {?subj rdfs:seeAlso ?src} GRAPH ?src {?s ?p ?o}}");
                TestQueries.Add(stdprefixes + "SELECT ?s ?src FROM <http://example.org/2> WHERE {GRAPH ?src {?s ?p ?o}}");
                TestQueries.Add("SELECT ?g WHERE {GRAPH ?g { }}");

                //UNION
                TestQueries.Add("SELECT * {{?s ?p ?o} UNION {?s ?p ?o}}");
                TestQueries.Add("SELECT * {{?s ?p ?o} UNION {?s ?p ?o} FILTER(IsLiteral(?o))} ORDER BY ?s ?p");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?plane WHERE {{?plane rdf:type eg:Plane} UNION {?subclass rdfs:subClassOf eg:Plane . ?plane rdf:type ?subclass}}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?plane ?speed WHERE {{?plane rdf:type eg:Plane} UNION {?subclass rdfs:subClassOf eg:Plane . ?plane rdf:type ?subclass} OPTIONAL {?plane eg:Speed ?speed}}");

                //Aggregates
                TestQueries.Add("SELECT COUNT(*) WHERE {?s ?p ?o}");
                TestQueries.Add("SELECT COUNT(?s) WHERE {?s ?p ?o}");
                TestQueries.Add("SELECT COUNT(DISTINCT *) WHERE {?s ?p ?o}");
                TestQueries.Add("SELECT COUNT(DISTINCT ?s) AS ?Subjects WHERE {?s ?p ?o}");
                TestQueries.Add(exprefix + "SELECT MAX(?speed) WHERE {?vehicle eg:Speed ?speed .}");
                TestQueries.Add(exprefix + "SELECT MIN(?speed) WHERE {?vehicle eg:Speed ?speed .}");
                TestQueries.Add("SELECT ?o {?s ?p ?o} ORDER BY ?o");
                TestQueries.Add("SELECT MAX(?o) WHERE {?s ?p ?o .}");
                TestQueries.Add("SELECT MEDIAN(?o) WHERE {?s ?p ?o.}");
                TestQueries.Add("SELECT MIN(?o) WHERE {?s ?p ?o .}");
                TestQueries.Add("SELECT MODE(?o) WHERE {?s ?p ?o .}");
                TestQueries.Add("SELECT NMAX(?o) WHERE {?s ?p ?o .}");
                TestQueries.Add("SELECT NMIN(?o) WHERE {?s ?p ?o .}");
                TestQueries.Add(exprefix + "SELECT AVG(?speed) AS ?AverageSpeed WHERE {?vehicle eg:Speed ?speed }");
                TestQueries.Add(exprefix + "SELECT SUM(?speed) AS ?TotalSpeeds WHERE {?vehicle eg:Speed ?speed }");

                //Projection
                TestQueries.Add(exprefix + "SELECT ?vehicle (?speed * 2) AS ?DoubleSpeed WHERE {?vehicle eg:Speed ?speed }");
                TestQueries.Add(exprefix + "SELECT ?vehicle (?speed * 2) AS ?DoubleSpeed WHERE {?vehicle eg:Speed ?speed } ORDER BY DESC(?DoubleSpeed)");
                TestQueries.Add(exprefix + "SELECT ?vehicle (1 / ?speed) AS ?Test WHERE {?vehicle eg:Speed ?speed } ORDER BY ?Test");
                TestQueries.Add(exprefix + "SELECT ?vehicle (?speed >= 700) AS ?BreaksSoundBarrier WHERE {?vehicle eg:Speed ?speed } ORDER BY ?BreaksSoundBarrier");
                TestQueries.Add(exprefix + "SELECT ?vehicle (?speed >= 700) AS ?BreaksSoundBarrier WHERE {?vehicle eg:Speed ?speed } ORDER BY DESC(?BreaksSoundBarrier)");

                //Optimisable Queries
                TestQueries.Add(exprefix + "SELECT * WHERE {?s ?p ?o . ?s a eg:Car}");
                TestQueries.Add(exprefix + "SELECT ?s ?speed WHERE {?s eg:Speed ?speed . ?s a eg:Car}");
                TestQueries.Add(exprefix + "SELECT * WHERE {?vehicle ?prop ?value . ?vehicle eg:Speed ?speed . ?vehicle eg:PassengerCapacity ?passengers }");
                TestQueries.Add(vdsprefixes + "SELECT * WHERE {ecs:11471 vds:has ?prop . ?prop vds:is \"a test\"}");

                //Testing FILTER placement
                TestQueries.Add(exprefix + "SELECT * WHERE {?car a eg:Car . ?car eg:Speed ?speed . ?car eg:PassengerCapacity ?passengers . FILTER(?speed > 100) . FILTER(?passengers > 2)}");

                //EXISTS and NOT EXISTS
                TestQueries.Add(exprefix + "SELECT * WHERE {?car a eg:Car . EXISTS { ?car eg:Speed ?speed }}");
                TestQueries.Add(exprefix + "SELECT * WHERE {?car a eg:Car . NOT EXISTS { ?car eg:Speed ?speed }}");
                TestQueries.Add(exprefix + "SELECT * WHERE {?car a eg:Car . EXISTS {?car eg:PassengerCapacity ?passengers }}");
                TestQueries.Add(exprefix + "SELECT * WHERE {?car a eg:Car . UNSAID {?car eg:PassengerCapacity ?passengers }}");

                //LET
                TestQueries.Add("SELECT ?z WHERE { LET(?b := (2)) LET(?a := (?b*4)) LET(?c := (1)) LET(?z := (?a+?c)) }");
                TestQueries.Add(exprefix + "SELECT ?speed ?doubleSpeed WHERE {?car a eg:Car . ?car eg:Speed ?speed . LET (?doubleSpeed := (?speed * 2)) }");
                TestQueries.Add(exprefix + "SELECT ?speed ?doubleSpeed WHERE {?car a eg:Car . OPTIONAL {?car eg:Speed ?speed }. OPTIONAL{ LET (?doubleSpeed := (?speed * 2))} }");
                TestQueries.Add(exprefix + "SELECT * WHERE {?car a eg:Car . OPTIONAL { ?car eg:Speed ?speed . LET(?doubleSpeed := (?speed * 2))}}");
                TestQueries.Add("SELECT * WHERE { LET(?a := (2)) . LET(?a := (\"Some String\")) }");
                TestQueries.Add(exprefix + "SELECT * WHERE {?vehicle a ?type . LET (?type := (eg:Plane))}");
                TestQueries.Add(exprefix + "SELECT * WHERE {?car a eg:Car . LET(?car := (eg:MiniCooper))}");

                //Sub-query
                TestQueries.Add(vdsprefixes + "SELECT * WHERE {?academic vds:supervises ecs:11471 . { SELECT * WHERE {?academic vds:collaborates ?collaborator}}}");
                TestQueries.Add("SELECT * WHERE {?s a ?type . {SELECT ?s COUNT(?s) AS ?Triples WHERE {?s ?p ?o} GROUP BY ?s} FILTER(?Triples >= 3)}");
                TestQueries.Add("SELECT ?s ?Triples ?Type2 WHERE {?s a ?type . {SELECT ?s COUNT(?s) AS ?Triples WHERE {?s ?p ?o} GROUP BY ?s} {SELECT ?s ?Type2 WHERE {?s a ?Type2}} FILTER(?Triples >= 3)}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?car ?speed WHERE {?car a eg:Car {SELECT ?car ?speed WHERE {?car eg:Speed ?speed}}}");
                TestQueries.Add(stdprefixes + exprefix + "SELECT ?car ?speed WHERE {?car a eg:Car OPTIONAL {SELECT ?car ?speed WHERE {?car eg:Speed ?speed}}}");

                //XPath String Functions
                TestQueries.Add(fnprefix + "SELECT ?o WHERE {?s ?p ?o FILTER(fn:contains(?o, \"a\"))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:encode-for-uri(?o)) AS ?funcResult WHERE {?s ?p ?o . FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o WHERE {?s ?p ?o FILTER(fn:ends-with(?o, \"s\"))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:false()) AS ?funcResult WHERE {?s ?p ?o}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:lower-case(?o)) AS ?funcResult WHERE {?s ?p ?o . FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o WHERE {?s ?p ?o FILTER(fn:matches(?o, \"a\"))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:normalize-space(?o)) AS ?funcResult WHERE {?s ?p ?o . FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:normalize-unicode(?o)) AS ?funcResult WHERE {?s ?p ?o . FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:normalize-unicode(?o, \"NFD\")) AS ?funcResult WHERE {?s ?p ?o . FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:not(?o)) AS ?funcResult WHERE {?s ?p ?o . FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:replace(?o, \"a\", \"b\")) AS ?funcResult WHERE {?s ?p ?o . FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o WHERE {?s ?p ?o FILTER(fn:starts-with(?o, \"a\"))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:string-length(?o)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:substring(?o, 5)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:substring(?o, 50)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:substring(?o, 5, 5)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:substring(?o, 5, 0)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:substring-after(?o, \"a\")) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:substring-before(?o, \"a\")) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:true()) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:upper-case(?o)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(stdprefixes + fnprefix + "SELECT ?class ?class1 (fn:compare(STR(?class),STR(?class1))) AS ?funcResult {?subclass rdfs:subClassOf ?class . ?subclass1 rdfs:subClassOf ?class1 } ORDER BY ?class ?class1");

                //XPath Numeric Functions
                TestQueries.Add(fnprefix + "SELECT ?o (fn:abs(?o)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:ceiling(?o)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:floor(?o)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:round(?o)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:round-half-to-even(?o)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");
                TestQueries.Add(fnprefix + "SELECT ?o (fn:round-half-to-even(?o, 4)) AS ?funcResult WHERE {?s ?p ?o FILTER(ISLITERAL(?o))}");

                //ARQ Functions
                TestQueries.Add(afnprefix + "SELECT ?s (afn:localname(?s)) AS ?LocalName (afn:namespace(?s)) AS ?Namespace WHERE {?s ?p ?o . FILTER(ISURI(?s))}");
                TestQueries.Add(afnprefix + "SELECT ?p (afn:localname(?p)) AS ?LocalName (afn:namespace(?p)) AS ?Namespace WHERE {?s ?p ?o . FILTER(ISURI(?p))}");
                TestQueries.Add(afnprefix + "SELECT ?o (afn:localname(?o)) AS ?LocalName (afn:namespace(?o)) AS ?Namespace WHERE {?s ?p ?o . FILTER(ISURI(?o))}");
                TestQueries.Add(afnprefix + "SELECT ?s (afn:now()) AS ?Now WHERE {?s ?p ?o}");
                TestQueries.Add(afnprefix + "SELECT (afn:sha1sum(<http://example.org/book/book5>)) AS ?SHA1 WHERE {}");
                TestQueries.Add(afnprefix + "SELECT (afn:sha1sum(\"Harry Potter and the Order of the Phoenix\")) AS ?SHA1 WHERE {}");
                TestQueries.Add(xsdprefix + afnprefix + "SELECT (afn:sha1sum(1)) AS ?SHA1 WHERE {}");
                TestQueries.Add(afnprefix + "SELECT (afn:sha1sum(\"Some Text\")) AS ?SHA1 WHERE {}");
                TestQueries.Add(afnprefix + "SELECT (afn:sha1sum(\"Some Text\"@en)) AS ?SHA1 WHERE {}");
                TestQueries.Add(afnprefix + "SELECT (afn:sha1sum(\"Some Text\"@fr)) AS ?SHA1 WHERE {}");
                TestQueries.Add(xsdprefix + afnprefix + "SELECT (afn:sha1sum(\"Some Text\"^^xsd:unknownType)) AS ?SHA1 WHERE {}");
                TestQueries.Add(xsdprefix + afnprefix + "SELECT (afn:sha1sum(\"2010-04-01T15:36:00+00:00\"^^xsd:dateTime)) AS ?SHA1 WHERE { }");
        
                //Options.QueryOptimisation = false;
                //Options.QueryDefaultSyntax = SparqlQuerySyntax.Sparql_1_0;
                //Options.QueryDefaultSyntax = SparqlQuerySyntax.Sparql_1_1;
                Options.QueryOptimisation = true;
                Options.QueryDefaultSyntax = SparqlQuerySyntax.Extended;

                //Register the ARQ Function Library
                SparqlExpressionFactory.AddCustomFactory(new ArqFunctionFactory());

                //Get the Sparql Parser
                SparqlQueryParser sparqlparser;
                try
                {
                    sparqlparser = new SparqlQueryParser();
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    if (ex.InnerException != null)
                    {
                        Console.WriteLine();
                        Console.WriteLine(ex.InnerException.Message);
                        Console.WriteLine(ex.InnerException.StackTrace);
                    }
                    output.Close();
                    return;
                }
                //sparqlparser.TraceTokeniser = true;

                //Run the Test Queries
                int i = 0;
                Stopwatch parseTimer = new Stopwatch();
                foreach (String q in TestQueries)
                {
                    Console.WriteLine();
                    Console.WriteLine("# Raw Query Input");
                    Console.WriteLine(q);
                    Console.WriteLine();
                    Debug.WriteLine(q);
                    try
                    {
                        parseTimer.Start();
                        SparqlQuery query = sparqlparser.ParseFromString(q);
                        parseTimer.Stop();
                        Console.Write("# Parsed Query Input");
                        Console.WriteLine(" - Took " + parseTimer.ElapsedMilliseconds + "ms (" + parseTimer.ElapsedTicks + " ticks) to parse");
                        Console.WriteLine(query.ToString());
                        Console.WriteLine();
                        TestQuery(store, query, "localsparql_test/" + i);
                    }
                    catch (Exception ex)
                    {
                        parseTimer.Stop();
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.StackTrace);
                        if (ex.InnerException != null)
                        {
                            Console.WriteLine();
                            Console.WriteLine(ex.InnerException.Message);
                            Console.WriteLine(ex.InnerException.StackTrace);
                        }

                        Console.WriteLine();
                        Console.WriteLine(new String('-', 150));
                    }
                    parseTimer.Reset();

                    i++;
                }

                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            output.Close();
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            StreamWriter output = new StreamWriter("ParserSpeedTest.txt");
            Notation3Parser n3parser = new Notation3Parser();
            TurtleParser ttlparser = new TurtleParser();
            ITokenQueue queue;
            DateTime start, end;
            long diff;
            bool tokeniseOnly = false;

            Console.SetOut(output);

            String[] files = { "turtle_tests/test-14.ttl", "turtle_tests/test-15.ttl", "turtle_tests/test-16.ttl" };
            foreach (String file in files)
            {
                Console.WriteLine("## Testing File " + file);

                //Use Turtle Tokeniser
                Debug.WriteLine("Testing file " + file + " using Turtle Tokeniser");
                Console.WriteLine("# Using Turtle Tokeniser Only");
                queue = new TokenQueue();
                queue.Tokeniser = new TurtleTokeniser(new StreamReader(file));
                Console.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                queue.InitialiseBuffer();
                Console.WriteLine("# Test Finished at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                
                //Use Turtle Parser
                if (!tokeniseOnly)
                {
                    Debug.WriteLine("Testing file " + file + " using Turtle Parser");
                    Console.WriteLine("# Using Turtle Parser");
                    Console.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    start = DateTime.Now;
                    Debug.WriteLine("Start " + start.ToString(TestSuite.TestSuiteTimeFormat));
                    Test(file, ttlparser, output);
                    Console.WriteLine("# Test Finished at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    end = DateTime.Now;
                    diff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, start, end, Microsoft.VisualBasic.FirstDayOfWeek.Saturday, Microsoft.VisualBasic.FirstWeekOfYear.System);
                    Console.WriteLine("Read Time was " + diff + " seconds");
                    Debug.WriteLine("End " + end.ToString(TestSuite.TestSuiteTimeFormat));
                    Debug.WriteLine("Read Time was " + diff + " seconds");
                    Console.WriteLine();
                }

                //Use Notation 3 Tokeniser
                Debug.WriteLine("Testing file " + file + " using Notation 3 Tokeniser");
                Console.WriteLine("# Using Notation 3 Tokeniser Only");
                queue = new TokenQueue();
                queue.Tokeniser = new Notation3Tokeniser(new StreamReader(file));
                Console.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                queue.InitialiseBuffer();
                Console.WriteLine("# Test Finished at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));


                //Use Notation 3 Parser
                if (!tokeniseOnly)
                {
                    Debug.WriteLine("Testing file " + file + " using Notation 3 Parser");
                    Console.WriteLine("# Using Notation 3 Parser");
                    Console.WriteLine("# Test Started at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    start = DateTime.Now;
                    Debug.WriteLine("Start " + start.ToString(TestSuite.TestSuiteTimeFormat));
                    Test(file, n3parser, output);
                    Console.WriteLine("# Test Finished at " + DateTime.Now.ToString(TestSuite.TestSuiteTimeFormat));
                    end = DateTime.Now;
                    diff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, start, end, Microsoft.VisualBasic.FirstDayOfWeek.Saturday, Microsoft.VisualBasic.FirstWeekOfYear.System);
                    Console.WriteLine("Read Time was " + diff + " seconds");
                    Debug.WriteLine("End " + end.ToString(TestSuite.TestSuiteTimeFormat));
                    Debug.WriteLine("Read Time was " + diff + " seconds");
                    Console.WriteLine();
                }
            }

            output.Close();

        }
Exemplo n.º 10
0
        public static void Main(string[] args)
        {
            StreamWriter output = new StreamWriter("WriterTests.txt");
            Console.SetOut(output);
            Console.WriteLine("## RDF Serialization Tests");

            try
            {
                //Create the Output Directory if required
                if (!Directory.Exists("writer_tests"))
                {
                    Console.WriteLine("Creating Output Directory");
                    Directory.CreateDirectory("writer_tests");
                }

                List<String> testFiles = new List<string>() {
                    "test.n3",
                    "InferenceTest.ttl",
                    "bnodes.ttl"
                };

                //Create list of Writers
                Console.WriteLine("Creating a set of Writer Classes");
                List<IRdfWriter> writers = new List<IRdfWriter>()
                {
                    new NTriplesWriter(),
                    new TurtleWriter(),
                    new CompressingTurtleWriter(),
                    new RdfXmlWriter(),
                    new FastRdfXmlWriter(),
                    new Notation3Writer(),
                    new RdfJsonWriter(),
                    new HtmlWriter()
                };

                //Create the Warning Handler
                RdfWriterWarning handler = delegate(String message) { Console.WriteLine("Writer Warning: " + message); };
                writers.ForEach(w => w.Warning += handler);

                //Create list of Compression levels
                List<int> compressionLevels = new List<int>() {
                    WriterCompressionLevel.None,
                    WriterCompressionLevel.Minimal,
                    WriterCompressionLevel.Default,
                    WriterCompressionLevel.Medium,
                    WriterCompressionLevel.More,
                    WriterCompressionLevel.High
                };

                //Create a set of Readers
                Console.WriteLine("Creating a set of Reader Classes");
                List<IRdfReader> readers = new List<IRdfReader>()
                {
                    new NTriplesParser(),
                    new TurtleParser(),
                    new TurtleParser(),
                    new RdfXmlParser(),
                    new RdfXmlParser(),
                    new Notation3Parser(),
                    new RdfJsonParser(),
                    new RdfAParser()
                };

                IRdfReader parser;

                int test = 0;
                foreach (String testFile in testFiles)
                {
                    //Read in the Test Graph
                    //parser = MimeTypesHelper.GetParser(MimeTypesHelper.GetMimeType(testFile));
                    parser = new Notation3Parser();
                    Graph g = new Graph();
                    Console.WriteLine("Attempting to load test file " + testFile);
                    parser.Load(g, testFile);
                    Console.WriteLine("RDF Loaded OK");

                    //Serialize with each parser
                    int i = 0;
                    foreach (IRdfWriter writer in writers)
                    {
                        if (writer is IHighSpeedWriter)
                        {
                            ((IHighSpeedWriter)writer).HighSpeedModePermitted = false;
                        }
                        if (writer is ICompressingWriter)
                        {
                            foreach (int c in compressionLevels)
                            {
                                ((ICompressingWriter)writer).CompressionLevel = c;
                                TestWriter(output, g, writer, readers[i], "tests-" + test + "-" + writer.GetType().ToString() + ".Compression." + c);
                            }
                        }
                        else
                        {
                            TestWriter(output, g, writer, readers[i], "tests-" + test + "-" + writer.GetType().ToString());
                        }

                        i++;
                    }

                    Console.WriteLine();
                    Console.WriteLine(new String('-', 100));
                    test++;
                }
            }
            catch (IOException ioEx)
            {
                reportError(output, "IO Exception", ioEx);
            }
            catch (RdfParseException parseEx)
            {
                reportError(output, "Parsing Exception", parseEx);
            }
            catch (RdfException rdfEx)
            {
                reportError(output, "RDF Exception", rdfEx);
            }
            catch (Exception ex)
            {
                reportError(output, "Other Exception", ex);
            }

            Console.WriteLine("Tests Finished");
            output.Close();
        }