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();
            }
        }
        /// <summary>
        /// Internal Method which performs multi-threaded writing of data
        /// </summary>
        private void SaveGraphs(FolderStoreWriterContext context)
        {
            //Create the relevant Writer
            IRdfWriter writer;
            switch (context.Format)
            {
                case FolderStoreFormat.Turtle:
                    writer = new TurtleWriter();
                    break;
                case FolderStoreFormat.Notation3:
                    writer = new Notation3Writer();
                    break;
                case FolderStoreFormat.RdfXml:
#if !NO_XMLDOM
                    writer = new FastRdfXmlWriter();
#else
                    writer = new RdfXmlWriter();
#endif
                    break;
                default:
                    writer = new TurtleWriter();
                    break;
            }

            try
            {
                Uri u = context.GetNextURI();
                while (u != null)
                {
                    //Get the Graph from the Store
                    IGraph g = context.Store.Graphs[u];

                    //Write to Disk
                    String destFile = Path.Combine(context.Folder, u.GetSha256Hash());
                    switch (context.Format)
                    {
                        case FolderStoreFormat.Turtle:
                            destFile += ".ttl";
                            break;
                        case FolderStoreFormat.Notation3:
                            destFile += ".n3";
                            break;
                        case FolderStoreFormat.RdfXml:
                            destFile += ".rdf";
                            break;
                        default:
                            destFile += ".ttl";
                            break;
                    }
                    writer.Save(g, destFile);

                    //Get the Next Uri
                    u = context.GetNextURI();
                }
            }
            catch (ThreadAbortException)
            {
                //We've been terminated, don't do anything
#if !SILVERLIGHT
                Thread.ResetAbort();
#endif
            }
            catch (Exception ex)
            {
                throw new RdfStorageException("Error in Threaded Writer in Thread ID " + Thread.CurrentThread.ManagedThreadId, ex);
            }
        }
 /// <summary>
 /// Saves Graph containing Facebook context items to a file for later restore
 /// </summary>
 public void SaveContextToFile()
 {
     foreach (IGraph g in _store.Graphs)
     {
         Notation3Writer n3w = new Notation3Writer();
         n3w.Save(_g, @"../../../SavedStore.n3");
     }
 }
Exemple #4
0
        /// <summary>
        /// Internal Method which performs multi-threaded writing of data
        /// </summary>
        private void SaveGraphs(FolderStoreWriterContext context)
        {
            //Create the relevant Writer
            IRdfWriter writer;

            switch (context.Format)
            {
            case FolderStoreFormat.Turtle:
                writer = new TurtleWriter();
                break;

            case FolderStoreFormat.Notation3:
                writer = new Notation3Writer();
                break;

            case FolderStoreFormat.RdfXml:
#if !NO_XMLDOM
                writer = new FastRdfXmlWriter();
#else
                writer = new RdfXmlWriter();
#endif
                break;

            default:
                writer = new TurtleWriter();
                break;
            }

            try
            {
                Uri u = context.GetNextURI();
                while (u != null)
                {
                    //Get the Graph from the Store
                    IGraph g = context.Store.Graphs[u];

                    //Write to Disk
                    String destFile = Path.Combine(context.Folder, u.GetSha256Hash());
                    switch (context.Format)
                    {
                    case FolderStoreFormat.Turtle:
                        destFile += ".ttl";
                        break;

                    case FolderStoreFormat.Notation3:
                        destFile += ".n3";
                        break;

                    case FolderStoreFormat.RdfXml:
                        destFile += ".rdf";
                        break;

                    default:
                        destFile += ".ttl";
                        break;
                    }
                    writer.Save(g, destFile);

                    //Get the Next Uri
                    u = context.GetNextURI();
                }
            }
            catch (ThreadAbortException)
            {
                //We've been terminated, don't do anything
#if !SILVERLIGHT
                Thread.ResetAbort();
#endif
            }
            catch (Exception ex)
            {
                throw new RdfStorageException("Error in Threaded Writer in Thread ID " + Thread.CurrentThread.ManagedThreadId, ex);
            }
        }
Exemple #5
0
 public void SaveGraphToFile()
 {
     Notation3Writer n3w = new Notation3Writer();
     n3w.Save(_g, @"../../../SavedStore.n3");
 }
Exemple #6
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();
            }
        }