private void WritingTriGActual()
        {
            Graph g = new Graph();
            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = null;
            TripleStore store = new TripleStore();
            store.Add(g);

            TriGWriter writer = new TriGWriter();
            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            writer.Save(store, new TextWriterParams(strWriter));

            Console.WriteLine(strWriter.ToString());

            Assert.IsFalse(strWriter.ToString().Equals(String.Empty));
        }
        public void WritingTriGUncompressedSingleThreaded()
        {
            Graph g = new Graph();
            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = null;
            TripleStore store = new TripleStore();
            store.Add(g);

            TriGWriter writer = new TriGWriter();
            writer.UseMultiThreadedWriting = false;
            writer.CompressionLevel = WriterCompressionLevel.None;
            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            writer.Save(store, new TextWriterParams(strWriter));

            Console.WriteLine(strWriter.ToString());

            Assert.IsFalse(strWriter.ToString().Equals(String.Empty));
        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            this.sfdExport.FilterIndex = this.cboExportFormat.SelectedIndex+1;
            if (this.sfdExport.ShowDialog() == DialogResult.OK)
            {
                String destFile = this.sfdExport.FileName;

                //Select the Writer
                IStoreWriter writer;
                switch (this.cboExportFormat.SelectedIndex)
                {
                    case 0:
                        writer = new TriGWriter();
                        break;
                    case 1:
                        writer = new TriXWriter();
                        break;
                    case 2:
                        writer = new NQuadsWriter();
                        break;
                    default:
                        writer = new TriGWriter();
                        break;
                }

                //Check the Extension matches the output format
                String ext = MimeTypesHelper.GetFileExtension(writer);
                if (!Path.GetExtension(destFile).Equals("." + ext))
                {
                    destFile = Path.Combine(Path.GetDirectoryName(destFile), Path.GetFileNameWithoutExtension(destFile) + "." + ext);
                }

                //Estimate Load Time
                int graphTriples = Int32.Parse(this.lvwDBInfo.Items[3].SubItems[1].Text);
                int loadTime = graphTriples / 25000;

                if (MessageBox.Show("Are you sure you wish to export this Store?  To do this your entire Store must first be loaded into memory - we estimate that this will take approximately " + loadTime + " seconds - and then it will be written to disk.  Are you sure you wish to proceed?", "Confirm Export", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    //Export
                    try
                    {
                        System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
                        timer.Start();
                        ThreadedSqlTripleStore store = new ThreadedSqlTripleStore(this._connection.ThreadedManager, 8, false);
                        timer.Stop();
                        double actualLoadTime = (double)timer.ElapsedMilliseconds / 1000d;
                        timer.Reset();
                        timer.Start();
                        writer.Save(store, new StreamParams(destFile));
                        timer.Stop();
                        double actualWriteTime = (double)timer.ElapsedMilliseconds / 1000d;

                        MessageBox.Show("Export completed successfully to file '" + destFile + "'\n\nLoad took " + actualLoadTime + " seconds - Writing took " + actualWriteTime + " seconds - Export took " + (actualLoadTime+actualWriteTime) + " seconds total", "Export Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Export failed due to the following error:\n" + ex.Message, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }                        
                }
                
            }
        }
        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();
            }
        }
Beispiel #5
0
        public void Dispose()
        {
            //Create all of the directories required for the file
            var f = new FileInfo(_outputPath);
            f.Directory.Create();

            if (this._outputFormat == ERdfFormat.RdfXml)
            {
                using (XmlTextWriter xmlWriter = new XmlTextWriter(_outputPath, new UTF8Encoding(false)))
                    //Set encoding
                {
                    _output.Save(xmlWriter);
                }
            }
            else if (this._outputFormat == ERdfFormat.TriG)
            {
                string fileNameAsTrig = GetFilePathBasedOnFormat();
                var outparams = new StreamParams(fileNameAsTrig);
                outparams.Encoding = Encoding.UTF8;
                var writer = new TriGWriter();

                if (_store == null)
                {
                    var g = GetXmlDocumentAsGraph();
                    _store = new TripleStore();
                    _store.Add(g, true);
                }

                writer.Save(_store, outparams);
            }
            else if (this._outputFormat == ERdfFormat.Turtle)
            {
                var g = GetXmlDocumentAsGraph();
                string filePathForFormat = GetFilePathBasedOnFormat();
                var writer = new TurtleWriter(TurtleSyntax.W3C);
                writer.Save(g, filePathForFormat);
            }
            else if (this._outputFormat == ERdfFormat.NTriples)
            {
                var g = GetXmlDocumentAsGraph();
                string filePathForFormat = GetFilePathBasedOnFormat();
                var writer = new NTriplesWriter();
                writer.Save(g, filePathForFormat);
            }
            else if (this._outputFormat == ERdfFormat.N3)
            {
                var g = GetXmlDocumentAsGraph();
                string filePathForFormat = GetFilePathBasedOnFormat();
                var writer = new Notation3Writer();
                writer.Save(g, filePathForFormat);
            }
            else if (this._outputFormat == ERdfFormat.NQuads)
            {
                string filePathForFormat = GetFilePathBasedOnFormat();
                var outparams = new StreamParams(filePathForFormat);
                outparams.Encoding = Encoding.UTF8;

                if (_store == null)
                {
                    var g = GetXmlDocumentAsGraph();
                    _store = new TripleStore();
                    _store.Add(g, true);
                }

                var writer = new NQuadsWriter();
                writer.Save(_store, outparams);
            }

            //make sure it's not null - can happen if no graphs have yet to be asserted!!
            if (_store != null)
            {
                foreach (var graph in _store.Graphs)
                {
                    graph.Dispose();
                }
                _store.Dispose();
                GC.Collect();
            }
        }