Python LMF library
 All Classes Namespaces Files Functions Variables
text_representation.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """! @package core
4 """
5 
6 from representation import Representation
7 from utils.attr import check_attr_type
8 
9 class TextRepresentation(Representation):
10  """! "Text Representation is a class representing the textual content of definition or statement. When there is more than one variant orthography, the Text Representation instance contains a Unicode string representing the textual content as well as unique attribute-value pairs that describe the specific language, script and orthography." (LMF)
11  """
12  def __init__(self):
13  """! @brief Constructor.
14  TextRepresentation instances are owned by Definition and Statement.
15  @return A TextRepresentation instance.
16  """
17  # Initialize Representation attributes: 'comment', 'writtenForm', 'language' and 'scriptName'
18  self.__new__()
19  self.font = None
20 
21  def __del__(self):
22  """! @brief Destructor.
23  """
24  pass
25 
26  def set_comment(self, comment):
27  """! @brief Set written form comment.
28  @param comment Comment about the written form.
29  @return TextRepresentation instance.
30  """
31  error_msg = "Written form comment value '%s' is not allowed" % comment
32  check_attr_type(comment, [str, unicode], error_msg)
33  self.comment = comment
34  return self
35 
36  def get_comment(self):
37  """! @brief Get written form comment.
38  @return Representation attribute 'comment'.
39  """
40  return self.comment
41 
42  def set_writtenForm(self, written_form, language=None):
43  """! @brief Set written form and language.
44  @param written_form The written form to set.
45  @param language Language used for the written form.
46  @return TextRepresentation instance.
47  """
48  error_msg = "Written form value '%s' is not allowed" % written_form
49  check_attr_type(written_form, [str, unicode], error_msg)
50  self.writtenForm = written_form
51  if language is not None:
52  self.set_language(language)
53  return self
54 
55  def get_writtenForm(self, language=None):
56  """! @brief Get written form.
57  @param language If this argument is given, get written form only if written in this language.
58  @return The filtered Representation attribute 'writtenForm'.
59  """
60  if language is None or language == self.get_language():
61  return self.writtenForm
62 
63  def set_language(self, language):
64  """! @brief Set language used for written form.
65  @param language Language used for the written form.
66  @return TextRepresentation instance.
67  """
68  error_msg = "Language value '%s' is not allowed" % language
69  check_attr_type(language, [str, unicode], error_msg)
70  self.language = language
71  return self
72 
73  def get_language(self):
74  """! @brief Get language used for written form.
75  @return Representation attribute 'language'.
76  """
77  return self.language
78 
79  def set_scriptName(self, script_name):
80  """! @brief Set script name.
81  @param script_name The script name to set.
82  @return TextRepresentation instance.
83  """
84  error_msg = "Script name value '%s' is not allowed" % script_name
85  check_attr_type(script_name, [str, unicode], error_msg)
86  self.scriptName = script_name
87  return self
88 
89  def get_scriptName(self):
90  """! @brief Get script name.
91  @return Representation attribute 'scriptName'.
92  """
93  return self.scriptName
def check_attr_type
Check that attribute value is of specified type.
Definition: attr.py:9
"Text Representation is a class representing the textual content of definition or statement...