Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SemanticLiteral.cs
1using System;
2using System.Text;
6
8{
13 {
14 private object value;
15 private Type valueType;
16 private IComparable comparable;
17
22 {
23 }
24
30 public SemanticLiteral(object Value, string StringValue)
31 {
32 this.value = Value;
33 this.valueType = null;
34 this.comparable = null;
35
36 this.StringValue = StringValue;
37 }
38
42 public override bool IsLiteral => true;
43
47 public object Value
48 {
49 get => this.value;
50 set
51 {
52 this.value = value;
53 this.valueType = null;
54 this.comparable = null;
55 }
56 }
57
61 public override object AssociatedObjectValue => this.value;
62
66 public abstract string StringType { get; }
67
71 public string StringValue { get; set; }
72
77
82
87
92
97
103 public virtual Grade Supports(string DataType)
104 {
105 return DataType == this.StringType ? Grade.Ok : Grade.NotAtAll;
106 }
107
113 public abstract Grade Supports(Type ValueType);
114
122 public abstract ISemanticLiteral Parse(string Value, string DataType, string Language);
123
129 public abstract ISemanticLiteral Encapsulate(object Value);
130
132 public override string ToString()
133 {
134 StringBuilder sb = new StringBuilder();
135
136 sb.Append('"');
137 sb.Append(JSON.Encode(this.StringValue));
138 sb.Append("\"^^<");
139 sb.Append(this.StringType);
140 sb.Append('>');
141
142 return sb.ToString();
143 }
144
156 public override int CompareTo(object obj)
157 {
158 if (obj is SemanticLiteral Typed)
159 {
160 if (this.valueType is null)
161 {
162 this.valueType = this.value?.GetType() ?? typeof(object);
163 this.comparable = this.value as IComparable;
164 }
165
166 if (Typed.valueType is null)
167 {
168 Typed.valueType = Typed.value?.GetType() ?? typeof(object);
169 Typed.comparable = Typed.value as IComparable;
170 }
171
172 if (this.valueType == Typed.valueType && !(this.comparable is null))
173 return this.comparable.CompareTo(Typed.value);
174 }
175
176 return base.CompareTo(obj);
177 }
178
185 {
186 return null;
187 }
188
195 {
196 return null;
197 }
198
203 public virtual IRingElement Invert()
204 {
205 return null;
206 }
207
214 {
215 if (this.AddRight(Element) is IAbelianGroupElement Result)
216 return Result;
217
218 if (Element.AddLeft(this) is IAbelianGroupElement Result2)
219 return Result2;
220
221 return null;
222 }
223
228 public virtual IGroupElement Negate()
229 {
230 return null;
231 }
232
239 {
240 return null;
241 }
242
249 {
250 return null;
251 }
252 }
253}
Helps with common JSON-related tasks.
Definition: JSON.cs:14
static string Encode(string s)
Encodes a string for inclusion in JSON.
Definition: JSON.cs:507
Abstract base class for semantic elements.
Abstract base class for semantic literal values.
virtual IRing AssociatedRing
Associated Ring.
override int CompareTo(object obj)
Compares the current instance with another object of the same type and returns an integer that indica...
virtual ISemiGroup AssociatedSemiGroup
Associated Semi-Group.
abstract ISemanticLiteral Encapsulate(object Value)
Encapsulates an object value as a semantic literal value.
override bool IsLiteral
If element is a literal.
virtual Grade Supports(string DataType)
How well the type supports a given data type.
virtual IAbelianGroupElement Zero
Returns the zero element of the group.
virtual IAbelianGroup AssociatedAbelianGroup
Associated Abelian Group.
abstract string StringType
Type name (or null if literal value is a string)
virtual IRingElement MultiplyLeft(IRingElement Element)
Tries to multiply an element to the current element, from the left.
SemanticLiteral()
Abstract base class for semantic literal values.
abstract ISemanticLiteral Parse(string Value, string DataType, string Language)
Tries to parse a string value of the type supported by the class..
virtual IRingElement Invert()
Inverts the element, if possible.
SemanticLiteral(object Value, string StringValue)
Abstract base class for semantic literal values.
virtual IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
virtual ISemiGroupElement AddLeft(ISemiGroupElement Element)
Tries to add an element to the current element, from the left.
override object AssociatedObjectValue
Associated object value.
virtual IRingElement MultiplyRight(IRingElement Element)
Tries to multiply an element to the current element, from the right.
string StringValue
String representation of value.
virtual IGroup AssociatedGroup
Associated Group.
virtual ISemiGroupElement AddRight(ISemiGroupElement Element)
Tries to add an element to the current element, from the right.
virtual IGroupElement Negate()
Negates the element.
abstract Grade Supports(Type ValueType)
How well the type supports a given value type.
static readonly SemanticLiterals Instance
Instance reference to the set of semantic literals.
override IAbelianGroupElement Zero
Returns the zero element of the group.
Base class for all types of elements.
Definition: Element.cs:13
Interface for semantic literals.
Basic interface for all types of abelian group elements.
Basic interface for all types of group elements.
Definition: IGroupElement.cs:9
Basic interface for all types of ring elements.
Definition: IRingElement.cs:10
Basic interface for all types of semigroup elements.
Basic interface for all types of abelian groups.
Basic interface for all types of groups.
Definition: IGroup.cs:10
Basic interface for all types of rings.
Definition: IRing.cs:10
Basic interface for all types of semigroups.
Definition: ISemiGroup.cs:10
Grade
Grade enumeration
Definition: Grade.cs:7