Skip to content

Commit

Permalink
Only inferencing is not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
meberl committed Aug 11, 2022
1 parent 9a54c5d commit 1f2502d
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 142 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Documentation/log.txt
*.zip
*.user
**/.vs/**
**/.idea/**
15 changes: 1 addition & 14 deletions Trinity.Fuseki/FusekiStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,6 @@ public override void UpdateResource(Resource resource, Uri modelUri, ITransactio

if (resource.IsNew)
{
if (resource.Uri.IsBlankId)
{
string queryString = string.Format(@"SELECT BNODE() AS ?x FROM <{0}> WHERE {{}}", modelUri.OriginalString);

var result = ExecuteQuery(new SparqlQuery(queryString), transaction);
var id = result.GetBindings().First()["x"] as UriRef;

resource.Uri = id;
}

updateString = string.Format(@"
INSERT DATA {{ GRAPH <{0}> {{ {1} }} }} ",
modelUri.OriginalString,
Expand Down Expand Up @@ -218,12 +208,9 @@ public override ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public object ExecuteQuery(string query)
public override object ExecuteQuery(string query)
{
Log?.Invoke(query);

//SparqlQueryParser parser = new SparqlQueryParser();

return Connector.Query(query);
}

Expand Down
4 changes: 2 additions & 2 deletions Trinity/Query/SparqlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ public static string SerializeCount(IModel model, ISparqlQuery query)

StringBuilder queryBuilder = new StringBuilder();

queryBuilder.Append("SELECT COUNT(DISTINCT ");
queryBuilder.Append("SELECT ( COUNT(DISTINCT ");
queryBuilder.Append(variable);
queryBuilder.Append(") AS ?count ");
queryBuilder.Append(") AS ?count )");
queryBuilder.Append(from);
queryBuilder.Append(" WHERE { ");
queryBuilder.Append(where);
Expand Down
10 changes: 10 additions & 0 deletions Trinity/Stores/StoreBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public virtual bool ContainsModel(IModel model)
/// <returns></returns>
public abstract ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction transaction = null);

/// <summary>
/// Executes a string query directly on the store.
/// </summary>
/// <param name="query">SPARQL query to be executed.</param>
/// <returns>A native return value is possible here.</returns>
public virtual object ExecuteQuery(string query)
{
return null;
}

/// <summary>
/// Executes a query on the store which does not expect a result.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions Trinity/Stores/dotNetRDF/dotNetRDFQueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ public virtual int Count()

SparqlQuery query = new SparqlQuery(countQuery);


object result = _store.ExecuteQuery(query);
object result = _store.ExecuteQuery(query.ToString());

if (result is SparqlResultSet)
{
Expand Down
2 changes: 1 addition & 1 deletion Trinity/Stores/dotNetRDF/dotNetRDFStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public override ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public object ExecuteQuery(string query)
public override object ExecuteQuery(string query)
{
Log?.Invoke(query);

Expand Down
48 changes: 42 additions & 6 deletions tests/Trinity.Tests.Fuseki/ModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ public Contact(Uri uri) : base(uri) { }
[Test]
public void ModelNameTest()
{
Uri modelUri = new Uri("http://www.example.com");
Uri modelUri2 = new Uri("http://www.example.com/");
Uri modelUri = new Uri("http://doesNotExist.example.com");
Uri modelUri2 = new Uri("http://doesNotExist.example.com/");

IModel m1 = Store.GetModel(modelUri);
m1.Clear();

Assert.IsTrue(m1.IsEmpty);

IModel m2 = Store.GetModel(modelUri2);
Expand All @@ -154,7 +153,7 @@ public void ModelNameTest()
c.Commit();

Assert.IsFalse(m1.IsEmpty);
Assert.IsFalse(m2.IsEmpty);
Assert.IsTrue(m2.IsEmpty);

m1.Clear();

Expand Down Expand Up @@ -325,6 +324,43 @@ public void GetResourceWithBlankIdPropertyTest()
}
}


[Test]
public void GetResourceWithDuplicateBlankIdPropertyTest()
{
Model.Clear();

var label = new Property(new UriRef("ex:label"));
var related = new Property(new UriRef("ex:related"));

var r0 = Model.CreateResource(new UriRef("_:0", true));
r0.AddProperty(label, "0");
r0.Commit();

var r1 = Model.CreateResource(new UriRef("_:0", true));
r0.AddProperty(label, "1");
r1.AddProperty(related, r0);
r1.Commit();

Assert.Throws<ArgumentException>(() => Model.ContainsResource(r1.Uri));
Assert.Throws<ArgumentException>(() => Model.GetResource(r1.Uri));
Assert.Throws<ArgumentException>(() => Model.GetResource(r1));

var resources = Model.GetResources<Resource>().ToArray();

Assert.AreEqual(2, resources.Length);

foreach (var r in resources)
{
Assert.IsTrue(r.Uri.IsBlankId);

foreach (var x in r.ListValues(related).OfType<Resource>())
{
Assert.IsTrue(x.Uri.IsBlankId);
}
}
}

[Test]
public void GetResourceTest()
{
Expand Down Expand Up @@ -470,9 +506,9 @@ public void LiteralWithLangTagTest()
IResource r = Model.GetResource(new Uri("ex:Resource"));
object o = r.GetValue(property);

Assert.AreEqual(typeof(Tuple<string, CultureInfo>), o.GetType());
Assert.AreEqual(typeof(Tuple<string, string>), o.GetType());

var val = o as Tuple<string, CultureInfo>;
var val = o as Tuple<string, string>;

Assert.AreEqual("in the jungle", val.Item1);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Trinity.Tests.Fuseki/SetupClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SetupClass
#region Methods

[OneTimeSetUp]
public void Setup()
public void OneTimeSetup()
{
Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);

Expand All @@ -42,7 +42,7 @@ public void Setup()
}

[OneTimeTearDown]
public void TearDown()
public void OneTimeTearDown()
{

}
Expand Down
114 changes: 0 additions & 114 deletions tests/Trinity.Tests.Fuseki/SparqlQueryItemsProviderTest.cs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Trinity.Tests.Fuseki/SparqlQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public void TestQueryParameters()
[Test]
public void TestSelectCount()
{
SparqlQuery query = new SparqlQuery("SELECT COUNT(?s) AS ?count WHERE { ?s rdf:type nco:PhoneNumber. }");
SparqlQuery query = new SparqlQuery("SELECT ( COUNT(?s) AS ?count ) WHERE { ?s rdf:type nco:PhoneNumber. }");
ISparqlQueryResult result = Model.ExecuteQuery(query);

var bindings = result.GetBindings();
Expand Down

0 comments on commit 1f2502d

Please sign in to comment.