Esempio n. 1
0
        public void ParsingSpeedTurtle100ThousandCountOnly()
        {
            try
            {
                Options.InternUris = false;
                EnsureTestData(100000, "100thou.ttl", new TurtleFormatter());

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

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

                Console.WriteLine(watch.Elapsed.ToString());
                this.CalculateSpeed(100000, watch);

                Assert.Equal(100000, handler.Count);
            }
            finally
            {
                Options.InternUris = true;
            }
        }
Esempio n. 2
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();
                _parser.Load(handler, new StringReader(data));

                message = "Valid RDF - " + handler.Count + " Triples - Parser: " + _parser.GetType().Name;
                return(new SyntaxValidationResults(true, message, handler));
            }
            catch (RdfParseException parseEx)
            {
                message = "Invalid RDF - Parsing Error from Parser: " + _parser.GetType().Name + " - " + parseEx.Message;
                return(new SyntaxValidationResults(message, parseEx));
            }
            catch (RdfException rdfEx)
            {
                message = "Invalid RDF - RDF Error from Parser: " + _parser.GetType().Name + " - " + rdfEx.Message;
                return(new SyntaxValidationResults(message, rdfEx));
            }
            catch (Exception ex)
            {
                message = "Invalid RDF - Error from Parser: " + _parser.GetType().Name + " - " + ex.Message;
                return(new SyntaxValidationResults(message, ex));
            }
        }
Esempio n. 3
0
            /// <summary>
            /// Initializes a new instance of the VirtualCodeUnitCollection class.
            /// </summary>
            /// <param name="collection">The collection of all code units.</param>
            /// <param name="countHandler">Retrieves the correct item count from the collection.</param>
            public VirtualCodeUnitCollection(CodeUnitCollection collection, CountHandler countHandler)
            {
                Param.AssertNotNull(collection, "collection");
                Param.AssertNotNull(countHandler, "countHandler");

                this.collection   = collection;
                this.countHandler = countHandler;
            }
        public void ItInvokesAnIRdfHandler()
        {
            RegisterConstructQueryGetHandler();
            var endpoint = GetQueryEndpoint();
            var handler  = new CountHandler();

            endpoint.QueryWithResultGraph(handler, "CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}");
            handler.Count.Should().Be(1);
        }
Esempio n. 5
0
        public void SparqlRemoteEndpointCountHandler()
        {
            SparqlRemoteEndpoint endpoint = RemoteEndpoints.GetQueryEndpoint();
            CountHandler         handler  = new CountHandler();

            endpoint.QueryWithResultGraph(handler, "CONSTRUCT { ?s ?p ?o } WHERE { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }");

            Console.WriteLine("Triple Count: " + handler.Count);
            Assert.NotEqual(0, handler.Count);
        }
Esempio n. 6
0
        public async Task AuthHandlerAuthenticateCachesTicket(string scheme)
        {
            var handler = new CountHandler(scheme);
            var context = new AuthenticateContext(scheme);
            await handler.AuthenticateAsync(context);

            await handler.AuthenticateAsync(context);

            Assert.Equal(1, handler.AuthCount);
        }
            public static async Task <CountHandler> Create(string scheme)
            {
                var handler = new CountHandler();
                var context = new DefaultHttpContext();

                context.Features.Set <IHttpResponseFeature>(new TestResponse());
                await handler.InitializeAsync(new CountOptions(), context, new LoggerFactory().CreateLogger("CountHandler"), Framework.WebEncoders.UrlEncoder.Default);

                handler.Options.AuthenticationScheme    = scheme;
                handler.Options.AutomaticAuthentication = true;
                return(handler);
            }
        private void TestCountHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Graph expected = processor.ProcessQuery(q) as Graph;

            Assert.NotNull(expected);

            CountHandler handler = new CountHandler();

            processor.ProcessQuery(handler, null, q);

            Assert.Equal(expected.Triples.Count, handler.Count);
        }
Esempio n. 9
0
        public void ParsingRdfXmlStreamingDoesNotExhaustMemory()
        {
            IGraph         g            = new Graph();
            GraphHandler   graphHandler = new GraphHandler(g);
            PagingHandler  paging       = new PagingHandler(graphHandler, 1000);
            CountHandler   counter      = new CountHandler();
            ChainedHandler handler      = new ChainedHandler(new IRdfHandler[] { paging, counter });

            GZippedRdfXmlParser parser = new GZippedRdfXmlParser(RdfXmlParserMode.Streaming);

            parser.Load(handler, @"resources\oom.rdf.gz");

            Assert.False(g.IsEmpty);
            Assert.Equal(1000, counter.Count);
            // Note that the source produces some duplicate triples so triples in the graph will be at most 1000
            Assert.True(g.Triples.Count <= 1000);
        }
        private void TestCountHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Graph expected = processor.ProcessQuery(q) as Graph;

            if (expected == null)
            {
                Assert.Fail("Query failed to return a Graph as expected");
            }

            CountHandler handler = new CountHandler();

            processor.ProcessQuery(handler, null, q);

            Assert.AreEqual(expected.Triples.Count, handler.Count, "Counts should have been equal");
        }
Esempio n. 11
0
        protected override TaskValueResult <int> RunTaskInternal()
        {
            if (this._graphUri != null && !this._graphUri.Equals(String.Empty))
            {
                this.Information = "Counting Triples for Graph " + this._graphUri.ToString() + "...";
            }
            else
            {
                this.Information = "Counting Triples for Default Graph...";
            }

            this._counter   = new CountHandler();
            this._canceller = new CancellableHandler(this._counter);
            this._manager.LoadGraph(this._canceller, this._graphUri);
            this.Information = "Graph contains " + this._counter.Count + " Triple(s)";
            return(new TaskValueResult <int>(this._counter.Count));
        }
Esempio n. 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
            {
                _gotWarning = false;
                _messages.Clear();
                CountHandler handler = new CountHandler();
                _parser.Load(handler, new StringReader(data));

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

                Graph orig = new Graph();
                orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                orig.BaseUri = new Uri("http://example.org/storage/dydra/tests/counting");

                DydraConnector dydra = DydraTests.GetConnection();
                dydra.DeleteGraph(orig.BaseUri);
                dydra.SaveGraph(orig);

                CountHandler handler = new CountHandler();
                dydra.LoadGraph(handler, orig.BaseUri);

                Assert.AreEqual(orig.Triples.Count, handler.Count, "Triple Counts should be equal");
            }
            finally
            {
                Options.HttpDebugging = false;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Reading-RDF
        /// </summary>
        public void PlayWithReadingRdf()
        {
            #region Reading RDF from Files
            IGraph       g         = new Graph();
            IGraph       h         = new Graph();
            TurtleParser ttlparser = new TurtleParser();

            // Load using a Filename
            ttlparser.Load(g, "HelloWorld.ttl");

            // Load using a StreamReader
            ttlparser.Load(h, new StreamReader("HelloWorld.ttl"));

            try
            {
                IGraph         g2       = new Graph();
                NTriplesParser ntparser = new NTriplesParser();

                //Load using Filename
                ntparser.Load(g2, "HelloWorld.nt");
            }
            catch (RdfParseException parseEx)
            {
                //This indicates a parser error e.g unexpected character, premature end of input, invalid syntax etc.
                Console.WriteLine("Parser Error");
                Console.WriteLine(parseEx.Message);
            }
            catch (RdfException rdfEx)
            {
                //This represents a RDF error e.g. illegal triple for the given syntax, undefined namespace
                Console.WriteLine("RDF Error");
                Console.WriteLine(rdfEx.Message);
            }
            #endregion

            #region Reading RDF from URIs

            try
            {
                IGraph g3 = new Graph();
                //UriLoader.Load(g3, new Uri("http://dbpedia.org/resource/Barack_Obama"));
            }
            catch (RdfParseException parseEx)
            {
                //This indicates a parser error e.g unexpected character, premature end of input, invalid syntax etc.
                Console.WriteLine("Parser Error");
                Console.WriteLine(parseEx.Message);
            }
            catch (RdfException rdfEx)
            {
                //This represents a RDF error e.g. illegal triple for the given syntax, undefined namespace
                Console.WriteLine("RDF Error");
                Console.WriteLine(rdfEx.Message);
            }
            #endregion

            #region Reading RDF from Embedded Resources

            try
            {
                IGraph g4 = new Graph();
                EmbeddedResourceLoader.Load(g4, "embedded.ttl, PlayWithDotNetRDF");
                Console.WriteLine(g4.IsEmpty);
            }
            catch (RdfParseException parseEx)
            {
                //This indicates a parser error e.g unexpected character, premature end of input, invalid syntax etc.
                Console.WriteLine("Parser Error");
                Console.WriteLine(parseEx.Message);
            }
            catch (RdfException rdfEx)
            {
                //This represents a RDF error e.g. illegal triple for the given syntax, undefined namespace
                Console.WriteLine("RDF Error");
                Console.WriteLine(rdfEx.Message);
            }
            #endregion

            #region Reading RDF from Strings

            Graph g5 = new Graph();
            StringParser.Parse(g5, "<http://example.org/a> <http://example.org/b> <http://example.org/c>.");

            Graph          g6     = new Graph();
            NTriplesParser parser = new NTriplesParser();
            parser.Load(g6, new StringReader("<http://example.org/a> <http://example.org/b> <http://example.org/c>."));

            #endregion

            #region Store Parsers

            /*
             * TripleStore store = new TripleStore();
             * TriGParser trigparser = new TriGParser();
             *
             * //Load the Store
             * trigparser.Load(store, "Example.trig");
             */

            #endregion

            #region Advanced Parsing

            // Create a Handler and use it for parsing
            CountHandler handler      = new CountHandler();
            TurtleParser turtleParser = new TurtleParser();
            turtleParser.Load(handler, "HelloWorld.ttl");

            //Print the resulting count
            Console.WriteLine(handler.Count + " Triple(s)");

            // https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Handlers-API
            #endregion

            /*
             * Parser Class         Supported Input
             * NTriplesParser       NTriples
             * Notation3Parser  Notation 3, Turtle, NTriples, some forms of TriG
             * NQuadsParser         NQuads, NTriples
             * RdfAParser           RDFa 1.0 embedded in (X)HTML, some RDFa 1.1 support
             * RdfJsonParser        RDF/JSON (Talis specification)
             * RdfXmlParser         RDF/XML
             * TriGParser           TriG
             * TriXParser           TriX
             * TurtleParser         Turtle, NTriples
             * JsonLdParser         JSON-LD
             */
        }