Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SemanticQueryTriple.cs
1using System.Text;
4
6{
10 public enum QueryTripleType
11 {
15 Constant = 0,
16
20 SubjectVariable = 1,
21
25 PredicateVariable = 2,
26
30 SubjectPredicateVariables = 3,
31
35 ObjectVariable = 4,
36
40 SubjectObjectVariable = 5,
41
45 PredicateObjectVariable = 6,
46
50 SubjectPredicateObjectVariable = 7
51 }
52
57 {
63 : this(Triple.Subject, Triple.Predicate, Triple.Object)
64 {
65 }
66
75 {
76 this.Subject = Subject;
77 this.Predicate = Predicate;
78 this.Object = Object;
79
80 int i = 0;
81
82 if (Subject is SemanticScriptElement ScriptElement &&
83 ScriptElement.Node is VariableReference VarRef)
84 {
85 this.SubjectIsVariable = true;
86 this.SubjectVariable = VarRef.VariableName;
87 i = 1;
88 }
89 else
90 {
91 this.SubjectIsVariable = false;
92 this.SubjectVariable = null;
93 }
94
95 if (Predicate is SemanticScriptElement ScriptElement2 &&
96 ScriptElement2.Node is VariableReference VarRef2)
97 {
98 this.PredicateIsVariable = true;
99 this.PredicateVariable = VarRef2.VariableName;
100 i += 2;
101 }
102 else
103 {
104 this.PredicateIsVariable = false;
105 this.PredicateVariable = null;
106 }
107
108 if (Object is SemanticScriptElement ScriptElement3 &&
109 ScriptElement3.Node is VariableReference VarRef3)
110 {
111 this.ObjectIsVariable = true;
112 this.ObjectVariable = VarRef3.VariableName;
113 i += 4;
114 }
115 else
116 {
117 this.ObjectIsVariable = false;
118 this.ObjectVariable = null;
119 }
120
121 this.Type = (QueryTripleType)i;
122 }
123
127 public ISemanticElement Subject { get; }
128
133
137 public ISemanticElement Object { get; }
138
142 public bool SubjectIsVariable { get; }
143
147 public bool PredicateIsVariable { get; }
148
152 public bool ObjectIsVariable { get; }
153
157 public string SubjectVariable { get; }
158
162 public string PredicateVariable { get; }
163
167 public string ObjectVariable { get; }
168
172 public QueryTripleType Type { get; }
173
179 public ISemanticElement this[int Index]
180 {
181 get
182 {
183 switch (Index)
184 {
185 case 0: return this.Subject;
186 case 1: return this.Predicate;
187 case 2: return this.Object;
188 default: return null;
189 }
190 }
191 }
192
198 public string VariableName(int Index)
199 {
200 switch (Index)
201 {
202 case 0: return this.SubjectVariable;
203 case 1: return this.PredicateVariable;
204 case 2: return this.ObjectVariable;
205 default: return null;
206 }
207 }
208
210 public override string ToString()
211 {
212 StringBuilder sb = new StringBuilder();
213
214 if (this.SubjectIsVariable)
215 {
216 sb.Append('?');
217 sb.Append(this.SubjectVariable);
218 }
219 else
220 sb.Append(this.Subject.ToString());
221
222 sb.Append('\t');
223
224 if (this.PredicateIsVariable)
225 {
226 sb.Append('?');
227 sb.Append(this.PredicateVariable);
228 }
229 else
230 sb.Append(this.Predicate.ToString());
231
232 sb.Append('\t');
233
234 if (this.ObjectIsVariable)
235 {
236 sb.Append('?');
237 sb.Append(this.ObjectVariable);
238 }
239 else
240 sb.Append(this.Object.ToString());
241
242 return base.ToString();
243 }
244 }
245}
Represents a variable reference.
string VariableName(int Index)
Gets a variable name, given the axis index: 0=Subject, 1=Predicate, 2=Object.
string PredicateVariable
Predicate element variable name, if any
bool ObjectIsVariable
If the Object element is a variable reference.
string ObjectVariable
Object element variable name, if any
bool PredicateIsVariable
If the Predicate element is a variable reference.
bool SubjectIsVariable
If the Subject element is a variable reference.
SemanticQueryTriple(ISemanticElement Subject, ISemanticElement Predicate, ISemanticElement Object)
Semantic query triple
SemanticQueryTriple(ISemanticTriple Triple)
Semantic query triple
string SubjectVariable
Subject element variable name, if any
Interface for semantic nodes.
Interface for semantic triples.