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: |
|
---|---|
Returns: | Newly created relation object. |
Return type: | |
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.
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. |
Methods relating to the creation of items in a relation:
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. |
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. |
Methods relating to the traversing of items in a relation:
for item in relation
SRelation supports the Python iterator protocol and therefore one can iterate over the items in a relation.
Methods relating to relation information.
name()
Get the relation’s name.
Returns: | The relation’s name. |
---|---|
Return type: | str |
utterance()
Get the relation’s utterance.
Returns: | The relation’s utterance or None if no utterance was set. |
---|---|
Return type: | SUtterance |
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.