Soprano.LiteralValue

KDE 4.9 PyKDE API Reference

- KDE's Python API

# LiteralValue Class Reference

`from PyKDE4.soprano import *`

Namespace: Soprano

## Detailed Description

\class LiteralValue literalvalue.h Soprano/LiteralValue

Represents a literal value of an RDF Node.

LiteralValue is based on QVariant to support a subset of the XML Schema types that are compatible with QT types.

The following types are supported natively including automatic type conversion. Other types are represented as strings.

- int (Vocabulary.XMLSchema.xsdInt)
- qlonglong (Vocabulary.XMLSchema.xsdLong)
- unsigned int (Vocabulary.XMLSchema.unsignedInt)
- qulonglong (Vocabulary.XMLSchema.unsignedLong)
- bool (Vocabulary.XMLSchema.boolean)
- double and float (Vocabulary.XMLSchema.xsdDouble) (float values are always converted to double)
- QString (Vocabulary.XMLSchema.string or Vocabulary.RDF.XMLLiteral)
- QDate (Vocabulary.XMLSchema.date)
- QTime (Vocabulary.XMLSchema.time)
- QDateTime (Vocabulary.XMLSchema.dateTime)
- QByteArray (Vocabulary.XMLSchema.base64Binary)

Literal values can be converted from strings via fromString().

\sa Vocabulary.XMLSchema

Author:
  Sebastian Trueg <trueg@kde.org>

## Methods
| __init__ (self)
| __init__ (self, Soprano.LiteralValue other)
| __init__ (self, QVariant v)
| __init__ (self, long i)
| __init__ (self, float d)
| __init__ (self, QString string)
| __init__ (self, QLatin1String string)
| __init__ (self, QString string)
| __init__ (self, QDate date)
| __init__ (self, QTime time)
| __init__ (self, QDateTime datetime)
| __init__ (self, QByteArray data)
QUrl | dataTypeUri (self)
bool | isBool (self)
bool | isByteArray (self)
bool | isDate (self)
bool | isDateTime (self)
bool | isDouble (self)
bool | isInt (self)
bool | isInt64 (self)
bool | isPlain (self)
bool | isString (self)
bool | isTime (self)
bool | isUnsignedInt (self)
bool | isUnsignedInt64 (self)
bool | isValid (self)
Soprano.LanguageTag | language (self)
bool | operator != (self, Soprano.LiteralValue other)
bool | operator == (self, Soprano.LiteralValue other)
bool | toBool (self)
QByteArray | toByteArray (self)
QDate | toDate (self)
QDateTime | toDateTime (self)
float | toDouble (self)
int | toInt (self)
long | toInt64 (self)
QString | toString (self)
QTime | toTime (self)
long | toUnsignedInt (self)
long | toUnsignedInt64 (self)
QVariant::Type | type (self)
QVariant | variant (self)
## Static Methods
Soprano.LiteralValue | createPlainLiteral (QString value, Soprano.LanguageTag lang=Soprano.LanguageTag())
QUrl | dataTypeUriFromType (QVariant::Type type)
Soprano.LiteralValue | fromString (QString value, QVariant::Type type)
Soprano.LiteralValue | fromString (QString value, QUrl dataTypeUri)
Soprano.LiteralValue | fromVariant (QVariant value, QUrl dataType)
QVariant::Type | typeFromDataTypeUri (QUrl dataTypeUri)

## Method Documentation

__init__ | ( |  | self ) |

Create an empty literal value

__init__ | ( | self, |
|  | Soprano.LiteralValue | other
| ) |  |  |

Default copy constructor

__init__ | ( | self, |
|  | QVariant | v
| ) |  |  |

Creates a new LiteralValue from a QVariant. User types are not supported. If v contains an unsupported type an invalid LiteralValue is created.

\sa fromVariant()

__init__ | ( | self, |
|  | long | i
| ) |  |  |

Creates a literal value of type unsigned long long (i.e. http://www.w3.org/2001/XMLSchema#unsignedLong)

__init__ | ( | self, |
|  | float | d
| ) |  |  |

Creates a literal value of type double (i.e. http://www.w3.org/2001/XMLSchema#double)

__init__ | ( | self, |
|  | QString | string
| ) |  |  |

Creates a literal value of type QString (i.e. http://www.w3.org/2001/XMLSchema#string)

__init__ | ( | self, |
|  | QLatin1String | string
| ) |  |  |

Creates a literal value of type QString (i.e. http://www.w3.org/2001/XMLSchema#string)

__init__ | ( | self, |
|  | QString | string
| ) |  |  |

Creates a literal value of type QString (i.e. http://www.w3.org/2001/XMLSchema#string)

__init__ | ( | self, |
|  | QDate | date
| ) |  |  |

Creates a literal value of type QDate (i.e. http://www.w3.org/2001/XMLSchema#date)

__init__ | ( | self, |
|  | QTime | time
| ) |  |  |

Creates a literal value of type QTime (i.e. http://www.w3.org/2001/XMLSchema#time)

__init__ | ( | self, |
|  | QDateTime | datetime
| ) |  |  |

Creates a literal value of type QDateTime (i.e. http://www.w3.org/2001/XMLSchema#dateTime)

__init__ | ( | self, |
|  | QByteArray | data
| ) |  |  |

Creates a literal value of type QByteArray (i.e. http://www.w3.org/2001/XMLSchema#base64Binary)

QUrl dataTypeUri | ( |  | self ) |

The XML Schema datatype URI.

Returns:
  The URI of the XML Schema type referring to the stored type or an empty QUrl if the LiteralValue is empty or is a plain literal.

bool isBool | ( |  | self ) |

bool isByteArray | ( |  | self ) |

bool isDate | ( |  | self ) |

bool isDateTime | ( |  | self ) |

bool isDouble | ( |  | self ) |

bool isInt | ( |  | self ) |

bool isInt64 | ( |  | self ) |

bool isPlain | ( |  | self ) |

Determines if this literal value is a plain literal. Plain literals have no data type, but may have an optional language tag.

Returns:
  true if this literal is plain

bool isString | ( |  | self ) |

Check if the literal contains a string value. Be aware that unknown literal types are also treated as strings. In that case compare dataTypeUrl.

bool isTime | ( |  | self ) |

bool isUnsignedInt | ( |  | self ) |

bool isUnsignedInt64 | ( |  | self ) |

bool isValid | ( |  | self ) |

Soprano.LanguageTag language | ( |  | self ) |

The language tag.

Returns:
  The language tag of the plain literal or an empty LanguageTag if the LiteralValue has no language or it is a typed literal.

bool operator != | ( | self, |
|  | Soprano.LiteralValue | other
| ) |  |  |

bool operator == | ( | self, |
|  | Soprano.LiteralValue | other
| ) |  |  |

bool toBool | ( |  | self ) |

QByteArray toByteArray | ( |  | self ) |

QDate toDate | ( |  | self ) |

QDateTime toDateTime | ( |  | self ) |

float toDouble | ( |  | self ) |

int toInt | ( |  | self ) |

long toInt64 | ( |  | self ) |

QString toString | ( |  | self ) |

Each type can be converted to a string which means that toString in combination with dataTypeUrl provides all the information necessary to store this literal as RDF.

The string value is cached so calling it multiple times in a row is fast.

Warning:
  For historical reasons this is not a user-readable representation.

\sa Node.toString

QTime toTime | ( |  | self ) |

long toUnsignedInt | ( |  | self ) |

long toUnsignedInt64 | ( |  | self ) |

QVariant::Type type | ( |  | self ) |

The type of the data.

Returns:
  The QVariant type of the stored data or QVariant.Invalid if it is an empty value.

QVariant variant | ( |  | self ) |

The literal value represented in a QVariant. Be aware that the RDF typing information is lost in the converted variant.

## Static Method Documentation

Soprano.LiteralValue createPlainLiteral | ( | QString | value,
|  | Soprano.LanguageTag | lang=Soprano.LanguageTag()
| ) |  |  |

Create a plain LiteralValue object with an optional language tag.

Parameters:

  | value | The value of the literal.

Parameters:

  | lang | The language tag.

Both an empty value and lang will result in an invalid LiteralValue instance but an empty value with a valid lang is possible. A valid value with an empty lang will result in a plain, untyped literal with no language tag.

Returns:
  A newly created LiteralValue instance based on the provided value and

lang.

QUrl dataTypeUriFromType | ( | QVariant::Type | type
| ) |  |  |

Convert a QVariant.Type into an XML Schema URI.

Returns:
  The XML Schema URI that corresponds to type or an empty QUrl if the type os unknown, i.e. can not be mapped to an XML Schema type.

Soprano.LiteralValue fromString | ( | QString | value,
|  | QVariant::Type | type
| ) |  |  |

Create a LiteralValue object by parsing string value based on dataTypeUri.

Parameters:

  | value | The value of the literal. Might be converted based on dataTypeUri.

Parameters:

  | dataTypeUri | The data type URI. %Soprano can automatically convert all XML schema types. All other (unknown) types will be stored as a string value with the plain dataTypeUri as type. Thus, unknown literal types can still be used without automatic type conversion. (Be aware though, that changing the value of a LiteralValue instance will reset the type, ie. custom data type URIs will be lost.)

Both an empty value and dataTypeUri will result in an invalid LiteralValue instance but an empty value with a valid dataTypeUri is possible. A valid value with an invalid dataTypeUri will result in a LiteralValue of type Vocabulary.XMLSchema.string.

Returns:
  A newly created LiteralValue instance based on the provided value and

dataTypeUri.

\sa fromString(const QString&, QVariant.Type), Vocabulary.XMLSchema

Soprano.LiteralValue fromString | ( | QString | value,
|  | QUrl | dataTypeUri
| ) |  |  |

Create a LiteralValue object by parsing string value based on dataTypeUri.

Parameters:

  | value | The value of the literal. Might be converted based on dataTypeUri.

Parameters:

  | dataTypeUri | The data type URI. %Soprano can automatically convert all XML schema types. All other (unknown) types will be stored as a string value with the plain dataTypeUri as type. Thus, unknown literal types can still be used without automatic type conversion. (Be aware though, that changing the value of a LiteralValue instance will reset the type, ie. custom data type URIs will be lost.)

Both an empty value and dataTypeUri will result in an invalid LiteralValue instance but an empty value with a valid dataTypeUri is possible. A valid value with an invalid dataTypeUri will result in a LiteralValue of type Vocabulary.XMLSchema.string.

Returns:
  A newly created LiteralValue instance based on the provided value and

dataTypeUri.

\sa fromString(const QString&, QVariant.Type), Vocabulary.XMLSchema

Soprano.LiteralValue fromVariant | ( | QVariant | value,
|  | QUrl | dataType
| ) |  |  |

Create a LiteralValue object by converting value to the given dataType.

If the type of the variant matches the dataType this method has the same effect as the constructor which takes a QVariant as parameter. However, this method supports automatic conversion for a set of types including:

- Conversion of different decimal types
- Conversion of everything to xsd:string
- Conversion of decimal types to xsd:dateTime (using QDateTime.fromTime_t())

Parameters:

  | value | The value the created LiteralValue should have. If invalid an invalid LiteralValue will be created.

Parameters:

  | dataType | The RDF literal data type the created LiteralValue should have. If empty the result will be the same as providing value to the constructor of LiteralValue. No conversion will take place.

Returns:
  A newly created Literalvalue instance based on the given value and

dataType.

Since:
  2.7

QVariant::Type typeFromDataTypeUri | ( | QUrl | dataTypeUri
| ) |  |  |

Convert an XML Schema URI into a QVariant.Type.

Returns:
  The QVariant.Type corresponding to dataTypeUri or QVariant.Invalid if dataTypeUri is unknown.