Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SemanticTriple.cs
1using System;
3using System.Numerics;
4using System.Text;
10
12{
17 {
22 {
23 this.Subject = null;
24 this.Predicate = null;
25 this.Object = null;
26 }
27
35 {
36 this.Subject = Subject;
37 this.Predicate = Predicate;
38 this.Object = Object;
39 }
40
48 {
49 this.Subject = Subject;
50 this.Predicate = new UriNode(Predicate);
51 this.Object = Object;
52 }
53
61 {
62 this.Subject = Subject;
63 this.Predicate = new UriNode(Predicate);
64 this.Object = new StringLiteral(Object);
65 }
66
74 {
75 this.Subject = Subject;
76 this.Predicate = new UriNode(Predicate);
77 this.Object = new DateTimeLiteral(Object);
78 }
79
87 {
88 this.Subject = Subject;
89 this.Predicate = new UriNode(Predicate);
90 this.Object = new BooleanLiteral(Object);
91 }
92
100 {
101 this.Subject = Subject;
102 this.Predicate = new UriNode(Predicate);
103 this.Object = new Base64Literal(Object);
104 }
105
113 {
114 this.Subject = Subject;
115 this.Predicate = new UriNode(Predicate);
116 this.Object = new DecimalLiteral(Object);
117 }
118
126 {
127 this.Subject = Subject;
128 this.Predicate = new UriNode(Predicate);
129 this.Object = new DoubleLiteral(Object);
130 }
131
139 {
140 this.Subject = Subject;
141 this.Predicate = new UriNode(Predicate);
142 this.Object = new SingleLiteral(Object);
143 }
144
152 {
153 this.Subject = Subject;
154 this.Predicate = new UriNode(Predicate);
155 this.Object = new DurationLiteral(Object);
156 }
157
165 {
166 this.Subject = Subject;
167 this.Predicate = new UriNode(Predicate);
168 this.Object = new Int8Literal(Object);
169 }
170
178 {
179 this.Subject = Subject;
180 this.Predicate = new UriNode(Predicate);
181 this.Object = new Int16Literal(Object);
182 }
183
191 {
192 this.Subject = Subject;
193 this.Predicate = new UriNode(Predicate);
194 this.Object = new Int32Literal(Object);
195 }
196
204 {
205 this.Subject = Subject;
206 this.Predicate = new UriNode(Predicate);
207 this.Object = new Int64Literal(Object);
208 }
209
217 {
218 this.Subject = Subject;
219 this.Predicate = new UriNode(Predicate);
220 this.Object = new UInt8Literal(Object);
221 }
222
230 {
231 this.Subject = Subject;
232 this.Predicate = new UriNode(Predicate);
233 this.Object = new UInt16Literal(Object);
234 }
235
243 {
244 this.Subject = Subject;
245 this.Predicate = new UriNode(Predicate);
246 this.Object = new UInt32Literal(Object);
247 }
248
256 {
257 this.Subject = Subject;
258 this.Predicate = new UriNode(Predicate);
259 this.Object = new UInt64Literal(Object);
260 }
261
269 {
270 this.Subject = Subject;
271 this.Predicate = new UriNode(Predicate);
272 this.Object = new IntegerLiteral(Object);
273 }
274
282 {
283 this.Subject = Subject;
284 this.Predicate = new UriNode(Predicate);
285 this.Object = new TimeLiteral(Object);
286 }
287
295 {
296 this.Subject = Subject;
297 this.Predicate = new UriNode(Predicate);
298 this.Object = new UriNode(Object);
299 }
300
308 {
309 this.Subject = Subject;
310 this.Predicate = new UriNode(Predicate);
312 }
313
317 public ISemanticElement Subject { get; set; }
318
322 public ISemanticElement Predicate { get; set; }
323
327 public ISemanticElement Object { get; set; }
328
332 public object Tag { get; set; }
333
337 public bool IsLiteral => this.Subject.IsLiteral && this.Predicate.IsLiteral && this.Object.IsLiteral;
338
343
347 public object AssociatedObjectValue => this;
348
352 public object ElementValue => this;
353
357 public bool IsScalar => false;
358
366 {
367 return this.Encapsulate((ICollection<IElement>)Elements, Node);
368 }
369
376 public IElement Encapsulate(ICollection<IElement> Elements, ScriptNode Node)
377 {
378 if (Elements.Count != 3)
379 return null;
380
384
385 foreach (IElement E in Elements)
386 {
389
390 if (Subject is null)
392 else if (Predicate is null)
394 else
396 }
397
399 }
400
407 public virtual bool TryConvertTo(Type DesiredType, out object Value)
408 {
409 Value = null;
410 return false;
411 }
412
416 public ICollection<IElement> ChildElements
417 {
418 get
419 {
420 return new IElement[]
421 {
422 this.Subject,
423 this.Predicate,
424 this.Object
425 };
426 }
427 }
428
430 public override string ToString()
431 {
432 StringBuilder sb = new StringBuilder();
433
434 sb.Append("<< ");
435 sb.Append(this.Subject);
436 sb.Append('\t');
437 sb.Append(this.Predicate);
438 sb.Append('\t');
439 sb.Append(this.Object);
440 sb.Append(" >>");
441
442 return sb.ToString();
443 }
444
446 public override bool Equals(object obj)
447 {
448 return obj is SemanticTriple Typed &&
449 Typed.Subject.Equals(this.Subject) &&
450 Typed.Predicate.Equals(this.Predicate) &&
451 Typed.Object.Equals(this.Object);
452 }
453
455 public override int GetHashCode()
456 {
457 int Result = this.Subject.GetHashCode();
458 Result ^= Result << 5 ^ this.Predicate.GetHashCode();
459 Result ^= Result << 5 ^ this.Object.GetHashCode();
460
461 return Result;
462 }
463
475 public int CompareTo(object obj)
476 {
477 if (!(obj is SemanticTriple T))
478 return this.ToString().CompareTo(obj?.ToString() ?? string.Empty);
479
480 int i = this.Subject.CompareTo(T.Subject);
481 if (i != 0)
482 return i;
483
484 i = this.Predicate.CompareTo(T.Predicate);
485 if (i != 0)
486 return i;
487
488 return this.Object.CompareTo(T.Object);
489 }
490
496 public ISemanticElement this[int Index]
497 {
498 get
499 {
500 switch (Index)
501 {
502 case 0: return this.Subject;
503 case 1: return this.Predicate;
504 case 2: return this.Object;
505 default: return null;
506 }
507 }
508 }
509 }
510}
Represents a 16-bit integer literal.
Definition: Int16Literal.cs:11
Represents a 32-bit integer literal.
Definition: Int32Literal.cs:11
Represents a 64-bit integer literal.
Definition: Int64Literal.cs:11
Represents a 8-bit integer literal.
Definition: Int8Literal.cs:11
Represents an integer literal of undefined size.
Represents a 16-bit unsigned integer literal.
Represents a 32-bit unsigned integer literal.
Represents a 64-bit unsigned integer literal.
Represents a 8-bit unsigned integer literal.
Definition: UInt8Literal.cs:11
Abstract base class for semantic elements.
static ISemanticLiteral EncapsulateLiteral(object Value)
Encapsulates an object as a semantic literal.
static readonly SemanticElements Instance
Instance reference to the set of semantic elements.
static ISemanticElement Encapsulate(object Value)
Encapsulates an object as a semantic element.
SemanticTriple()
Implements a semantic triple.
IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
object Tag
Property used by processor, to tag information to an element.
SemanticTriple(ISemanticElement Subject, Uri Predicate, long Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, int Object)
Implements a semantic triple.
ISemanticElement Predicate
Predicate element
bool IsScalar
If the element represents a scalar value.
SemanticTriple(ISemanticElement Subject, Uri Predicate, DateTime Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, ushort Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, decimal Object)
Implements a semantic triple.
object ElementValue
Underlying element value represented by the semantic element.
SemanticTriple(ISemanticElement Subject, Uri Predicate, double Object)
Implements a semantic triple.
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
virtual bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
SemanticTriple(ISemanticElement Subject, Uri Predicate, string Object)
Implements a semantic triple.
ISemanticElement Subject
Subject element
SemanticTriple(ISemanticElement Subject, Uri Predicate, uint Object)
Implements a semantic triple.
object AssociatedObjectValue
Associated object value.
SemanticTriple(ISemanticElement Subject, ISemanticElement Predicate, ISemanticElement Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, Uri Object)
Implements a semantic triple.
ISemanticElement Object
Object element
SemanticTriple(ISemanticElement Subject, Uri Predicate, short Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, ISemanticElement Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, byte Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, object Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, Duration Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, bool Object)
Implements a semantic triple.
bool IsLiteral
If element is a literal.
int CompareTo(object obj)
Compares the current instance with another object of the same type and returns an integer that indica...
SemanticTriple(ISemanticElement Subject, Uri Predicate, sbyte Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, ulong Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, byte[] Object)
Implements a semantic triple.
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
SemanticTriple(ISemanticElement Subject, Uri Predicate, float Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, BigInteger Object)
Implements a semantic triple.
SemanticTriple(ISemanticElement Subject, Uri Predicate, TimeSpan Object)
Implements a semantic triple.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Interface for semantic nodes.
bool IsLiteral
If element is a literal.
Interface for semantic triples.
Basic interface for all types of elements.
Definition: IElement.cs:21
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:34
Basic interface for all types of sets.
Definition: ISet.cs:10
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:14