コード例 #1
0
        /// <summary>
        /// Validates the given data to see if it is valid RDF Syntax
        /// </summary>
        /// <param name="data">Data</param>
        /// <returns></returns>
        public virtual ISyntaxValidationResults Validate(string data)
        {
            String message;
            try
            {
                CountHandler handler = new CountHandler();
                this._parser.Load(handler, new StringReader(data));

                message = "Valid RDF - " + handler.Count + " Triples - Parser: " + this._parser.GetType().Name;
                return new SyntaxValidationResults(true, message, handler);
            }
            catch (RdfParseException parseEx)
            {
                message = "Invalid RDF - Parsing Error from Parser: " + this._parser.GetType().Name + " - " + parseEx.Message;
                return new SyntaxValidationResults(message, parseEx);
            }
            catch (RdfException rdfEx)
            {
                message = "Invalid RDF - RDF Error from Parser: " + this._parser.GetType().Name + " - " + rdfEx.Message;
                return new SyntaxValidationResults(message, rdfEx);
            }
            catch (Exception ex)
            {
                message = "Invalid RDF - Error from Parser: " + this._parser.GetType().Name + " - " + ex.Message;
                return new SyntaxValidationResults(message, ex);
            }
        }
コード例 #2
0
        public void ParsingUriLoaderCountHandler()
        {
            Graph orig = new Graph();
            orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");

            CountHandler handler = new CountHandler();
            UriLoader.Load(handler, new Uri("http://www.dotnetrdf.org/configuration#"));

            Assert.AreEqual(orig.Triples.Count, handler.Count);
        }
コード例 #3
0
        public void ParsingFileLoaderCountHandlerTurtle()
        {
            EnsureTestData("temp.ttl");
            Graph orig = new Graph();
            orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            CountHandler handler = new CountHandler();
            FileLoader.Load(handler, "temp.ttl");

            Assert.AreEqual(orig.Triples.Count, handler.Count);
        }
コード例 #4
0
        public void ParsingFileLoaderCountHandlerTurtle()
        {
            Graph orig = new Graph();

            orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            CountHandler handler = new CountHandler();

            FileLoader.Load(handler, TestDataFile);

            Assert.Equal(orig.Triples.Count, handler.Count);
        }
コード例 #5
0
        public void ParsingUriLoaderCountHandler()
        {
            Graph orig = new Graph();

            orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");

            CountHandler handler = new CountHandler();

            EmbeddedResourceLoader.Load(handler, "VDS.RDF.Configuration.configuration.ttl");

            Assert.AreEqual(orig.Triples.Count, handler.Count);
        }
コード例 #6
0
        private void ParsingUsingCountHandler(String tempFile, IRdfReader parser)
        {
            Graph g = new Graph();
            EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
            g.SaveToFile(tempFile);

            CountHandler handler = new CountHandler();
            parser.Load(handler, tempFile);

            Console.WriteLine("Counted " + handler.Count + " Triples");
            Assert.AreEqual(g.Triples.Count, handler.Count, "Counts should have been equal");
        }
コード例 #7
0
        private void ParsingUsingCountHandler(String tempFile, IRdfReader parser)
        {
            Graph g = new Graph();

            EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
            g.SaveToFile(tempFile);

            CountHandler handler = new CountHandler();

            parser.Load(handler, tempFile);

            Console.WriteLine("Counted " + handler.Count + " Triples");
            Assert.AreEqual(g.Triples.Count, handler.Count, "Counts should have been equal");
        }
コード例 #8
0
        public void ParsingMultiHandlerGraphAndCount()
        {
            EnsureTestData();

            Graph        g        = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            CountHandler handler2 = new CountHandler();

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "multi_handler_tests_temp.ttl");

            Assert.Equal(g.Triples.Count, handler2.Count);
        }
コード例 #9
0
        public void ParsingChainedHandlerGraphAndCount()
        {
            EnsureTestData();

            Graph        g        = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            CountHandler handler2 = new CountHandler();

            ChainedHandler handler = new ChainedHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();

            parser.Load(handler, "temp.ttl");

            Assert.AreEqual(g.Triples.Count, handler2.Count, "Expected Counts to be the same");
        }
コード例 #10
0
        public void ParsingFileLoaderCountHandlerTurtle()
        {
            Graph orig = new Graph();

            orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            CountHandler handler = new CountHandler();

#if PORTABLE
            using (var input = File.OpenRead(TestDataFile))
            {
                StreamLoader.Load(handler, TestDataFile, input);
            }
#else
            FileLoader.Load(handler, "temp.ttl");
#endif

            Assert.AreEqual(orig.Triples.Count, handler.Count);
        }
コード例 #11
0
        public void ParsingSpeedTurtle10ThousandCountOnly()
        {
            EnsureTestData(10000, "10thou.ttl", new TurtleFormatter());

            CountHandler handler = new CountHandler();
            Stopwatch watch = new Stopwatch();
            TurtleParser parser = new TurtleParser();

            watch.Start();
            parser.Load(handler, "10thou.ttl");
            watch.Stop();

            Console.WriteLine(watch.Elapsed);
            this.CalculateSpeed(10000, watch);

            Assert.AreEqual(10000, handler.Count);
        }
コード例 #12
0
        /// <summary>
        /// Validates the data to see if it is valid RDF syntax which does not produce any warnings
        /// </summary>
        /// <param name="data">Data</param>
        /// <returns></returns>
        public override ISyntaxValidationResults Validate(string data)
        {
            String message;
            try
            {
                this._gotWarning = false;
                this._messages.Clear();
                CountHandler handler = new CountHandler();
                this._parser.Load(handler, new StringReader(data));

                if (!this._gotWarning)
                {
                    message = "Valid RDF - " + handler.Count + " Triples - Parser: " + this._parser.GetType().Name;
                    return new SyntaxValidationResults(true, message, handler);
                }
                else
                {
                    message = "Valid RDF with Warnings - " + handler.Count + " Triples - Parser: " + this._parser.GetType().Name + " - " + this._messages.Count + " Warnings";
                    int i = 1;
                    foreach (String m in this._messages)
                    {
                        message += "\n" + i + " - " + m;
                        i++;
                    }
                    return new SyntaxValidationResults(false, message, handler, this._messages);
                }
            }
            catch (RdfParseException parseEx)
            {
                message = "Invalid RDF - Parsing Error from Parser: " + this._parser.GetType().Name + " - " + parseEx.Message;
                return new SyntaxValidationResults(message, parseEx);
            }
            catch (RdfException rdfEx)
            {
                message = "Invalid RDF - RDF Error from Parser: " + this._parser.GetType().Name + " - " + rdfEx.Message;
                return new SyntaxValidationResults(message, rdfEx);
            }
            catch (Exception ex)
            {
                message = "Invalid RDF - Error from Parser: " + this._parser.GetType().Name + " - " + ex.Message;
                return new SyntaxValidationResults(message, ex);
            }
        }
コード例 #13
0
        public void ParsingMultiHandlerGraphAndCount()
        {
            EnsureTestData();

            Graph g = new Graph();
            GraphHandler handler1 = new GraphHandler(g);

            CountHandler handler2 = new CountHandler();

            MultiHandler handler = new MultiHandler(new IRdfHandler[] { handler1, handler2 });

            TurtleParser parser = new TurtleParser();
            parser.Load(handler, "temp.ttl");

            Assert.AreEqual(g.Triples.Count, handler2.Count, "Expected Counts to be the same");
 
        }