KDE 4.7 PyKDE API Reference

- KDE's Python API

# Rule Class Reference

`from PyKDE4.soprano import *`

Namespace: Soprano.Inference

## Detailed Description

\class Rule inferencerule.h Soprano/Inference/Rule

A rule used by the InferenceModel to generate inferenced statements.

Rules can be created manually by adding preconditions and the effect via addPrecondition() and setEffect() or from a rules file through the RuleParser.

Author:
  Sebastian Trueg <trueg@kde.org>

## Methods
| __init__ (self)
| __init__ (self, Soprano.Inference.Rule other)
| addPrecondition (self, Soprano.Inference.StatementPattern a0)
Soprano.Statement | bindEffect (self, Soprano.BindingSet bindings)
[Soprano.Statement] | bindPreconditions (self, Soprano.BindingSet bindings)
| bindToStatement (self, Soprano.Statement statement)
Soprano.Statement | boundToStatement (self)
QString | createSparqlQuery (self, bool bindVariables=0)
Soprano.Inference.StatementPattern | effect (self)
bool | isValid (self)
bool | match (self, Soprano.Statement statement)
[Soprano.Inference.StatementPattern] | preconditions (self)
| setEffect (self, Soprano.Inference.StatementPattern a0)

## Method Documentation

__init__ | ( |  | self ) |

Constructs an invalid rule

__init__ | ( | self, |
|  | Soprano.Inference.Rule | other
| ) |  |  |

Copy constructor. Creates a shallow copy of other.

addPrecondition | ( | self, |
|  | Soprano.Inference.StatementPattern | a0
| ) |  |  |

Add a precondition

Soprano.Statement bindEffect | ( | self, |
|  | Soprano.BindingSet | bindings
| ) |  |  |

Bind the rule's effect to a set of bindings as reveived from a query. If the bindings do not contain all variables the bound statement is used as backup.

Parameters:

  | bindings | The bindings to apply to this rule.

Returns:
  The statement infered by this rule under the application of bindings.

\sa bindToStatement, bindPreconditions

[Soprano.Statement] bindPreconditions | ( | self, |
|  | Soprano.BindingSet | bindings
| ) |  |  |

Bind the rule's preconditions to a set of bindings as reveived from a query. If the bindings do not contain all variables the bound statement is used as backup.

Parameters:

  | bindings | The bindings to apply to this rule.

Returns:
  The statements that have to be valid in order for this rule to infer the statement returned by bindEffect under the same bindings.

\sa bindToStatement, bindEffect

bindToStatement | ( | self, |
|  | Soprano.Statement | statement
| ) |  |  |

Bind this rule to a specific Statement.

The purpose of this method is to allow retricting the application of a rule to one statement, i.e. a newly added one.

Parameters:

  | statement | The Statement to bind this rule to.

\sa createSparqlQuery, bindEffect, bindPreconditions

Soprano.Statement boundToStatement | ( |  | self ) |

Returns:
  The statement set ia bindToStatement() or an invalid one if none was set.

QString createSparqlQuery | ( | self, |
|  | bool | bindVariables=0
| ) |  |  |

Create a SPARQL query that retrieves all resources matching this rule.

Parameters:

  | bindVariables | If true and a valid binding statement is set the query will be bound to this statement resulting in a UNION query of all possible bindings.

Returns:
  A full SPARQL query or an empty string if this rule does not apply to the statement set via bindToStatement.

\sa bindToStatement

Soprano.Inference.StatementPattern effect | ( |  | self ) |

The effect of a rule is a pattern that repeats variables from the preconditions and thus, identifies the statements that are to be infered from the preconditions.

bool isValid | ( |  | self ) |

Check if a rule is valid.

Returns:
  true if the rule is valid and can be used with the InferenceModel,

false otherwise.

Since:
  2.3

bool match | ( | self, |
|  | Soprano.Statement | statement
| ) |  |  |

Check if a statement matches any of the statement patterns in this rule.

Returns:
  true if statement matches any of the patterns, false otherwise. Be aware that createSparqlQuery() might still return an empty string since it does perform some aditional optimization checks based on the bound statement.

[Soprano.Inference.StatementPattern] preconditions | ( |  | self ) |

The list of preconditions for the rule. Each condition is a StatementPattern which can contain variables. These variables are identified by their name and matched accordingly.

setEffect | ( | self, |
|  | Soprano.Inference.StatementPattern | a0
| ) |  |  |

Set the effect of the rule.