-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestApi.cs
More file actions
94 lines (76 loc) · 3.33 KB
/
Copy pathTestApi.cs
File metadata and controls
94 lines (76 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using DagSemTools.Api;
using IriTools;
using Xunit.Abstractions;
using FluentAssertions;
namespace NugetTest;
using DagSemTools.Api;
public class TestApi(ITestOutputHelper output)
{
TestOutputTextWriter outputWriter = new TestOutputTextWriter(output);
[Fact]
public void Test1()
{
var ontology = new FileInfo("TestData/example1.ttl");
var ont = TriGParser.Parse(ontology, outputWriter).GetDefaultGraph();
Assert.NotNull(ont);
var enemies = ont.GetTriplesWithPredicate(new IriReference("http://www.perceive.net/schemas/relationship/enemyOf"));
enemies.Count().Should().Be(2, "There are two trples with enemies");
}
[Fact]
public void TestSparql()
{
var ontology = new FileInfo("TestData/example1.ttl");
var ont = TriGParser.Parse(ontology, outputWriter);
Assert.NotNull(ont);
var enemies = ont.AnswerSelectQuery("SELECT * WHERE where{?hero <http://www.perceive.net/schemas/relationship/enemyOf> ?enemy.}").ToList();
Assert.NotNull(enemies);
foreach (var answerMap in enemies)
{
outputWriter.WriteLine();
foreach (var answer in answerMap.Values)
outputWriter.Write(answer);
}
enemies.Count().Should().Be(2, "There are two triples with enemies");
}
[Fact]
public void TestDbPedia()
{
var ontology = new FileInfo("DbpediaTests/test2.ttl");
var ont = TriGParser.Parse(ontology, outputWriter);
Assert.NotNull(ont);
var subjects = ont.GetDefaultGraph().GetTriplesWithPredicate(new IriReference("http://purl.org/dc/terms/subject"));
subjects.Count().Should().BeGreaterThan(200, "There are many triples with subjects");
}
[Fact]
public void TestDbPediaOntology()
{
var ontology = new FileInfo("DbpediaTests/test1.ttl");
var ont = TriGParser.Parse(ontology, outputWriter);
Assert.NotNull(ont);
var labels = ont.GetDefaultGraph().GetTriplesWithSubjectPredicate(
new IriReference("http://dbpedia.org/ontology/NaturalEvent"),
new IriReference("http://www.w3.org/2000/01/rdf-schema#label"));
labels.Count().Should().Be(7, "There are two labels on natural event");
}
[Fact]
public void TestDatalog()
{
var ontology = new FileInfo("TestData/data.ttl");
var ont = DagSemTools.Api.TriGParser.Parse(ontology, outputWriter);
var resultsData = ont.GetDefaultGraph().GetTriplesWithPredicateObject(
new IriReference("https://example.com/data#predicate"),
new IriReference("https://example.com/data#object"));
resultsData.Should().HaveCount(1);
var resultsBefore = ont.GetDefaultGraph().GetTriplesWithPredicateObject(
new IriReference("https://example.com/data#predicate"),
new IriReference("https://example.com/data#object2"));
resultsBefore.Should().BeEmpty();
Assert.NotNull(ont);
var datalogFile = new FileInfo("TestData/rules.datalog");
ont.LoadDatalog(datalogFile);
var resultsAfter = ont.GetDefaultGraph().GetTriplesWithPredicateObject(
new IriReference("https://example.com/data#predicate"),
new IriReference("https://example.com/data#object2"));
resultsAfter.Should().HaveCount(1);
}
}