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);

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.1, 1.0.6.2

Members

See Also: Inherited members from Resource.

Public Constructors

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

Public Properties

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

Public 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
Documentation for this section has not yet been entered. (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)
Documentation for this section has not yet been entered. (Inherited from Resource.)

Public Operators

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

Explicitly Implemented Interface Members

IComparable.CompareTo This implements the .NET 1.0 IComparable interface method to compare two Resources. The public method Resource.CompareTo(Resource) is also available, and in .NET 2.0 Resource additionally implements IComparable<SemWeb.Resource>. (Inherited from Resource.)

Member Details

Literal Constructor

Creates a new Literal with the given string value.

public Literal (string value)

Parameters

value
The value of the Literal node.

Remarks

None.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

Literal Constructor

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

public Literal (string value, string language, string 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

DataType Property

The datatype URI of the literal.

public string DataType { get; }

Value

The datatype URI of the literal, or null.

Remarks

None.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (bool 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (byte 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (DateTime value)

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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (decimal 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (double 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (short 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (int 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (long 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (sbyte 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (float 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (string 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (TimeSpan 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (ushort 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (uint 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (ulong 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

public static Literal FromValue (Uri 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

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

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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

FromValue Method

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

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

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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

Language Property

The language of the literal.

public string Language { get; }

Value

The language identifier of the literal, or null.

Remarks

None.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

Normalize Method

Creates a normalized form of the literal.

public Literal Normalize ()

Returns

A normalized form of the literal.

Remarks

If this literal has a DataType recognized by the 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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

Explicit Conversion Operator

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

public static explicit operator Literal (string value)

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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

Parse Method

Parses a literal value.

public static Literal Parse (string literal, NamespaceManager namespaces)

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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

ParseValue Method

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

public object ParseValue ()

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 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 TimeSpan.Parse(string).
dateTime, date, time The literal's value as a SemWeb.XsdDateTime.
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.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2

Value Property

The value of the literal.

public string Value { get; }

Value

The string value of the literal.

Remarks

None.

Requirements

Namespace: SemWeb
Assembly: SemWeb (in SemWeb.dll)
Assembly Versions: 1.0.6.2