Node Class Reference
from PyKDE4.soprano import *
Namespace: Soprano
Detailed Description
\class Node node.h Soprano/Node
A Node represents one RDF resource.
Nodes are the cornerstone of RDF data in %Soprano. Four Nodes form one Statement and a Model is essentially a set of Statements.
A Node can have one of four types: EmptyNode, ResourceNode, LiteralNode, and BlankNode. Resource nodes are identified through their URI (uri()), literal nodes have a LiteralValue (literal()), and blank nodes have a string identifier.
Empty nodes can be used as wildcards in methods such as Model.listStatements.
Enumerations | |
N3ParserFlag | { NoFlags, StrictLiteralTypes, StrictUris, IgnorePrefixes } |
Type | { EmptyNode, ResourceNode, LiteralNode, BlankNode } |
Methods | |
__init__ (self) | |
__init__ (self, QUrl uri) | |
__init__ (self, QString id) | |
__init__ (self, Soprano.LiteralValue value) | |
__init__ (self, Soprano.LiteralValue value, QString language) | |
__init__ (self, Soprano.Node other) | |
QUrl | dataType (self) |
QString | identifier (self) |
bool | isBlank (self) |
bool | isEmpty (self) |
bool | isLiteral (self) |
bool | isResource (self) |
bool | isValid (self) |
QString | language (self) |
Soprano.LiteralValue | literal (self) |
bool | matches (self, Soprano.Node other) |
bool | operator != (self, Soprano.Node other) |
bool | operator == (self, Soprano.Node other) |
bool | operator == (self, QUrl uri) |
bool | operator == (self, Soprano.LiteralValue other) |
QString | toN3 (self) |
QString | toString (self) |
Soprano.Node.Type | type (self) |
QUrl | uri (self) |
Static Methods | |
QString | blankToN3 (QString blank) |
Soprano.Node | createBlankNode (QString id) |
Soprano.Node | createEmptyNode () |
Soprano.Node | createLiteralNode (Soprano.LiteralValue value) |
Soprano.Node | createLiteralNode (Soprano.LiteralValue value, QString language) |
Soprano.Node | createResourceNode (QUrl uri) |
Soprano.Node | fromN3 (QString n3, Soprano.Node.N3ParserFlags flags=Soprano.Node.NoFlags) |
Soprano.Node | fromN3Stream (QTextStream stream, Soprano.Node.N3ParserFlags flags=Soprano.Node.NoFlags) |
QString | literalToN3 (Soprano.LiteralValue literal) |
QString | resourceToN3 (QUrl resource) |
Method Documentation
__init__ | ( | self ) |
Default costructor. Creates an empty node.
\sa createEmptyNode()
__init__ | ( | self, | ||
QUrl | uri | |||
) |
Creates a resource node.
- Parameters:
-
uri The URI of the node. If empty the type will be ignored and an empty node will be created.
\sa createResourceNode()
__init__ | ( | self, | ||
QString | id | |||
) |
Creates a blank node.
- Parameters:
-
id An identifier for the blank node.
\sa createBlankNode()
__init__ | ( | self, | ||
Soprano.LiteralValue | value | |||
) |
Creates a literal node.
- Parameters:
-
value The value of a node. If empty the node will become an empty node.
\sa createLiteralNode()
- Since:
- 2.3
__init__ | ( | self, | ||
Soprano.LiteralValue | value, | |||
QString | language | |||
) |
__init__ | ( | self, | ||
Soprano.Node | other | |||
) |
Copy constructor.
QUrl dataType | ( | self ) |
- Returns:
- The datatype URI of a literal node, i.e. the XML schema type or an empty value if the node is not a LiteralNode.
QString identifier | ( | self ) |
Retrieve a blank node's identifier.
- Returns:
- The node's identifier if it is a BlankNode, a null string otherwise.
bool isBlank | ( | self ) |
- Returns:
- true if the node is a BlankNode (anonymous).
bool isEmpty | ( | self ) |
- Returns:
- true if the node is empty.
bool isLiteral | ( | self ) |
- Returns:
- true if the node is a LiteralNode.
bool isResource | ( | self ) |
- Returns:
- true if the node is a ResourceNode.
bool isValid | ( | self ) |
- Returns:
- true if the node is a ResourceNode, LiteralNode or BlankNode.
QString language | ( | self ) |
Each literal value can have an associated language, thus each property can be stored for different languages. An empty language refers to the default language.
- Returns:
- A string representing the language of the literal value or an empty string if the node is not a literal.
- Deprecated:
- Language exists on the Soprano.LiteralValue. Use Soprano.Node.literal() and Soprano.LiteralValue.language().
Soprano.LiteralValue literal | ( | self ) |
- Returns:
- The literal value if the node is a LiteralNode. An null QString otherwise.
bool matches | ( | self, | ||
Soprano.Node | other | |||
) |
Match this node against template node other. The only difference to operator== is that empty nodes are matched as wildcards, i.e. they match any other node.
Be aware that the following is NOT always true since only other is treated a a wildcard:
// NOT always true: a.matches(b) == b.matches(a)
- Returns:
- true if this node matches other, false if not.
\sa Statement.matches
bool operator != | ( | self, | ||
Soprano.Node | other | |||
) |
Comparision operator.
- Returns:
- true if this node and other differ.
bool operator == | ( | self, | ||
Soprano.Node | other | |||
) |
Comparision operator.
- Returns:
- true if this node is a LiteralNode and has literal value other.
bool operator == | ( | self, | ||
QUrl | uri | |||
) |
Comparision operator.
- Returns:
- true if this node is a LiteralNode and has literal value other.
bool operator == | ( | self, | ||
Soprano.LiteralValue | other | |||
) |
Comparision operator.
- Returns:
- true if this node is a LiteralNode and has literal value other.
QString toN3 | ( | self ) |
Convert a Node into N3 notation to be used in SPARQL graph patterns.
Examples:
<http://soprano.sourceforce.net/> "Hello World"^^<http://www.w3.org/2001/XMLSchema#string> "09-08-1977T17:42.234Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> _:blankNode
- Returns:
- A string representing the node in N3 encoding or an empty string for invalid nodes.
\sa resourceToN3(), literalToN3(), blankToN3(), fromN3(), toString()
- Since:
- 2.2
QString toString | ( | self ) |
Converts the Node to a string.
- Returns:
- A String representation of the Node, suitable for storage, not really suitable for user readable strings.
\sa LiteralValue.toString(), QUrl.toString(), toN3()
Soprano.Node.Type type | ( | self ) |
- Returns:
- The node type.
QUrl uri | ( | self ) |
- Returns:
- The URI if the node is a ResourceNode. An null QUrl otherwise.
Static Method Documentation
QString blankToN3 | ( | QString | blank | |
) |
Format a blank node identifier as N3 string to be used in SPARQL queries.
- Returns:
- A string representing the blank identifier in N3 encoding or an empty string for invalid/empty ids.
Example:
_:blankNode
\sa toN3(), fromN3()
- Since:
- 2.3
Soprano.Node createBlankNode | ( | QString | id | |
) |
Convenience method to create a blank node. Using this method instead of the constructor may result in better readable code.
If you need to create a new blank node which is not used in the model yet and, thus, has a unique identifier see Model.createBlankNode().
- Parameters:
-
id An identifier for the blank node.
- Returns:
- A blank node or an empty Node if the specified identifier was empty.
Soprano.Node createEmptyNode | ( | ) |
Convenience method to create an empty node. Using this method instead of the default constructor may result in better readable code.
- Returns:
- An empty Node.
Soprano.Node createLiteralNode | ( | Soprano.LiteralValue | value | |
) |
Convenience method to create a literal node. Using this method instead of the constructor may result in better readable code.
- Parameters:
-
value The value of a node. If empty the node will become an empty node.
- Parameters:
-
language The language of the literal value.
- Returns:
- A literal node or an empty node if the specified value was empty.
- Deprecated:
- Use Soprano.Node.createLiteralNode( const LiteralValue& ) and Soprano.LiteralValue.createPlainLiteral( const QString&, const LanguageTag& )
Soprano.Node createLiteralNode | ( | Soprano.LiteralValue | value, | |
QString | language | |||
) |
Convenience method to create a literal node. Using this method instead of the constructor may result in better readable code.
- Parameters:
-
value The value of a node. If empty the node will become an empty node.
- Parameters:
-
language The language of the literal value.
- Returns:
- A literal node or an empty node if the specified value was empty.
- Deprecated:
- Use Soprano.Node.createLiteralNode( const LiteralValue& ) and Soprano.LiteralValue.createPlainLiteral( const QString&, const LanguageTag& )
Soprano.Node createResourceNode | ( | QUrl | uri | |
) |
Convenience method to create a resource node. Using this method instead of the constructor may result in better readable code.
- Parameters:
-
uri The URI of the node. If empty the type will be ignored and an empty node will be created.
- Returns:
- A resource Node or an empty Node if the specified URI is empty.
Soprano.Node fromN3 | ( | QString | n3, | |
Soprano.Node.N3ParserFlags | flags=Soprano.Node.NoFlags | |||
) |
Convert a node from its N3 representation.
- Parameters:
-
n3 The N3 representation of the node.
- Returns:
- A %Node representing the parsed version of n3 or an invalid %Node in case parsing failed.
\sa resourceToN3(), literalToN3(), blankToN3(), toN3()
- Since:
- 2.5
Soprano.Node fromN3Stream | ( | QTextStream | stream, | |
Soprano.Node.N3ParserFlags | flags=Soprano.Node.NoFlags | |||
) |
Read a node from its N3 representation on a stream.
- Parameters:
-
stream The stream from which the N3 representation of the node will be read.
- Returns:
- A %Node representing the parsed version of n3 or an invalid %Node in case parsing failed.
\sa resourceToN3(), literalToN3(), blankToN3(), toN3()
- Since:
- 2.5
QString literalToN3 | ( | Soprano.LiteralValue | literal | |
) |
Format a literal value as N3 string to be used in SPARQL queries.
- Returns:
- A string representing the literal in N3 encoding or an empty string for invalid literals.
Examples:
"Hello World"^^<http://www.w3.org/2001/XMLSchema#string> "09-08-1977T17:42.234Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>
\sa toN3(), fromN3()
- Since:
- 2.3
QString resourceToN3 | ( | QUrl | resource | |
) |
Format a resource URI as N3 string to be used in SPARQL queries.
- Returns:
- A string representing the resource in N3 encoding or an empty string for invalid URIs.
Example:
<http://soprano.sourceforce.net/>
\sa toN3(), fromN3()
- Since:
- 2.3
Enumeration Documentation
N3ParserFlag |
Parsing flags to infuence the behaviour of the parser in fromN3() and fromN3Stream().
- Since:
- 2.5
- Enumerator:
-
NoFlags = 0x0 StrictLiteralTypes = 0x1 StrictUris = 0x2 IgnorePrefixes = 0x4
Type |
- Enumerator:
-
EmptyNode = 0 ResourceNode = 1 LiteralNode = 2 BlankNode = 3