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;
5
7{
11 public enum QueryTripleType
12 {
16 Constant = 0,
17
21 SubjectVariable = 1,
22
26 PredicateVariable = 2,
27
31 SubjectPredicateVariables = 3,
32
36 ObjectVariable = 4,
37
41 SubjectObjectVariable = 5,
42
46 PredicateObjectVariable = 6,
47
51 SubjectPredicateObjectVariable = 7
52 }
53
58 {
64 : this(Triple.Subject, Triple.Predicate, Triple.Object)
65 {
66 }
67
76 {
77 this.Subject = Subject;
78 this.Predicate = Predicate;
79 this.Object = Object;
80
81 int i = 0;
82
83 if (Subject is SemanticScriptElement ScriptElement &&
84 ScriptElement.Node is VariableReference VarRef)
85 {
86 this.SubjectIsVariable = true;
87 this.SubjectVariable = VarRef.VariableName;
88 i = 1;
89 }
90 else if (Subject is BlankNode Node) // §4.1.4: Blank nodes in graph patterns act as variables
91 {
92 this.SubjectIsVariable = true;
93 this.SubjectVariable = Node.ToString();
94 i = 1;
95 }
96 else
97 {
98 this.SubjectIsVariable = false;
99 this.SubjectVariable = null;
100 }
101
102 if (Predicate is SemanticScriptElement ScriptElement2 &&
103 ScriptElement2.Node is VariableReference VarRef2)
104 {
105 this.PredicateIsVariable = true;
106 this.PredicateVariable = VarRef2.VariableName;
107 i += 2;
108 }
109 else if (Predicate is BlankNode Node) // §4.1.4: Blank nodes in graph patterns act as variables
110 {
111 this.PredicateIsVariable = true;
112 this.PredicateVariable = Node.ToString();
113 i += 2;
114 }
115 else
116 {
117 this.PredicateIsVariable = false;
118 this.PredicateVariable = null;
119 }
120
121 if (Object is SemanticScriptElement ScriptElement3 &&
122 ScriptElement3.Node is VariableReference VarRef3)
123 {
124 this.ObjectIsVariable = true;
125 this.ObjectVariable = VarRef3.VariableName;
126 i += 4;
127 }
128 else if (Object is BlankNode Node) // §4.1.4: Blank nodes in graph patterns act as variables
129 {
130 this.ObjectIsVariable = true;
131 this.ObjectVariable = Node.ToString();
132 i += 4;
133 }
134 else
135 {
136 this.ObjectIsVariable = false;
137 this.ObjectVariable = null;
138 }
139
140 this.Type = (QueryTripleType)i;
141 }
142
146 public ISemanticElement Subject { get; }
147
152
156 public ISemanticElement Object { get; }
157
161 public bool SubjectIsVariable { get; }
162
166 public bool PredicateIsVariable { get; }
167
171 public bool ObjectIsVariable { get; }
172
176 public string SubjectVariable { get; }
177
181 public string PredicateVariable { get; }
182
186 public string ObjectVariable { get; }
187
191 public QueryTripleType Type { get; }
192
198 public ISemanticElement this[int Index]
199 {
200 get
201 {
202 switch (Index)
203 {
204 case 0: return this.Subject;
205 case 1: return this.Predicate;
206 case 2: return this.Object;
207 default: return null;
208 }
209 }
210 }
211
217 public string VariableName(int Index)
218 {
219 switch (Index)
220 {
221 case 0: return this.SubjectVariable;
222 case 1: return this.PredicateVariable;
223 case 2: return this.ObjectVariable;
224 default: return null;
225 }
226 }
227
229 public override string ToString()
230 {
231 StringBuilder sb = new StringBuilder();
232
233 if (this.SubjectIsVariable)
234 {
235 sb.Append('?');
236 sb.Append(this.SubjectVariable);
237 }
238 else
239 sb.Append(this.Subject.ToString());
240
241 sb.Append('\t');
242
243 if (this.PredicateIsVariable)
244 {
245 sb.Append('?');
246 sb.Append(this.PredicateVariable);
247 }
248 else
249 sb.Append(this.Predicate.ToString());
250
251 sb.Append('\t');
252
253 if (this.ObjectIsVariable)
254 {
255 sb.Append('?');
256 sb.Append(this.ObjectVariable);
257 }
258 else
259 sb.Append(this.Object.ToString());
260
261 return base.ToString();
262 }
263 }
264}
Represents a blank node
Definition: BlankNode.cs:7
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.