public override void AppendTriples(IEnumerable <Triple> ts, IDocument <StreamReader, TextWriter> document) { if (!ts.Any()) { return; } try { TextWriter writer = document.BeginWrite(true); foreach (Triple t in ts) { writer.WriteLine(this._formatter.Format(t)); } writer.Close(); document.EndWrite(); } catch (AlexandriaException) { throw; } catch (Exception ex) { document.EndWrite(); throw new AlexandriaException("Error appending Triples to Document " + document.Name, ex); } }
public void DeleteTriples(IEnumerable <Triple> ts, IDocument <Document, Document> document) { //Generate the JSON String Graph g = new Graph(); g.Assert(ts); String json = VDS.RDF.Writing.StringWriter.Write(g, this._writer); Object[] toDelete = MongoDBHelper.JsonArrayToObjects(json); //Then load the existing Triples from the Document Document mongoDoc = document.BeginWrite(false); if (mongoDoc["graph"] != null) { //Only need to do something if the Graph is non-empty List <Object> existing = MongoDBHelper.DocumentListToObjectList(mongoDoc["graph"]); foreach (Object obj in toDelete) { existing.Remove(obj); } mongoDoc["graph"] = existing.ToArray(); } document.EndWrite(); }
public void ToDocument(IGraph g, IDocument <Document, Document> document) { Document mongoDoc = document.BeginWrite(false); //Assign URI if necessary String graphUri = (g.BaseUri == null) ? String.Empty : g.BaseUri.ToString(); if (mongoDoc["uri"] == null) { mongoDoc["uri"] = graphUri; } document.EndWrite(); //Then create and save a Document for every Triple in the Graph foreach (Triple t in g.Triples) { 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); } } }
public void AppendTriples(IEnumerable <Triple> ts, IDocument <Document, Document> document) { //Generate our JSON String Graph g = new Graph(); g.Assert(ts); String json = VDS.RDF.Writing.StringWriter.Write(g, this._writer); //Then convert this to a Document Document mongoDoc = document.BeginWrite(false); Object[] temp = MongoDBHelper.JsonArrayToObjects(json); if (mongoDoc["graph"] != null) { List <Object> existing = MongoDBHelper.DocumentListToObjectList(mongoDoc["graph"]); existing.AddRange(temp); mongoDoc["graph"] = existing.ToArray(); } else { //If it was null this was a new Document mongoDoc["graph"] = temp; } document.EndWrite(); }
public void ToDocument(IGraph g, IDocument <Document, Document> document) { //Generate our JSON String String json = VDS.RDF.Writing.StringWriter.Write(g, this._writer); //Then convert this to a Document Document mongoDoc = document.BeginWrite(false); mongoDoc["graph"] = MongoDBHelper.JsonArrayToObjects(json); document.EndWrite(); }
public virtual void ToDocument(IGraph g, IDocument <StreamReader, TextWriter> document) { try { this._writer.Save(g, document.BeginWrite(false)); document.EndWrite(); } catch (AlexandriaException) { throw; } catch (Exception ex) { document.EndWrite(); throw new AlexandriaException("Error writing Graph to Document " + document.Name, ex); } }
public override void AppendTriples(IEnumerable<Triple> ts, IDocument<StreamReader,TextWriter> document) { if (!ts.Any()) return; try { TextWriter writer = document.BeginWrite(true); foreach (Triple t in ts) { writer.WriteLine(this._formatter.Format(t)); } writer.Close(); document.EndWrite(); } catch (AlexandriaException) { throw; } catch (Exception ex) { document.EndWrite(); throw new AlexandriaException("Error appending Triples to Document " + document.Name, ex); } }
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); } }
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); } }