Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco authored and Marco committed Dec 8, 2018
1 parent 18995a6 commit 04dfb27
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 55 deletions.
15 changes: 0 additions & 15 deletions RDFSharp/Model/RDFGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,6 @@ public RDFGraph AddTriple(RDFTriple triple) {
}
return this;
}
/// <summary>
/// Adds the given triple to the graph, avoiding duplicate insertions
/// (this is internal version which does not raise events)
/// </summary>
internal RDFGraph AddTripleInternal(RDFTriple triple) {
if (triple != null) {
if (!this.Triples.ContainsKey(triple.TripleID)) {
//Add triple
this.Triples.Add(triple.TripleID, triple);
//Add index
this.GraphIndex.AddIndex(triple);
}
}
return this;
}

/// <summary>
/// Adds the given container to the graph
Expand Down
92 changes: 54 additions & 38 deletions RDFSharp/Store/Engines/RDFMemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ public override RDFStore MergeGraph(RDFGraph graph) {
public override RDFStore AddQuadruple(RDFQuadruple quadruple) {
if (quadruple != null) {
if (!this.Quadruples.ContainsKey(quadruple.QuadrupleID)) {
//Add quadruple
this.Quadruples.Add(quadruple.QuadrupleID, quadruple);
RDFStoreEvents.RaiseOnQuadrupleAdded(String.Format("Quadruple '{0}' has been added to the Store '{1}'.", quadruple, this));
//Index update
//Add index
this.StoreIndex.AddIndex(quadruple);
//Raise event
RDFStoreEvents.RaiseOnQuadrupleAdded(String.Format("Quadruple '{0}' has been added to the Store '{1}'.", quadruple, this));
}
}
return this;
Expand All @@ -164,10 +166,12 @@ public override RDFStore AddQuadruple(RDFQuadruple quadruple) {
/// </summary>
public override RDFStore RemoveQuadruple(RDFQuadruple quadruple) {
if (this.ContainsQuadruple(quadruple)) {
//Remove quadruple
this.Quadruples.Remove(quadruple.QuadrupleID);
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quadruple, this));
//Index update
//Remove index
this.StoreIndex.RemoveIndex(quadruple);
//Raise event
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quadruple, this));
}
return this;
}
Expand All @@ -176,12 +180,14 @@ public override RDFStore RemoveQuadruple(RDFQuadruple quadruple) {
/// Removes the quadruples with the given context
/// </summary>
public override RDFStore RemoveQuadruplesByContext(RDFContext contextResource) {
if (contextResource != null) {
foreach (var quadruple in this.SelectQuadruplesByContext(contextResource)) {
this.Quadruples.Remove(quadruple.QuadrupleID);
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quadruple, this));
//Index update
this.StoreIndex.RemoveIndex(quadruple);
if (contextResource != null) {
foreach (var quad in this.SelectQuadruplesByContext(contextResource)) {
//Remove quadruple
this.Quadruples.Remove(quad.QuadrupleID);
//Remove index
this.StoreIndex.RemoveIndex(quad);
//Raise event
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quad, this));
}
}
return this;
Expand All @@ -191,12 +197,14 @@ public override RDFStore RemoveQuadruplesByContext(RDFContext contextResource) {
/// Removes the quadruples with the given subject
/// </summary>
public override RDFStore RemoveQuadruplesBySubject(RDFResource subjectResource) {
if (subjectResource != null) {
foreach (var quadruple in this.SelectQuadruplesBySubject(subjectResource)) {
this.Quadruples.Remove(quadruple.QuadrupleID);
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quadruple, this));
//Index update
this.StoreIndex.RemoveIndex(quadruple);
if (subjectResource != null) {
foreach (var quad in this.SelectQuadruplesBySubject(subjectResource)) {
//Remove quadruple
this.Quadruples.Remove(quad.QuadrupleID);
//Remove index
this.StoreIndex.RemoveIndex(quad);
//Raise event
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quad, this));
}
}
return this;
Expand All @@ -206,12 +214,14 @@ public override RDFStore RemoveQuadruplesBySubject(RDFResource subjectResource)
/// Removes the quadruples with the given (non-blank) predicate
/// </summary>
public override RDFStore RemoveQuadruplesByPredicate(RDFResource predicateResource) {
if (predicateResource != null && !predicateResource.IsBlank) {
foreach (var quadruple in this.SelectQuadruplesByPredicate(predicateResource)) {
this.Quadruples.Remove(quadruple.QuadrupleID);
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quadruple, this));
//Index update
this.StoreIndex.RemoveIndex(quadruple);
if (predicateResource != null && !predicateResource.IsBlank) {
foreach (var quad in this.SelectQuadruplesByPredicate(predicateResource)) {
//Remove quadruple
this.Quadruples.Remove(quad.QuadrupleID);
//Remove index
this.StoreIndex.RemoveIndex(quad);
//Raise event
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quad, this));
}
}
return this;
Expand All @@ -221,12 +231,14 @@ public override RDFStore RemoveQuadruplesByPredicate(RDFResource predicateResour
/// Removes the quadruples with the given resource as object
/// </summary>
public override RDFStore RemoveQuadruplesByObject(RDFResource objectResource) {
if (objectResource != null) {
foreach (var quadruple in this.SelectQuadruplesByObject(objectResource)) {
this.Quadruples.Remove(quadruple.QuadrupleID);
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quadruple, this));
//Index update
this.StoreIndex.RemoveIndex(quadruple);
if (objectResource != null) {
foreach (var quad in this.SelectQuadruplesByObject(objectResource)) {
//Remove quadruple
this.Quadruples.Remove(quad.QuadrupleID);
//Remove index
this.StoreIndex.RemoveIndex(quad);
//Raise event
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quad, this));
}
}
return this;
Expand All @@ -236,12 +248,14 @@ public override RDFStore RemoveQuadruplesByObject(RDFResource objectResource) {
/// Removes the quadruples with the given literal as object
/// </summary>
public override RDFStore RemoveQuadruplesByLiteral(RDFLiteral literalObject) {
if (literalObject != null) {
foreach (var quadruple in this.SelectQuadruplesByLiteral(literalObject)) {
this.Quadruples.Remove(quadruple.QuadrupleID);
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quadruple, this));
//Index update
this.StoreIndex.RemoveIndex(quadruple);
if (literalObject != null) {
foreach (var quad in this.SelectQuadruplesByLiteral(literalObject)) {
//Remove quadruple
this.Quadruples.Remove(quad.QuadrupleID);
//Remove index
this.StoreIndex.RemoveIndex(quad);
//Raise event
RDFStoreEvents.RaiseOnQuadrupleRemoved(String.Format("Quadruple '{0}' has been removed from the Store '{1}'.", quad, this));
}
}
return this;
Expand All @@ -251,10 +265,12 @@ public override RDFStore RemoveQuadruplesByLiteral(RDFLiteral literalObject) {
/// Clears the quadruples of the store
/// </summary>
public override void ClearQuadruples() {
//Clear quadruples
this.Quadruples.Clear();
RDFStoreEvents.RaiseOnStoreCleared(String.Format("Store '{0}' has been cleared.", this));
//Index update
//Clear index
this.StoreIndex.ClearIndex();
//Raise event
RDFStoreEvents.RaiseOnStoreCleared(String.Format("Store '{0}' has been cleared.", this));
}
#endregion

Expand Down Expand Up @@ -350,12 +366,12 @@ public RDFMemoryStore DifferenceWith(RDFStore store) {

#region Convert

#region Importers
#region Import
/// <summary>
/// Creates a memory store from a file of the given RDF format.
/// </summary>
public static RDFMemoryStore FromFile(RDFStoreEnums.RDFFormats rdfFormat, String filepath) {
if (filepath != null) {
if(!String.IsNullOrEmpty(filepath)) {
if (File.Exists(filepath)) {
switch (rdfFormat) {
case RDFStoreEnums.RDFFormats.TriX:
Expand Down
4 changes: 2 additions & 2 deletions RDFSharp/Store/RDFStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ internal abstract RDFMemoryStore SelectQuadruples(RDFContext contextResource,

#region Convert

#region Exporters
#region Export
/// <summary>
/// Writes the store into a file in the given RDF format.
/// </summary>
public void ToFile(RDFStoreEnums.RDFFormats rdfFormat, String filepath) {
if (filepath != null) {
if(!String.IsNullOrEmpty(filepath)) {
switch (rdfFormat) {
case RDFStoreEnums.RDFFormats.NQuads:
RDFNQuads.Serialize(this, filepath);
Expand Down

0 comments on commit 04dfb27

Please sign in to comment.