Soprano  2.9.4
Public Slots | Public Member Functions | List of all members
Soprano::Inference::InferenceModel Class Reference

The Soprano Inference Model provides a simple forward chaining inference engine which uses the underlying parent model itself to store status information. More...

#include <Soprano/Inference/InferenceModel>

+ Inheritance diagram for Soprano::Inference::InferenceModel:

Public Slots

void performInference ()
 
void clearInference ()
 
void setCompressedSourceStatements (bool b)
 
void setOptimizedQueriesEnabled (bool b)
 

Public Member Functions

 InferenceModel (Model *parent)
 
 ~InferenceModel ()
 
Error::ErrorCode addStatement (const Statement &)
 
Error::ErrorCode removeStatement (const Statement &)
 
Error::ErrorCode removeAllStatements (const Statement &)
 
void addRule (const Rule &)
 
void setRules (const QList< Rule > &rules)
 
virtual Error::ErrorCode addStatement (const Statement &statement)
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode addStatement (const Statement &statement)=0
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeStatement (const Statement &statement)
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeStatement (const Statement &statement)=0
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeAllStatements (const Statement &statement)
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeAllStatements (const Statement &statement)=0
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeAllStatements ()
 
- Public Member Functions inherited from Soprano::FilterModel
virtual ~FilterModel ()
 
virtual void setParentModel (Model *model)
 
virtual ModelparentModel () const
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual StatementIterator listStatements (const Statement &partial) const
 
StatementIterator listStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual NodeIterator listContexts () const
 
virtual QueryResultIterator executeQuery (const QString &query, Query::QueryLanguage language, const QString &userQueryLanguage=QString()) const
 
virtual bool containsStatement (const Statement &statement) const
 
bool containsStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual bool containsAnyStatement (const Statement &statement) const
 
bool containsAnyStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual bool isEmpty () const
 
virtual int statementCount () const
 
virtual Error::ErrorCode write (QTextStream &os) const
 
virtual Node createBlankNode ()
 
virtual Error::ErrorCode addStatement (const Statement &statement)=0
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeStatement (const Statement &statement)=0
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeAllStatements (const Statement &statement)=0
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeAllStatements ()
 
virtual StatementIterator listStatements (const Statement &partial) const=0
 
StatementIterator listStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
StatementIterator listStatements () const
 
virtual bool containsStatement (const Statement &statement) const=0
 
bool containsStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual bool containsAnyStatement (const Statement &statement) const=0
 
bool containsAnyStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
- Public Member Functions inherited from Soprano::Model
virtual ~Model ()
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode addStatements (const QList< Statement > &statements)
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeStatements (const QList< Statement > &statements)
 
Error::ErrorCode removeContext (const Node &)
 
Error::ErrorCode removeAllStatements ()
 
StatementIterator listStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
StatementIterator listStatements () const
 
StatementIterator listStatementsInContext (const Node &context) const
 
bool containsAnyStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
bool containsStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
bool containsContext (const Node &context) const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent=0)
 
 blockSignals (bool block)
 
 childEvent (QChildEvent *event)
 
 children ()
 
 connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type=Qt::AutoCompatConnection)
 
 connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type=Qt::AutoCompatConnection)
 
 connectNotify (const char *signal)
 
 customEvent (QEvent *event)
 
 deleteLater ()
 
 destroyed (QObject *obj=0)
 
 disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
 disconnect (const char *signal=0, const QObject *receiver=0, const char *method=0)
 
 disconnect (const QObject *receiver, const char *method=0)
 
 disconnectNotify (const char *signal)
 
 dumpObjectInfo ()
 
 dumpObjectTree ()
 
 dynamicPropertyNames ()
 
 event (QEvent *e)
 
 eventFilter (QObject *watched, QEvent *event)
 
 findChild (const QString &name=QString()
 
 findChildren (const QString &name=QString()
 
 findChildren (const QRegExp &regExp)
 
 inherits (const char *className)
 
 installEventFilter (QObject *filterObj)
 
 isWidgetType ()
 
 killTimer (int id)
 
 metaObject ()
 
 moveToThread (QThread *targetThread)
 
 parent ()
 
 property (const char *name)
 
 receivers (const char *signal)
 
 removeEventFilter (QObject *obj)
 
 sender ()
 
 setParent (QObject *parent)
 
 setProperty (const char *name, const QVariant &value)
 
 signalsBlocked ()
 
 startTimer (int interval)
 
 thread ()
 
 timerEvent (QTimerEvent *event)
 
 tr (const char *sourceText, const char *comment=0, int n=-1)
 
 trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
 staticMetaObject
 
 QObject (QObject *parent, const char *name)
 
 checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
 child (const char *objName, const char *inheritsClass=0, bool recursiveSearch=true)
 
 className ()
 
 insertChild (QObject *object)
 
 isA (const char *className)
 
 name ()
 
 name (const char *defaultName)
 
 normalizeSignalSlot (const char *signalSlot)
 
 removeChild (QObject *object)
 
 setName (const char *name)
 
- Public Member Functions inherited from Soprano::Error::ErrorCache
virtual ~ErrorCache ()
 
virtual Error lastError () const
 

Additional Inherited Members

- Signals inherited from Soprano::Model
void statementsAdded ()
 
void statementsRemoved ()
 
void statementAdded (const Soprano::Statement &statement)
 
void statementRemoved (const Soprano::Statement &statement)
 
- Protected Member Functions inherited from Soprano::FilterModel
 FilterModel ()
 
 FilterModel (Model *parent)
 
virtual void parentStatementsAdded ()
 
virtual void parentStatementsRemoved ()
 
virtual void parentStatementAdded (const Statement &)
 
virtual void parentStatementRemoved (const Statement &)
 
- Protected Member Functions inherited from Soprano::Model
 Model ()
 
- Protected Member Functions inherited from Soprano::Error::ErrorCache
 ErrorCache ()
 
void clearError () const
 
void setError (const Error &) const
 
void setError (const QString &errorMessage, int code=ErrorUnknown) const
 

Detailed Description

The Soprano Inference Model provides a simple forward chaining inference engine which uses the underlying parent model itself to store status information.

The InferenceModel does perfect inference which means that removing of statements is supported and results in a perfect update of the infered statements. There is only one exception: If a model contains two statements in different named graphs that both have the same subject, predicate, and object and trigger one rule then if one of these statements is removed the infered statements are removed, too, although the second statement would still make the infered one valid. This situation gets resolved once the same rule is triggered again by some other added statement or performInference gets called.

The inference is performed based on rules which are stored in Rule instances. Rules can be created manually or parsed using a RuleParser.

The inference engine works roughly as follows:

Whenever a new statement is added it is compared to each rule to check if it could trigger this rule. Then if it could trigger a rule this rule is applied to the whole model.

If a rule produces a new infered statement the following data is created:

Thus, when removing a statement it can easily be checked if this statement had been used to infer another one by querying all named graphs that have this statement as a source statement.

Author
Sebastian Trueg trueg.nosp@m.@kde.nosp@m..org

Definition at line 71 of file inferencemodel.h.

Constructor & Destructor Documentation

◆ InferenceModel()

Soprano::Inference::InferenceModel::InferenceModel ( Model parent)

◆ ~InferenceModel()

Soprano::Inference::InferenceModel::~InferenceModel ( )

Member Function Documentation

◆ addStatement() [1/5]

Error::ErrorCode Soprano::Inference::InferenceModel::addStatement ( const Statement )
virtual

Add a new statement to the model. Inferencing will be done directly. Inferenced statements are stored in additional named graphs.

Reimplemented from Soprano::FilterModel.

◆ removeStatement() [1/5]

Error::ErrorCode Soprano::Inference::InferenceModel::removeStatement ( const Statement )
virtual

Remove one statement from the model.

Reimplemented from Soprano::FilterModel.

◆ removeAllStatements() [1/6]

Error::ErrorCode Soprano::Inference::InferenceModel::removeAllStatements ( const Statement )
virtual

Remove statements from the model.

Reimplemented from Soprano::FilterModel.

◆ addRule()

void Soprano::Inference::InferenceModel::addRule ( const Rule )

Add an inference rule to the set of rules. This method will not trigger any inference action. If inference is necessary call performInference() after adding the new rules.

◆ setRules()

void Soprano::Inference::InferenceModel::setRules ( const QList< Rule > &  rules)

Set the inference rules to be used. This method will not trigger any inference action. If inference is necessary call performInference() after adding the new rules.

◆ performInference

void Soprano::Inference::InferenceModel::performInference ( )
slot

Normally inferencing is done once new statements are added to the model or statements are removed. This method performs inferencing on the whole model. It is useful for initializing a model that already contains statements or update the model if it has been modified bypassing this filter model.

Tha latter can easily be done by connecting the Model::statementsAdded and Model::statementsRemoved signals to this slot.

◆ clearInference

void Soprano::Inference::InferenceModel::clearInference ( )
slot

Removes all statements infered by this model. This can be useful if the parent model has been changed without informing the inference model and statements have been removed.

◆ setCompressedSourceStatements

void Soprano::Inference::InferenceModel::setCompressedSourceStatements ( bool  b)
slot

If compressed statements are enabled source statements are stored compressed in one literal value. Otherwise source statements are stored using rdf:subject, rdf:predicate, rdf:object, and sil:context. Non-compressed statements are much cleaner from an ontology design point of view while compressed statements take much less space.

By default comressed source statements are enabled.

This method exists mainly for historical reasons and there normally is no need to call it. Compressed statements should work well for most users.

Parameters
bIf true compressed source statements are enabled (the default).

◆ setOptimizedQueriesEnabled

void Soprano::Inference::InferenceModel::setOptimizedQueriesEnabled ( bool  b)
slot

If the storage backend supports joined SPARQL queries via UNION it makes sense to enable this.

Parameters
bIf true InferenceModel will use optimized queries for the inference during addStatement. This will speed up the process quite a lot as matching rules are only applied to the new statement. This flag has no influcence on performInference() though.

The default is to disable the optimized queries since the default soprano redland backend does not support UNION.

◆ addStatement() [2/5]

virtual Error::ErrorCode Soprano::FilterModel::addStatement

Default implementation simply pipes the call through to the parent model.

◆ addStatement() [3/5]

Error::ErrorCode Soprano::FilterModel::addStatement

◆ addStatement() [4/5]

virtual Error::ErrorCode Soprano::Model::addStatement

Add the Statement to the Model.

Parameters
statementThe Statement to add.

◆ addStatement() [5/5]

Error::ErrorCode Soprano::Model::addStatement

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ removeStatement() [2/5]

virtual Error::ErrorCode Soprano::FilterModel::removeStatement

Default implementation simply pipes the call through to the parent model.

◆ removeStatement() [3/5]

Error::ErrorCode Soprano::FilterModel::removeStatement

◆ removeStatement() [4/5]

virtual Error::ErrorCode Soprano::Model::removeStatement

Remove one statement. For removing statements with wildward matching see removeAllStatements().

Parameters
statementThe statement that should be removed. This has to be a valid statement.
Returns
Error::ErrorNone on success and an error code if statement was invalid or an error occured.

◆ removeStatement() [5/5]

Error::ErrorCode Soprano::Model::removeStatement

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ removeAllStatements() [2/6]

virtual Error::ErrorCode Soprano::FilterModel::removeAllStatements

Default implementation simply pipes the call through to the parent model.

◆ removeAllStatements() [3/6]

Error::ErrorCode Soprano::FilterModel::removeAllStatements

◆ removeAllStatements() [4/6]

virtual Error::ErrorCode Soprano::Model::removeAllStatements

Remove all statements that match the partial statement. For removing one specific statement see removeStatement().

Parameters
statementA possible partially defined statement that serves as a filter for all statements that should be removed.

◆ removeAllStatements() [5/6]

Error::ErrorCode Soprano::Model::removeAllStatements

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
subjectThe subject node to match. Can be empty as a wildcard.
predicateThe predicate node to match. Can be empty as a wildcard.
objectThe object node to match. Can be empty as a wildcard.
contextThe context node to match. Can be empty as a wildcard.

◆ removeAllStatements() [6/6]

Error::ErrorCode Soprano::Model::removeAllStatements

Convenience method that clear the Model of all statements


The documentation for this class was generated from the following file: