KDE 4.9 PyKDE API Reference

- KDE's Python API

# Graph Class Reference

`from PyKDE4.soprano import *`

Namespace: Soprano

## Detailed Description

\class Graph graph.h Soprano/Graph

A simple collection of statements.

A Graph is a simple in-memory collection of Statements. It is supposed to be used where one needs a quick way to exchange or store a small number of statements. It is basically a fancy QSet of statements.

In comparision to Model it does not support queries, it does not use a specific backend plugin, and it is not optimized in any way.

One graph does not represent one named graph, i.e. one context, it can contain Statements with different context nodes.

Author:
  Sebastian Trueg <trueg@kde.org>

Since:
  2.3

## Methods
| __init__ (self)
| __init__ (self, Soprano.Graph a0)
| __init__ (self, [Soprano.Statement] a0)
| addStatement (self, Soprano.Statement statement)
| addStatement (self, Soprano.Node subject, Soprano.Node predicate, Soprano.Node object, Soprano.Node context=Soprano.Node())
| addStatements (self, [Soprano.Statement] statements)
bool | containsAnyStatement (self, Soprano.Statement statement)
bool | containsAnyStatement (self, Soprano.Node subject, Soprano.Node predicate, Soprano.Node object, Soprano.Node context=Soprano.Node())
bool | containsContext (self, Soprano.Node context)
bool | containsStatement (self, Soprano.Statement statement)
bool | containsStatement (self, Soprano.Node subject, Soprano.Node predicate, Soprano.Node object, Soprano.Node context=Soprano.Node())
bool | isEmpty (self)
Soprano.NodeIterator | listContexts (self)
Soprano.StatementIterator | listStatements (self, Soprano.Statement partial=Soprano.Statement())
Soprano.StatementIterator | listStatements (self, Soprano.Node subject, Soprano.Node predicate, Soprano.Node object, Soprano.Node context=Soprano.Node())
Soprano.StatementIterator | listStatementsInContext (self, Soprano.Node context)
bool | operator != (self, Soprano.Graph g)
Soprano.Graph | operator + (self, Soprano.Graph g)
Soprano.Graph | operator + (self, Soprano.Statement s)
Soprano.Graph | operator += (self, Soprano.Graph g)
Soprano.Graph | operator += (self, Soprano.Statement s)
Soprano.Graph | operator - (self, Soprano.Graph a0)
Soprano.Graph | operator - (self, Soprano.Statement s)
Soprano.Graph | operator -= (self, Soprano.Graph g)
Soprano.Graph | operator -= (self, Soprano.Statement s)
Soprano.Graph | operator << (self, Soprano.Graph a0)
Soprano.Graph | operator << (self, Soprano.Statement a0)
bool | operator == (self, Soprano.Graph g)
| removeAllStatements (self, Soprano.Statement statement=Soprano.Statement())
| removeAllStatements (self, Soprano.Node subject, Soprano.Node predicate, Soprano.Node object, Soprano.Node context=Soprano.Node())
| removeContext (self, Soprano.Node a0)
| removeStatement (self, Soprano.Statement statement)
| removeStatement (self, Soprano.Node subject, Soprano.Node predicate, Soprano.Node object, Soprano.Node context=Soprano.Node())
| removeStatements (self, [Soprano.Statement] statements)
int | statementCount (self)
[Soprano.Statement] | toList (self)
QSet | toSet (self)

## Method Documentation

__init__ | ( |  | self ) |

Create a graph from a list of statements.

\sa operator=(const QList<Statement>&)

__init__ | ( | self, |
|  | Soprano.Graph | a0
| ) |  |  |

Create a graph from a list of statements.

\sa operator=(const QList<Statement>&)

__init__ | ( | self, |
|  | [Soprano.Statement] | a0
| ) |  |  |

Create a graph from a list of statements.

\sa operator=(const QList<Statement>&)

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

addStatement | ( | self, |
|  | Soprano.Node | subject,
|  | Soprano.Node | predicate,
|  | Soprano.Node | object,
|  | Soprano.Node | context=Soprano.Node()
| ) |  |  |

addStatements | ( | self, |
|  | [Soprano.Statement] | statements
| ) |  |  |

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

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
| ) |  |  |

bool containsStatement | ( | self, |
|  | Soprano.Node | subject,
|  | Soprano.Node | predicate,
|  | Soprano.Node | object,
|  | Soprano.Node | context=Soprano.Node()
| ) |  |  |

bool isEmpty | ( |  | self ) |

Returns:
  true if the Graph doesn't contains any Statement.

Soprano.NodeIterator listContexts | ( |  | self ) |

List all contexts in the graph, 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=Soprano.Statement()
| ) |  |  |

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.

Returns:
  An iterator for all the matched Statements, 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()
| ) |  |  |

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.

Returns:
  An iterator for all the matched Statements, 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.

bool operator != | ( | self, |
|  | Soprano.Graph | g
| ) |  |  |

Comparision operator.

Returns:
  true if this graph contains a statement

g does not contain or the other way around, false otherwise.

Soprano.Graph operator + | ( | self, |
|  | Soprano.Graph | g
| ) |  |  |

Returns a graph containing all statements from this graph and from s.

Soprano.Graph operator + | ( | self, |
|  | Soprano.Statement | s
| ) |  |  |

Returns a graph containing all statements from this graph and from s.

Soprano.Graph operator += | ( | self, |
|  | Soprano.Graph | g
| ) |  |  |

Inserts the statement s into this graph and returns a reference to this graph.

Soprano.Graph operator += | ( | self, |
|  | Soprano.Statement | s
| ) |  |  |

Inserts the statement s into this graph and returns a reference to this graph.

Soprano.Graph operator - | ( | self, |
|  | Soprano.Graph | a0
| ) |  |  |

Substracts s from this graph and returns a reference to this graph.

Soprano.Graph operator - | ( | self, |
|  | Soprano.Statement | s
| ) |  |  |

Substracts s from this graph and returns a reference to this graph.

Soprano.Graph operator -= | ( | self, |
|  | Soprano.Graph | g
| ) |  |  |

Removes the statement s from this graph and returns a reference to this graph.

Soprano.Graph operator -= | ( | self, |
|  | Soprano.Statement | s
| ) |  |  |

Removes the statement s from this graph and returns a reference to this graph.

Soprano.Graph operator << | ( | self, |
|  | Soprano.Graph | a0
| ) |  |  |

\sa operator+=

Soprano.Graph operator << | ( | self, |
|  | Soprano.Statement | a0
| ) |  |  |

\sa operator+=

bool operator == | ( | self, |
|  | Soprano.Graph | g
| ) |  |  |

Comparision operator.

Returns:
  true if this graph and g contain the same statements, false otherwise.

removeAllStatements | ( | self, |
|  | Soprano.Statement | statement=Soprano.Statement()
| ) |  |  |

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.

removeAllStatements | ( | 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.

removeContext | ( | self, |
|  | Soprano.Node | a0
| ) |  |  |

Convenience method that removes all statements in the context.

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

removeStatement | ( | self, |
|  | Soprano.Node | subject,
|  | Soprano.Node | predicate,
|  | Soprano.Node | object,
|  | Soprano.Node | context=Soprano.Node()
| ) |  |  |

removeStatements | ( | self, |
|  | [Soprano.Statement] | statements
| ) |  |  |

Convenience method which removes all %statements in statements.

int statementCount | ( |  | self ) |

The number of statements stored in this Graph.

Returns:
  The size of the Graph.

[Soprano.Statement] toList | ( |  | self ) |

Convert the Graph into a list

QSet toSet | ( |  | self ) |

Convert the Graph into a set