Model Class Reference
from PyKDE4.soprano import *
Inherits: QObject,Soprano.Error.ErrorCache
Namespace: Soprano
Detailed Description
\class Model model.h Soprano/Model
A Model is the central class in %Soprano. It is a queryable collection of RDF quadruples, i.e statements.
Model itself is just an interface for numerous implementations. (If you are looking for a simple container for statements, see Graph.) There are basically two types of Models in %Soprano:
The simplest way to create a memory Model is to use the default Backend:
Model* memModel = Soprano.createModel();
%Error handling:
Model is based on %Soprano's own error handling system which tries to emulate exceptions to a certain extend. Most methods in Model have a means of reporting if an operation was successful or not. For additional error information Model inherits ErrorCache which provides the method lastError().
Thus, advanced error handling would look as follows:
Soprano.Model* model = Soprano.createModel(); Soprano.Statement invalidStatement; if( model->addStatement( invalidStatement ) != Error.ErrorNone ) { showErrorMessage( model->lastError().message() ); }
For this to work properly Model implementations have to reset the error in each method by either calling clearError() or setError().
\sa soprano_error_handling
Model is thread-safe when used with a thread-safe backend (all "official" %Soprano backends are thread-safe). However, it is recommended to create Model instances in the main thread.
Signal Documentation
statementAdded | ( | Soprano.Statement | statement | |
) |
Notification signal for new statements. Model implementations should emit this signal for each newly added statement.
- Signal syntax:
QObject.connect(source, SIGNAL("statementAdded(const Soprano::Statement&)"), target_slot)
statementRemoved | ( | Soprano.Statement | statement | |
) |
Notification signal for removed statements. Model implementations should emit this signal for each removed statement.
- Warning:
- Backends may choose not to emit this signal for each removed statement but only for a statement pattern (i.e. an invalid statement as used in removeAllStatements()) to prevent massive performance loss.
- Signal syntax:
QObject.connect(source, SIGNAL("statementRemoved(const Soprano::Statement&)"), target_slot)
statementsAdded | ( | ) |
Emitted when new statements have been added to the model.
Implementations of this interface have to emit this signal.
- Signal syntax:
QObject.connect(source, SIGNAL("statementsAdded()"), target_slot)
statementsRemoved | ( | ) |
Emitted when statements have been removed from the model.
Implementations of this interface have to emit this signal.
- Signal syntax:
QObject.connect(source, SIGNAL("statementsRemoved()"), target_slot)
Method Documentation
__init__ | ( | self ) |
Model instances are not meant to be copied.
__init__ | ( | self, | ||
Soprano.Model | a0 | |||
) |
Model instances are not meant to be copied.
Soprano.Error.ErrorCode addStatement | ( | self, | ||
Soprano.Statement | statement | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Soprano.Error.ErrorCode addStatement | ( | self, | ||
Soprano.Node | subject, | |||
Soprano.Node | predicate, | |||
Soprano.Node | object, | |||
Soprano.Node | context=Soprano.Node() | |||
) |
Soprano.Error.ErrorCode addStatements | ( | self, | ||
[Soprano.Statement] | statements | |||
) |
bool containsAnyStatement | ( | self, | ||
Soprano.Statement | statement | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
- Parameters:
-
subject The subject node to match. Can be empty as a wildcard.
- Parameters:
-
predicate The predicate node to match. Can be empty as a wildcard.
- Parameters:
-
object The object node to match. Can be empty as a wildcard.
- Parameters:
-
context The context node to match. Can be empty as a wildcard.
bool containsAnyStatement | ( | self, | ||
Soprano.Node | subject, | |||
Soprano.Node | predicate, | |||
Soprano.Node | object, | |||
Soprano.Node | context=Soprano.Node() | |||
) |
- Parameters:
-
subject The subject node to match. Can be empty as a wildcard.
- Parameters:
-
predicate The predicate node to match. Can be empty as a wildcard.
- Parameters:
-
object The object node to match. Can be empty as a wildcard.
- Parameters:
-
context The context node to match. Can be empty as a wildcard.
bool containsContext | ( | self, | ||
Soprano.Node | context | |||
) |
Convenience method which is based on containsAnyStatement
bool containsStatement | ( | self, | ||
Soprano.Statement | statement | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
bool containsStatement | ( | self, | ||
Soprano.Node | subject, | |||
Soprano.Node | predicate, | |||
Soprano.Node | object, | |||
Soprano.Node | context=Soprano.Node() | |||
) |
Soprano.Node createBlankNode | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Creates a new blank node with a unique identifier.
- Returns:
- A blank node that can be used to create new statements.
Soprano.QueryResultIterator executeQuery | ( | self, | ||
QString | query, | |||
Soprano.Query.QueryLanguage | language, | |||
QString | userQueryLanguage=QString() | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Execute the given query over the Model.
This is a const read-only method. As such Model implementations should not support SPARQL extensions such as INSERT or UPDATE through this method. A future version of %Soprano will provide an additional API for queries that change the Model.
- Parameters:
-
query The query to evaluate.
- Parameters:
-
language The %query language used to encode query.
- Parameters:
-
userQueryLanguage If language equals Query.QueryLanguageUser userQueryLanguage defines the language to use.
- Returns:
- An iterator over all results matching the query, on error an invalid iterator is returned.
bool isEmpty | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
- Returns:
- true if the Model doesn't contains any Statement.
Soprano.NodeIterator listContexts | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
List all contexts in the model, i.e. all named graphs.
- Returns:
- An iterator over context Nodes, on error an invalid iterator is returned.
Soprano.StatementIterator listStatements | ( | self, | ||
Soprano.Statement | partial | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
- Returns:
- An iterator for all statements in the model, on error an invalid iterator is returned.
Soprano.StatementIterator listStatements | ( | self, | ||
Soprano.Node | subject, | |||
Soprano.Node | predicate, | |||
Soprano.Node | object, | |||
Soprano.Node | context=Soprano.Node() | |||
) |
- Returns:
- An iterator for all statements in the model, on error an invalid iterator is returned.
Soprano.StatementIterator listStatements | ( | self ) |
- Returns:
- An iterator for all statements in the model, on error an invalid iterator is returned.
Soprano.StatementIterator listStatementsInContext | ( | self, | ||
Soprano.Node | context | |||
) |
Convenience method which lists all statements in context.
- Returns:
- An iterator for all the matched Statements, on error an invalid iterator is returned.
Soprano.Error.ErrorCode removeAllStatements | ( | self, | ||
Soprano.Statement | statement | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Convenience method that clear the Model of all statements
Soprano.Error.ErrorCode removeAllStatements | ( | self, | ||
Soprano.Node | subject, | |||
Soprano.Node | predicate, | |||
Soprano.Node | object, | |||
Soprano.Node | context=Soprano.Node() | |||
) |
Convenience method that clear the Model of all statements
Soprano.Error.ErrorCode removeAllStatements | ( | self ) |
Convenience method that clear the Model of all statements
Soprano.Error.ErrorCode removeContext | ( | self, | ||
Soprano.Node | a0 | |||
) |
Convenience method that removes all statements in the context.
Soprano.Error.ErrorCode removeStatement | ( | self, | ||
Soprano.Statement | statement | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Soprano.Error.ErrorCode removeStatement | ( | self, | ||
Soprano.Node | subject, | |||
Soprano.Node | predicate, | |||
Soprano.Node | object, | |||
Soprano.Node | context=Soprano.Node() | |||
) |
Soprano.Error.ErrorCode removeStatements | ( | self, | ||
[Soprano.Statement] | statements | |||
) |
Convenience method which removes all %statements in statements.
int statementCount | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
The number of statements stored in this Model.
- Returns:
- The size of the Model, or -1 on error.
Soprano.Error.ErrorCode write | ( | self, | ||
QTextStream | os | |||
) |
Write all statements in this Model to os.
Default implementation is based on Model.listStatements