-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
106 lines (89 loc) · 3.17 KB
/
Program.cs
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
95
96
97
98
99
100
101
102
103
104
105
106
// ***********************************************************************
// <author>Stepan Burguchev</author>
// <copyright company="Comindware">
// Copyright (c) Comindware 2010-2015. All rights reserved.
// </copyright>
// <summary>
// Program.cs
// </summary>
// ***********************************************************************
using System;
using System.Linq;
using Comindware.Common;
using Comindware.Logics;
using Comindware.Logics.NTriples;
using Comindware.Logics.Think;
using Initializer = Comindware.Logics.Initializer;
namespace Comindware.Database.Examples.Rules
{
internal class Program
{
private static void Main()
{
// Initializing required database engine modules:
// - Basic operations
// - N3-Interpreter
// - Brain
Initializer.Initialize();
Logics.N3.Initializer.Initialize();
Logics.Think.Initializer.Initialize();
// Simple inference example
using (var model = ModelManager.CreateInMemoryModel(Names.DatabaseName).AutoDispose().Think(Names.Brain))
{
model.AddStatements(@"
@prefix : <http://www.example.com/logics/example#>.
:Paul :mother :Rita.
:Rita :mother :Caroline.
{
?x :mother ?y.
?y :mother ?z.
}
=>
{
?x :grandmother ?z
}.
".ParseString());
var grandmother = model.GetFact(Names.Paul, Names.Grandmother);
Console.WriteLine("Paul's grandmother is: {0}", Helpers.Beautify(grandmother));
}
// Recursion example
using (var model = ModelManager.CreateInMemoryModel(Names.DatabaseName).AutoDispose().Think(Names.Brain))
{
model.AddStatements(@"
@prefix : <http://www.example.com/logics/example#>.
:Paul a :Person;
:child :Rita;
:child :Caroline.
:Rita a :Person.
:Caroline a :Person;
:child :Dirk.
:Dirk a :Person.
:Greta a :Person;
:child :Jos.
:Jos a :Person.
# First rule: end of recursion
{
?x a :Person.
?x :child ?y.
}
=>
{
?x :descendants ?y.
}.
# Second rule: recursion body
{
?x a :Person.
?x :child ?z.
?z :descendants ?y.
}
=>
{
?x :descendants ?y.
}.
".ParseString());
var descendants = model.GetFacts(Names.Paul, Names.Example.CreateName("descendants")).ToArray();
Console.WriteLine("Paul's descendants: {0}", string.Join(", ", descendants.Select(Helpers.Beautify)));
}
}
}
}