コード例 #1
0
        public void ToHandler(IRdfHandler handler, IDocument <Document, Document> document)
        {
            Document mongoDoc = document.BeginRead();
            Document lookup   = new Document();

            lookup["graphuri"] = mongoDoc["uri"];
            document.EndRead();

            IEnumerable <Triple> ts = new MongoDBTripleCentricEnumerable(this._manager, lookup);

            handler.Apply(ts);
        }
コード例 #2
0
        public void ToGraph(IGraph g, IDocument <Document, Document> document)
        {
            Document mongoDoc = document.BeginRead();
            Document lookup   = new Document();

            lookup["graphuri"] = mongoDoc["uri"];
            document.EndRead();

            IEnumerable <Triple> ts = new MongoDBTripleCentricEnumerable(this._manager, lookup);

            foreach (Triple t in ts)
            {
                g.Assert(Tools.CopyTriple(t, g));
            }
        }
コード例 #3
0
        public void ToHandler(IRdfHandler handler, IDocument <Document, Document> document)
        {
            //Get our JSON String
            Document mongoDoc = document.BeginRead();
            String   json     = MongoDBHelper.DocumentListToJsonArray(mongoDoc["graph"]);

            document.EndRead();
            if (json.Equals(String.Empty))
            {
                return;
            }

            //Then parse this
            this._parser.Load(handler, new StringReader(json));
        }
コード例 #4
0
        public void DeleteTriples(IEnumerable <Triple> ts, IDocument <Document, Document> document)
        {
            Document mongoDoc = document.BeginRead();
            String   graphUri = (String)mongoDoc["uri"];

            document.EndRead();

            foreach (Triple t in ts)
            {
                Document tripleDoc = new Document();
                tripleDoc["subject"]   = this._formatter.Format(t.Subject);
                tripleDoc["predicate"] = this._formatter.Format(t.Predicate);
                tripleDoc["object"]    = this._formatter.Format(t.Object);
                tripleDoc["graphuri"]  = graphUri;

                this._manager.Database[this._manager.Collection].Delete(tripleDoc);
            }
        }
コード例 #5
0
 public virtual void ToHandler(IRdfHandler handler, IDocument <StreamReader, TextWriter> document)
 {
     if (document.Exists)
     {
         try
         {
             this._parser.Load(handler, document.BeginRead());
             document.EndRead();
         }
         catch (AlexandriaException)
         {
             throw;
         }
         catch (Exception ex)
         {
             document.EndRead();
             throw new AlexandriaException("Error reading Document " + document.Name + " with a RDF Handler", ex);
         }
     }
 }
コード例 #6
0
 public virtual void ToGraph(IGraph g, IDocument <StreamReader, TextWriter> document)
 {
     if (document.Exists)
     {
         try
         {
             this._parser.Load(g, document.BeginRead());
             document.EndRead();
         }
         catch (AlexandriaException)
         {
             throw;
         }
         catch (Exception ex)
         {
             document.EndRead();
             throw new AlexandriaException("Error reading Document " + document.Name + " into a Graph", ex);
         }
     }
 }
コード例 #7
0
        public void AppendTriples(IEnumerable <Triple> ts, IDocument <Document, Document> document)
        {
            Document mongoDoc = document.BeginRead();
            String   graphUri = (String)mongoDoc["uri"];

            document.EndRead();

            foreach (Triple t in ts)
            {
                Document tripleDoc = new Document();
                tripleDoc["subject"]   = this._formatter.Format(t.Subject);
                tripleDoc["predicate"] = this._formatter.Format(t.Predicate);
                tripleDoc["object"]    = this._formatter.Format(t.Object);
                tripleDoc["graphuri"]  = graphUri;

                //Only Save if not already in Store
                if (this._manager.Database[this._manager.Collection].FindOne(tripleDoc) == null)
                {
                    this._manager.Database[this._manager.Collection].Save(tripleDoc);
                }
            }
        }
コード例 #8
0
        public override void DeleteTriples(IEnumerable <Triple> ts, IDocument <StreamReader, TextWriter> document)
        {
            if (!ts.Any())
            {
                return;
            }

            //Generate the String forms of these Triples
            HashSet <String> triples = new HashSet <string>();

            foreach (Triple t in ts)
            {
                triples.Add(this._formatter.Format(t));
            }

            try
            {
                //Now read through the file line by line
                int           lineCount = 0, editedLineCount = 0;
                StringBuilder editedOutput = new StringBuilder();
                StreamReader  reader       = document.BeginRead();

                while (!reader.EndOfStream)
                {
                    lineCount++;
                    String line = reader.ReadLine();

                    //If the Line is a Triple that isn't marked for deletion we pass it through to our edited output
                    if (!triples.Contains(line))
                    {
                        editedOutput.AppendLine(line);
                        editedLineCount++;
                    }
                }
                reader.Close();
                document.EndRead();

                if (lineCount > editedLineCount || lineCount == 0)
                {
                    //We deleted some Triples so need to reserialize the data
                    try
                    {
                        if (editedLineCount > 0)
                        {
                            TextWriter writer = document.BeginWrite(false);
                            writer.Write(editedOutput.ToString());
                            writer.Close();
                            document.EndWrite();
                        }
                        else
                        {
                            //If there are no lines in the result then delete the document
                            document.DocumentManager.ReleaseDocument(document.Name);
                            document.DocumentManager.DeleteDocument(document.Name);
                        }
                    }
                    catch (AlexandriaException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        document.EndWrite();
                        throw new AlexandriaException("Error deleting Triples from Document " + document.Name, ex);
                    }
                }
            }
            catch (AlexandriaException)
            {
                throw;
            }
            catch (Exception ex)
            {
                document.EndRead();
                throw new AlexandriaException("Error deleting Triples from Document " + document.Name, ex);
            }
        }
コード例 #9
0
ファイル: NTriplesAdaptor.cs プロジェクト: jbunzel/MvcRQ_git
        public override void DeleteTriples(IEnumerable<Triple> ts, IDocument<StreamReader,TextWriter> document)
        {
            if (!ts.Any()) return;

            //Generate the String forms of these Triples
            HashSet<String> triples = new HashSet<string>();
            foreach (Triple t in ts)
            {
                triples.Add(this._formatter.Format(t));
            }

            try
            {
                //Now read through the file line by line
                int lineCount = 0, editedLineCount = 0;
                StringBuilder editedOutput = new StringBuilder();
                StreamReader reader = document.BeginRead();

                while (!reader.EndOfStream)
                {
                    lineCount++;
                    String line = reader.ReadLine();

                    //If the Line is a Triple that isn't marked for deletion we pass it through to our edited output
                    if (!triples.Contains(line))
                    {
                        editedOutput.AppendLine(line);
                        editedLineCount++;
                    }
                }
                reader.Close();
                document.EndRead();

                if (lineCount > editedLineCount || lineCount == 0)
                {
                    //We deleted some Triples so need to reserialize the data
                    try
                    {
                        if (editedLineCount > 0)
                        {
                            TextWriter writer = document.BeginWrite(false);
                            writer.Write(editedOutput.ToString());
                            writer.Close();
                            document.EndWrite();
                        }
                        else
                        {
                            //If there are no lines in the result then delete the document
                            document.DocumentManager.ReleaseDocument(document.Name);
                            document.DocumentManager.DeleteDocument(document.Name);
                        }
                    }
                    catch (AlexandriaException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        document.EndWrite();
                        throw new AlexandriaException("Error deleting Triples from Document " + document.Name, ex);
                    }
                }
            }
            catch (AlexandriaException)
            {
                throw;
            }
            catch (Exception ex)
            {
                document.EndRead();
                throw new AlexandriaException("Error deleting Triples from Document " + document.Name, ex);
            }
        }