diff --git a/RDFSharp.Test/Model/RDFGraphTest.cs b/RDFSharp.Test/Model/RDFGraphTest.cs
index db97008e..9a760c15 100644
--- a/RDFSharp.Test/Model/RDFGraphTest.cs
+++ b/RDFSharp.Test/Model/RDFGraphTest.cs
@@ -18,6 +18,7 @@ limitations under the License.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using System.IO;
+using System.Linq;
using System;
using System.Collections.Generic;
@@ -221,6 +222,19 @@ public void ShouldAddTriple()
Assert.IsTrue(graph.IndexedTriples.ContainsKey(triple.TripleID));
}
+ [TestMethod]
+ public void ShouldAddTripleAsInference()
+ {
+ RDFGraph graph = new RDFGraph();
+ RDFTriple triple = new RDFTriple(new RDFResource("http://subj/"), new RDFResource("http://pred/"), new RDFResource("http://obj/")).SetInference();
+ graph.AddTriple(triple);
+
+ Assert.IsTrue(graph.TriplesCount == 1);
+ Assert.IsTrue(graph.IndexedTriples.ContainsKey(triple.TripleID));
+ Assert.IsTrue(graph.Count(t => t.IsInference) == 1);
+
+ }
+
[TestMethod]
public void ShouldNotAddDuplicateTriples()
{
diff --git a/RDFSharp.Test/RDFSharp.Test.csproj b/RDFSharp.Test/RDFSharp.Test.csproj
index 8cb26292..904a596b 100644
--- a/RDFSharp.Test/RDFSharp.Test.csproj
+++ b/RDFSharp.Test/RDFSharp.Test.csproj
@@ -3,7 +3,7 @@
RDFSharp.Test
RDFSharp.Test
$(Version)
- 3.7.0
+ 3.7.1
Marco De Salvo
Marco De Salvo
net6.0
@@ -11,10 +11,10 @@
RDFSharp
-
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/RDFSharp/Model/RDFGraph.cs b/RDFSharp/Model/RDFGraph.cs
index ab065b49..817e6908 100644
--- a/RDFSharp/Model/RDFGraph.cs
+++ b/RDFSharp/Model/RDFGraph.cs
@@ -51,8 +51,8 @@ public IEnumerator TriplesEnumerator
foreach (RDFIndexedTriple indexedTriple in IndexedTriples.Values)
{
yield return indexedTriple.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO
- ? new RDFTriple(GraphIndex.ResourcesRegister[indexedTriple.SubjectID], GraphIndex.ResourcesRegister[indexedTriple.PredicateID], GraphIndex.ResourcesRegister[indexedTriple.ObjectID])
- : new RDFTriple(GraphIndex.ResourcesRegister[indexedTriple.SubjectID], GraphIndex.ResourcesRegister[indexedTriple.PredicateID], GraphIndex.LiteralsRegister[indexedTriple.ObjectID]);
+ ? new RDFTriple(GraphIndex.ResourcesRegister[indexedTriple.SubjectID], GraphIndex.ResourcesRegister[indexedTriple.PredicateID], GraphIndex.ResourcesRegister[indexedTriple.ObjectID]) { IsInference = indexedTriple.IsInference }
+ : new RDFTriple(GraphIndex.ResourcesRegister[indexedTriple.SubjectID], GraphIndex.ResourcesRegister[indexedTriple.PredicateID], GraphIndex.LiteralsRegister[indexedTriple.ObjectID]) { IsInference = indexedTriple.IsInference };
}
}
}
@@ -595,8 +595,10 @@ public RDFGraph DifferenceWith(RDFGraph graph)
///
public void ToFile(RDFModelEnums.RDFFormats rdfFormat, string filepath)
{
+ #region Guards
if (string.IsNullOrEmpty(filepath))
throw new RDFModelException("Cannot write RDF graph to file because given \"filepath\" parameter is null or empty.");
+ #endregion
switch (rdfFormat)
{
@@ -620,8 +622,10 @@ public void ToFile(RDFModelEnums.RDFFormats rdfFormat, string filepath)
///
public void ToStream(RDFModelEnums.RDFFormats rdfFormat, Stream outputStream)
{
+ #region Guards
if (outputStream == null)
throw new RDFModelException("Cannot write RDF graph to stream because given \"outputStream\" parameter is null.");
+ #endregion
switch (rdfFormat)
{
@@ -673,10 +677,12 @@ public DataTable ToDataTable()
///
public static RDFGraph FromFile(RDFModelEnums.RDFFormats rdfFormat, string filepath)
{
+ #region Guards
if (string.IsNullOrEmpty(filepath))
throw new RDFModelException("Cannot read RDF graph from file because given \"filepath\" parameter is null or empty.");
if (!File.Exists(filepath))
throw new RDFModelException("Cannot read RDF graph from file because given \"filepath\" parameter (" + filepath + ") does not indicate an existing file.");
+ #endregion
switch (rdfFormat)
{
@@ -699,8 +705,10 @@ public static RDFGraph FromFile(RDFModelEnums.RDFFormats rdfFormat, string filep
public static RDFGraph FromStream(RDFModelEnums.RDFFormats rdfFormat, Stream inputStream) => FromStream(rdfFormat, inputStream, null);
internal static RDFGraph FromStream(RDFModelEnums.RDFFormats rdfFormat, Stream inputStream, Uri graphContext)
{
+ #region Guards
if (inputStream == null)
throw new RDFModelException("Cannot read RDF graph from stream because given \"inputStream\" parameter is null.");
+ #endregion
switch (rdfFormat)
{
@@ -722,12 +730,14 @@ internal static RDFGraph FromStream(RDFModelEnums.RDFFormats rdfFormat, Stream i
///
public static RDFGraph FromDataTable(DataTable table)
{
+ #region Guards
if (table == null)
throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter is null.");
if (table.Columns.Count != 3)
throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter does not have exactly 3 columns.");
if (!(table.Columns.Contains("?SUBJECT") && table.Columns.Contains("?PREDICATE") && table.Columns.Contains("?OBJECT")))
throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter does not have the required columns \"?SUBJECT\", \"?PREDICATE\", \"?OBJECT\".");
+ #endregion
RDFGraph result = new RDFGraph();
@@ -780,10 +790,12 @@ public static RDFGraph FromDataTable(DataTable table)
///
public static RDFGraph FromUri(Uri uri, int timeoutMilliseconds = 20000)
{
+ #region Guards
if (uri == null)
throw new RDFModelException("Cannot read RDF graph from Uri because given \"uri\" parameter is null.");
if (!uri.IsAbsoluteUri)
throw new RDFModelException("Cannot read RDF graph from Uri because given \"uri\" parameter does not represent an absolute Uri.");
+ #endregion
RDFGraph result = new RDFGraph();
try
diff --git a/RDFSharp/Model/RDFTriple.cs b/RDFSharp/Model/RDFTriple.cs
index 99348f24..3556277a 100644
--- a/RDFSharp/Model/RDFTriple.cs
+++ b/RDFSharp/Model/RDFTriple.cs
@@ -37,6 +37,11 @@ public class RDFTriple : IEquatable
///
public RDFModelEnums.RDFTripleFlavors TripleFlavor { get; internal set; }
+ ///
+ /// Indicates that the triple has been emitted in consequence of any kind of reasoning
+ ///
+ public bool IsInference { get; internal set;}
+
///
/// Member acting as subject token of the triple
///
@@ -52,11 +57,6 @@ public class RDFTriple : IEquatable
///
public RDFPatternMember Object { get; internal set; }
- ///
- /// Indicates that the triple has been emitted in consequence of any kind of reasoning
- ///
- public bool IsInference { get; internal set;}
-
///
/// Subject of the triple's reification
///
@@ -78,10 +78,10 @@ public RDFTriple(RDFResource subj, RDFResource pred, RDFResource obj)
#endregion
TripleFlavor = RDFModelEnums.RDFTripleFlavors.SPO;
+ IsInference = false;
Subject = subj ?? new RDFResource();
Predicate = pred;
Object = obj ?? new RDFResource();
- IsInference = false;
LazyTripleID = new Lazy(() => RDFModelUtilities.CreateHash(ToString()));
LazyReificationSubject = new Lazy(() => new RDFResource(string.Concat("bnode:", TripleID.ToString())));
}
@@ -99,10 +99,10 @@ public RDFTriple(RDFResource subj, RDFResource pred, RDFLiteral lit)
#endregion
TripleFlavor = RDFModelEnums.RDFTripleFlavors.SPL;
+ IsInference = false;
Subject = subj ?? new RDFResource();
Predicate = pred;
Object = lit ?? new RDFPlainLiteral(string.Empty);
- IsInference = false;
LazyTripleID = new Lazy(() => RDFModelUtilities.CreateHash(ToString()));
LazyReificationSubject = new Lazy(() => new RDFResource(string.Concat("bnode:", TripleID.ToString())));
}
@@ -113,6 +113,7 @@ public RDFTriple(RDFResource subj, RDFResource pred, RDFLiteral lit)
internal RDFTriple(RDFIndexedTriple indexedTriple, RDFGraphIndex graphIndex)
{
TripleFlavor = indexedTriple.TripleFlavor;
+ IsInference = indexedTriple.IsInference;
Subject = graphIndex.ResourcesRegister[indexedTriple.SubjectID];
Predicate = graphIndex.ResourcesRegister[indexedTriple.PredicateID];
if (indexedTriple.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO)
@@ -204,6 +205,11 @@ internal class RDFIndexedTriple : IEquatable
/// Flavor of the triple
///
internal RDFModelEnums.RDFTripleFlavors TripleFlavor { get; set; }
+
+ ///
+ /// Indicates that the triple has been emitted in consequence of any kind of reasoning
+ ///
+ internal bool IsInference { get; set; }
#endregion
#region Ctor
@@ -213,10 +219,11 @@ internal class RDFIndexedTriple : IEquatable
internal RDFIndexedTriple(RDFTriple triple)
{
TripleFlavor = triple.TripleFlavor;
+ IsInference = triple.IsInference;
TripleID = triple.TripleID;
SubjectID = triple.Subject.PatternMemberID;
PredicateID = triple.Predicate.PatternMemberID;
- ObjectID = triple.Object.PatternMemberID;
+ ObjectID = triple.Object.PatternMemberID;
}
#endregion
diff --git a/RDFSharp/RDFSharp.csproj b/RDFSharp/RDFSharp.csproj
index bf7ea415..ecdb2b81 100644
--- a/RDFSharp/RDFSharp.csproj
+++ b/RDFSharp/RDFSharp.csproj
@@ -3,7 +3,7 @@
RDFSharp
RDFSharp
$(Version)
- 3.7.0
+ 3.7.1
Marco De Salvo
Marco De Salvo
Lightweight and friendly .NET library for realizing Semantic Web applications