Table Of Contents

Previous topic

SItem

Next topic

SUtterance

SRelation

class speect.SRelation(*args)

SRelation(utt, name)

The Relation class. A Relation is a named list of items. An Utterance can hold an arbitrary number of Relations.

Initialize a newly created relation with the given name, and set it in the given utterance.

Parameters:
  • utt (SUtterance) – The utterance that the newly created relation should be placed in.
  • name (str) – The name of the newly created relation.
Returns:

Newly created relation object.

Return type:

SRelation

Raises :

RuntimeError if Speect was unable to create the utterance.

Note :

Parameter utt may be None.

Note :

A relation with the same name that already exists in the utterance will be deleted.

Note

The SRelation object inherits from SObject in the Speect Engine and can therefore be used in functions/methods that require parameters of type SObject.

Summary

SRelation.append([toShare = None]) Create a new item and append it to the end of the items in the relation.
SRelation.prepend([toShare = None]) Create a new item and prepend it to the beginning of the items in the relation.
SRelation.head() Get the first item in the relation.
SRelation.tail() Get the last item in the relation.
SRelation.name() Get the relation’s name.
SRelation.utterance() Get the relation’s utterance.

Item Creation

Methods relating to the creation of items in a relation:

SRelation.append()

append([toShare = None])

Create a new item and append it to the end of the items in the relation.

Parameters:toShare (SItem) – The item with which the newly created item will share it’s content. If None then a new content will be created for the appended item.
Returns:Newly created and appended item object.
Return type:SItem
Raises :RuntimeError if Speect was unable to create the item.
SRelation.prepend()

prepend([toShare = None])

Create a new item and prepend it to the beginning of the items in the relation.

Parameters:toShare (SItem) – The item with which the newly created item will share it’s content. If None then a new content will be created for the prepended item.
Returns:Newly created and prepended item object.
Return type:SItem
Raises :RuntimeError if Speect was unable to create the item.

Traversing

Methods relating to the traversing of items in a relation:

SRelation.head()

head()

Get the first item in the relation.

Returns:The first item in the relation or None if the relation is empty.
Return type:SItem
SRelation.tail()

tail()

Get the last item in the relation.

Returns:The last item in the relation or None if the relation is empty.
Return type:SItem

Iteration

for item in relation

SRelation supports the Python iterator protocol and therefore one can iterate over the items in a relation.

Information

Methods relating to relation information.

SRelation.name()

name()

Get the relation’s name.

Returns:The relation’s name.
Return type:str
SRelation.utterance()

utterance()

Get the relation’s utterance.

Returns:The relation’s utterance or None if no utterance was set.
Return type:SUtterance

Printing

str(relation)

SRelation supports the Python method __str__() and can therefore be used in the str() built-in function and by the print statement to compute the “informal” string representation of the relation.