6 from common.range
import type_example_range
7 from utils.attr
import check_attr_type, check_attr_range
8 from core.text_representation
import TextRepresentation
11 """! "Context is a class representing a text string that provides authentic context for the use of the word form managed by the Lemma. This class is to be distinguished from Sense Example." (LMF)
14 """! @brief Constructor.
15 Context instances are owned by Sense.
16 @param speakerID Related speaker identifier. If not provided, default value is None.
17 @return A Context instance.
31 """! @brief Destructor.
32 Release TextRepresentation instances.
35 del text_representation
41 """! @brief Set context type.
42 @param type Type of text representations, in range 'type_example_range' defined in 'common/range.py'.
43 @return Context instance.
45 error_msg =
"Context type value '%s' is not allowed" % type
54 """! @brief Get context type.
55 @return Context attribute 'type'.
60 """! @brief Create a text representation.
61 @return TextRepresentation instance.
63 return TextRepresentation()
66 """! @brief Add a text representation to the context.
67 @param text_representation The TextRepresentation instance to add to the context.
68 @return Context instance.
70 self.text_representation.append(text_representation)
74 """! @brief Get all text representations maintained by the context.
75 @return A Python list of text representations.
80 """! @brief Get the previously registered TextRepresentation instance.
81 @return The last element of Context attribute 'text_representation'.
87 """! @brief Find written forms.
88 This attribute is owned by TextRepresentation.
89 @param language If given, the language to consider to retrieve the written form.
90 @param script_name If given, the script to consider to retrieve the written form.
91 @return A Python list of found TextRepresentation attributes 'writtenForm'.
95 if (language
is None or repr.get_language() == language)
and repr.get_writtenForm()
is not None \
96 and (script_name
is None or repr.get_scriptName() == script_name):
97 found_forms.append(repr.get_writtenForm())
101 """! @brief Get comments.
102 This attribute is owned by TextRepresentation.
103 @return A Python list of found TextRepresentation attributes 'comment'.
107 if repr.get_comment()
is not None:
108 found_comments.append(repr.get_comment())
109 return found_comments
112 """! @brief Set text representation written form, language and script.
113 Attributes 'writtenForm', 'language' and 'scriptName' are owned by TextRepresentation.
114 @param written_form The written form to set.
115 @param language Language of the written form.
116 @param script_name The name of the script used to write the form, e.g. devanagari.
117 @return Context instance.
121 if language
is not None:
122 repr.set_language(language)
123 if script_name
is not None:
124 repr.set_scriptName(script_name)
129 """! @brief Set text representation comment.
130 Attribute 'comment' is owned by TextRepresentation.
131 @param comment The comment to set.
132 @return Context instance.
137 if repr
is None or repr.get_comment()
is not None:
141 repr.set_comment(comment)
145 """! @brief Get related speaker identifier.
146 @return Context attribute 'targets'.
151 """! @brief Get speaker.
152 @return Context private attribute '__speaker'.
def check_attr_type
Check that attribute value is of specified type.
def set_type
Set context type.
def get_speaker
Get speaker.
def get_text_representations
Get all text representations maintained by the context.
def create_text_representation
Create a text representation.
def check_attr_range
Check that attribute value is in specified range.
__speaker
Pointer to an existing Speaker There is zero or one Speaker pointer per Context instance.
def set_written_form
Set text representation written form, language and script.
def set_comment
Set text representation comment.
def get_type
Get context type.
def get_speakerID
Get related speaker identifier.
def get_comments
Get comments.
def add_text_representation
Add a text representation to the context.
def find_written_forms
Find written forms.
text_representation
TextRepresentation instances are owned by Context There is zero to many TextRepresentation instances ...
def get_last_text_representation
Get the previously registered TextRepresentation instance.
"Context is a class representing a text string that provides authentic context for the use of the wor...