SemWeb.Literal

SemWeb : SemWeb Namespace
Literal Class

A literal (text string) node in an RDF graph.

public sealed class Literal : Resource

#### Remarks

Literals are string values optionally tagged with a language or datatype URI.

An explicit conversion operator is defined from strings to literals as a convenience. The operator converts the string to a literal by returning a literal with that value, and `null` language and datatype.

The following examples create literal nodes.

C# Example
    Literal thing1 = new Literal("SemWeb: The C# Library");
    Literal thing2 = (Literal)"SemWeb: The C# Library"; // explicit operator overload
    Literal thing3 = new Literal("SemWeb: The C# Library", "en", null); // with language
    Literal thing3 = new Literal("SemWeb: The C# Library", null, "http://www.w3.org/2001/XMLSchema#string"); // with datatype

    Console.WriteLine(thing1.Value);
    Console.WriteLine(thing2.Language);
    Console.WriteLine(thing3.DataType);

## Members

See Also: Inherited members from Resource.

### Constructors

Literal (string) Creates a new Literal with the given string value.
Literal (string, string, string) Creates a new Literal with the given value, language, and datatype.

### Properties

DataType [read-only] | string . The datatype URI of the literal.
Language [read-only] | string . The language of the literal.
Uri [read-only] abstract | string . The URI of this resource. (Inherited from Resource.)
Value [read-only] | string . The value of the literal.

### Methods

| CompareTo (Resource) : int Compares two resources. (Inherited from Resource.)
static | FromValue (bool) : Literal Returns an XSD-typed boolean literal from the given value.
static | FromValue (byte) : Literal Returns an XSD-typed (unsigned) byte literal from the given value.
static | FromValue (DateTime) : Literal Returns an XSD-typed dateTime literal from the given value representing a date and UTC time.
static | FromValue (decimal) : Literal Returns an XSD-typed decimal literal from the given value.
static | FromValue (double) : Literal Returns an XSD-typed double-precision literal from the given value.
static | FromValue (short) : Literal Returns an XSD-typed short literal from the given value.
static | FromValue (int) : Literal Returns an XSD-typed int literal from the given value.
static | FromValue (long) : Literal Returns an XSD-typed long literal from the given value.
static | FromValue (sbyte) : Literal Returns an XSD-typed (signed) byte literal from the given value.
static | FromValue (float) : Literal Returns an XSD-typed floating-point literal from the given value.
static | FromValue (string) : Literal Returns an XSD-typed string literal from the given value.
static | FromValue (TimeSpan) : Literal Returns an XSD-typed duration literal from the given value.
static | FromValue (ushort) : Literal Returns an XSD-typed unsigned short literal from the given value.
static | FromValue (uint) : Literal Returns an XSD-typed unsigned int literal from the given value.
static | FromValue (ulong) : Literal Returns an XSD-typed boolean literal from the given value.
static | FromValue (Uri) : Literal Returns an XSD-typed URI (anyURI) literal from the given value.
static | FromValue (DateTime, bool, bool) : Literal Returns an XSD-typed date or dateTime literal from the given value.
static | FromValue (TimeSpan, bool, bool) : Literal Returns an XSD-typed duration or time literal from the given value.
| GetResourceKey (object) : object To be added. (Inherited from Resource.)
| Normalize () : Literal Creates a normalized form of the literal.
static | Parse (string, NamespaceManager) : Literal Parses a literal value.
| ParseValue () : object Gets a native .NET type for the literl value using a XSD DataType.
| SetResourceKey (object, object) To be added. (Inherited from Resource.)

### Operators

Conversion to SemWeb.Literal (Explicit) Converts a string to a Literal object whose language and datatype are `null`.

## Member Details

### Literal Constructor

public Literal (string value)

Creates a new Literal with the given string value.

#### Parameters

value
  The value of the Literal node.

#### Remarks

None.

### Literal Constructor

public Literal (string value, string language, string dataType)

Creates a new Literal with the given value, language, and datatype.

#### Parameters

value
  The value of the Literal node.
language
  A language identifier, or `null` to leave the language unspecified.
dataType
  The URI that gives the datatype of the literal, or `null` to leave the specific datatype unspecified.

#### Remarks

A language and datatype cannot both be specified, following to the RDF standard. An exception will be thrown if both are given.

### Value Property

public string Value { get; }

The value of the literal.

#### Value

The string value of the literal.

#### Remarks

None.

### Language Property

public string Language { get; }

The language of the literal.

#### Value

The language identifier of the literal, or `null`.

#### Remarks

None.

### DataType Property

public string DataType { get; }

The datatype URI of the literal.

#### Value

The datatype URI of the literal, or `null`.

#### Remarks

None.

### Parse Method

public static Literal Parse (string literal, NamespaceManager namespaces)

Parses a literal value.

#### Parameters

literal
  An N3-encoded form of a literal.
namespaces
  A namespace manager used to resolve the literal's datatype, if present, or `null`.

#### Returns

A Literal object.

#### Remarks

The encoded literal must be in the form of: "value"[@langcode | ^^datatypeURI].

If namespaces is `null` and a datatype was provided as a QName, or if the QName prefix was not found in the namespace manager, an ArgumentException is thrown.

### Conversion Method

public static explicit operator Literal (string value)

Converts a string to a Literal object whose language and datatype are `null`.

#### Parameters

value
  The string value to convert to a Literal object.

#### Returns

A literal object whose Value is the string, and whose language and datatype are null.

#### Remarks

This is an explicit cast operator.

### ParseValue Method

public object ParseValue ()

Gets a native .NET type for the literl value using a XSD DataType.

#### Returns

A string, boolean, integer, or other value, as described below.

#### Remarks

If the DataType of the literal is not set, or if the DataType is not one of the following recognized types, the literal's string value is returned.

The recognized types below are all in the `http://www.w3.org/2001/XMLSchema#` namespace. That is, where it says "string" below, it means the DataType is `http://www.w3.org/2001/XMLSchema#string`.

DataType(s) | Return Value
--- | ---
string, normalizedString, anyURI | The literal's value, as a string.
boolean | A bool, true if the literal's value is "true" or "1", false otherwise.
decimal, integer, positiveInteger, nonPositiveInteger, negativeInteger, nonNegativeInteger | The literal's value as a decimal using System.Decimal.Parse(string).
float or double | The literal's value as a float for float or double for double, using the appropriate Parse method.
duration | The literal's value as a TimeSpan using System.TimeSpan.Parse(string).
dateTime, time, date | The literal's value as a DateTime using System.DateTime.Parse(string).
long, int, short, byte | The literal's value as a long, int, short, or sbyte using the appropriate Parse method.
unsignedLong, unsignedInt, unsignedShort, unsignedByte | The literal's value as a ulong, uint, ushort, or byte using the appropriate Parse method.

### Normalize Method

public Literal Normalize ()

Creates a normalized form of the literal.

#### Returns

A normalized form of the literal.

#### Remarks

If this literal has a DataType recognized by the SemWeb.Literal.ParseValue() method, this method returns a new literal whose value is a normalized form of the value of this literal. Otherwise, Normalize returns the literal unchanged.

### FromValue Method

public static Literal FromValue (float value)

Returns an XSD-typed floating-point literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (double value)

Returns an XSD-typed double-precision literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (byte value)

Returns an XSD-typed (unsigned) byte literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (short value)

Returns an XSD-typed short literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (int value)

Returns an XSD-typed int literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (long value)

Returns an XSD-typed long literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (sbyte value)

Returns an XSD-typed (signed) byte literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (ushort value)

Returns an XSD-typed unsigned short literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (uint value)

Returns an XSD-typed unsigned int literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (ulong value)

Returns an XSD-typed boolean literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (bool value)

Returns an XSD-typed boolean literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (string value)

Returns an XSD-typed string literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (Uri value)

Returns an XSD-typed URI (anyURI) literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (DateTime value)

Returns an XSD-typed dateTime literal from the given value representing a date and UTC time.

#### Parameters

value
  A value whose time is in UTC.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (DateTime value, bool withTime, bool isLocalTime)

Returns an XSD-typed date or dateTime literal from the given value.

#### Parameters

value
  A date value, optionally with a time component.
withTime
  A boolean indicating whether value has a time component, or else only has a date component.
isLocalTime
  A boolean value indicating whether the time component of value is a local time, or else is a UTC time.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (TimeSpan value)

Returns an XSD-typed duration literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (TimeSpan value, bool asTime, bool isLocalTime)

Returns an XSD-typed duration or time literal from the given value.

#### Parameters

value
  A value.
asTime
  A boolean value indicating whether value should be interpreted as a time, or else as a duration.
isLocalTime
  If asTime is true, then isLocalTime is a boolean value indicating whether value is a local time, or else is a UTC time.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.

### FromValue Method

public static Literal FromValue (decimal value)

Returns an XSD-typed decimal literal from the given value.

#### Parameters

value
  A value.

#### Returns

A new Literal object with the indicated XSD datatype and a value in the lexical space of that datatype according to the parameters given.

#### Remarks

None.