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;
2using System.Collections.Generic;
3using System.Text;
7
9{
14 {
19 : this(null, null, null)
20 {
21 }
22
30 {
31 this.Subject = Subject;
32 this.Predicate = Predicate;
33 this.Object = Object;
34 }
35
39 public ISemanticElement Subject { get; set; }
40
44 public ISemanticElement Predicate { get; set; }
45
49 public ISemanticElement Object { get; set; }
50
54 public object Tag { get; set; }
55
59 public bool IsLiteral => this.Subject.IsLiteral && this.Predicate.IsLiteral && this.Object.IsLiteral;
60
65
69 public object AssociatedObjectValue => this;
70
74 public object ElementValue => this;
75
79 public bool IsScalar => false;
80
87 public IElement Encapsulate(ICollection<IElement> Elements, ScriptNode Node)
88 {
89 if (Elements.Count != 3)
90 return null;
91
95
96 foreach (IElement E in Elements)
97 {
100
101 if (Subject is null)
103 else if (Predicate is null)
105 else
107 }
108
110 }
111
118 public virtual bool TryConvertTo(Type DesiredType, out object Value)
119 {
120 Value = null;
121 return false;
122 }
123
127 public ICollection<IElement> ChildElements
128 {
129 get
130 {
131 return new IElement[]
132 {
133 this.Subject,
134 this.Predicate,
135 this.Object
136 };
137 }
138 }
139
141 public override string ToString()
142 {
143 StringBuilder sb = new StringBuilder();
144
145 sb.Append("<< ");
146 sb.Append(this.Subject);
147 sb.Append('\t');
148 sb.Append(this.Predicate);
149 sb.Append('\t');
150 sb.Append(this.Object);
151 sb.Append(" >>");
152
153 return sb.ToString();
154 }
155
157 public override bool Equals(object obj)
158 {
159 return obj is SemanticTriple Typed &&
160 Typed.Subject.Equals(this.Subject) &&
161 Typed.Predicate.Equals(this.Predicate) &&
162 Typed.Object.Equals(this.Object);
163 }
164
166 public override int GetHashCode()
167 {
168 int Result = this.Subject.GetHashCode();
169 Result ^= Result << 5 ^ this.Predicate.GetHashCode();
170 Result ^= Result << 5 ^ this.Object.GetHashCode();
171
172 return Result;
173 }
174
186 public int CompareTo(object obj)
187 {
188 if (!(obj is SemanticTriple T))
189 return this.ToString().CompareTo(obj?.ToString() ?? string.Empty);
190
191 int i = this.Subject.CompareTo(T.Subject);
192 if (i != 0)
193 return i;
194
195 i = this.Predicate.CompareTo(T.Predicate);
196 if (i != 0)
197 return i;
198
199 return this.Object.CompareTo(T.Object);
200 }
201
207 public ISemanticElement this[int Index]
208 {
209 get
210 {
211 switch (Index)
212 {
213 case 0: return this.Subject;
214 case 1: return this.Predicate;
215 case 2: return this.Object;
216 default: return null;
217 }
218 }
219 }
220 }
221}
Abstract base class for semantic elements.
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.
object Tag
Property used by processor, to tag information to an element.
ISemanticElement Predicate
Predicate element
bool IsScalar
If the element represents a scalar value.
object ElementValue
Underlying element value represented by the semantic element.
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.
ISemanticElement Subject
Subject element
object AssociatedObjectValue
Associated object value.
SemanticTriple(ISemanticElement Subject, ISemanticElement Predicate, ISemanticElement Object)
Implements a semantic triple.
ISemanticElement Object
Object element
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...
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
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:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for all types of sets.
Definition: ISet.cs:10