Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ToSingleLiteral.cs
1
using
System.Numerics;
2
using
Waher.Content
;
3
using
Waher.Content.Semantic.Model.Literals
;
4
using
Waher.Script.Abstraction.Elements
;
5
using
Waher.Script.Model
;
6
7
namespace
Waher.Script.Persistence.SPARQL.Functions.TypeConversion
8
{
12
public
class
ToSingleLiteral
:
SemanticConversionFunction
13
{
17
public
ToSingleLiteral
()
18
: base()
19
{
20
}
21
29
public
ToSingleLiteral
(
ScriptNode
Argument
,
int
Start
,
int
Length
,
Expression
Expression
)
30
: base(
Argument
,
Start
,
Length
,
Expression
)
31
{
32
}
33
42
public
override
ScriptNode
CreateFunction
(
ScriptNode
Argument
,
int
Start
,
int
Length
,
Expression
Expression
)
43
{
44
return
new
ToSingleLiteral
(
Argument
,
Start
,
Length
,
Expression
);
45
}
46
50
public
override
string
FunctionName
=>
SingleLiteral
.
TypeUri
;
51
57
public
override
IElement
Convert
(
object
Value)
58
{
59
if
(Value is
float
d)
60
return
new
SingleLiteral
(d);
61
else
if
(Value is
bool
b)
62
return
new
SingleLiteral
(b ? 1 : 0);
63
else
if
(Value is
string
s)
64
{
65
if
(
CommonTypes
.
TryParse
(s, out d))
66
return
new
SingleLiteral
(d);
67
}
68
else
if
(Value is BigInteger i)
69
return
new
SingleLiteral
((
float
)i);
70
else
if
(Value is Complex z)
71
{
72
if
(z.Imaginary == 0)
73
return
new
SingleLiteral
((
float
)z.Real);
74
}
75
76
d = System.Convert.ToSingle(Value);
77
return
new
SingleLiteral
(d);
78
}
79
}
80
}
Waher.Content.CommonTypes
Helps with parsing of commong data types.
Definition:
CommonTypes.cs:13
Waher.Content.CommonTypes.TryParse
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition:
CommonTypes.cs:46
Waher.Content.Semantic.Model.Literals.SingleLiteral
Represents a float literal.
Definition:
SingleLiteral.cs:11
Waher.Content.Semantic.Model.Literals.SingleLiteral.TypeUri
const string TypeUri
http://www.w3.org/2001/XMLSchema#float
Definition:
SingleLiteral.cs:42
Waher.Script.Expression
Class managing a script expression.
Definition:
Expression.cs:39
Waher.Script.Model.FunctionOneVariable.Argument
ScriptNode Argument
Function argument.
Definition:
FunctionOneVariable.cs:33
Waher.Script.Model.ScriptNode
Base class for all nodes in a parsed script tree.
Definition:
ScriptNode.cs:69
Waher.Script.Model.ScriptNode.Length
int Length
Length of expression covered by node.
Definition:
ScriptNode.cs:101
Waher.Script.Model.ScriptNode.Start
int Start
Start position in script expression.
Definition:
ScriptNode.cs:92
Waher.Script.Persistence.SPARQL.Functions.TypeConversion.SemanticConversionFunction
Abstract base class for semantic conversion functions.
Definition:
SemanticConversionFunction.cs:12
Waher.Script.Persistence.SPARQL.Functions.TypeConversion.ToSingleLiteral
Converts a value to a single literal.
Definition:
ToSingleLiteral.cs:13
Waher.Script.Persistence.SPARQL.Functions.TypeConversion.ToSingleLiteral.ToSingleLiteral
ToSingleLiteral()
Converts a value to a single literal.
Definition:
ToSingleLiteral.cs:17
Waher.Script.Persistence.SPARQL.Functions.TypeConversion.ToSingleLiteral.FunctionName
override string FunctionName
Name of the function
Definition:
ToSingleLiteral.cs:50
Waher.Script.Persistence.SPARQL.Functions.TypeConversion.ToSingleLiteral.CreateFunction
override ScriptNode CreateFunction(ScriptNode Argument, int Start, int Length, Expression Expression)
Creates a function node.
Definition:
ToSingleLiteral.cs:42
Waher.Script.Persistence.SPARQL.Functions.TypeConversion.ToSingleLiteral.ToSingleLiteral
ToSingleLiteral(ScriptNode Argument, int Start, int Length, Expression Expression)
Converts a value to a single literal.
Definition:
ToSingleLiteral.cs:29
Waher.Script.Persistence.SPARQL.Functions.TypeConversion.ToSingleLiteral.Convert
override IElement Convert(object Value)
Converts an object to the desired type.
Definition:
ToSingleLiteral.cs:57
Waher.Script.Abstraction.Elements.IElement
Basic interface for all types of elements.
Definition:
IElement.cs:20
Waher.Content.Semantic.Model.Literals
Definition:
Base64Literal.cs:6
Waher.Content
Definition:
Array.cs:6
Waher.Script.Abstraction.Elements
Definition:
AbelianGroupElement.cs:5
Waher.Script.Model
Definition:
BinaryBooleanOperator.cs:8
Waher.Script.Persistence.SPARQL.Functions.TypeConversion
Definition:
SemanticConversionFunction.cs:7
IoTGateway
Script
Waher.Script.Persistence
SPARQL
Functions
TypeConversion
ToSingleLiteral.cs
Generated by
1.9.5