Python LMF library
 All Classes Namespaces Files Functions Variables
word_form.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """! @package morphology
4 """
5 
6 from core.form import Form
7 from core.form_representation import FormRepresentation
8 from utils.attr import check_attr_range
9 from common.range import person_range, anymacy_range, grammaticalNumber_range, clusivity_range
10 from config.mdf import pd_person, pd_anymacy, pd_grammaticalNumber, pd_clusivity
11 
12 class WordForm(Form):
13  """! "Word Form is a Form subclass representing a form that a lexeme can take when used in a sentence or a phrase." (LMF)
14  """
15  def __init__(self):
16  """! @brief Constructor.
17  WordForm instances are owned by LexicalEntry.
18  @return A WordForm instance.
19  """
20  # Initialize Form attribute 'form_representation'
21  self.__new__()
22  self.grammaticalNumber = None
23  self.grammaticalGender = None
24  self.person = None
25  self.anymacy = None
26  self.clusivity = None
27  self.tense = None
28  self.case = None
29  self.degree = None
30  self.voice = None
31  self.verbFormMood = None
32 
33  def __del__(self):
34  """! @brief Destructor.
35  """
36  pass
37 
39  """! @brief Create a form representation.
40  @return FormRepresentation instance.
41  """
42  return FormRepresentation()
43 
44  def add_form_representation(self, form_representation):
45  """! @brief Add a form representation to the word form.
46  @param form_representation The FormRepresentation instance to add to the word form.
47  @return WordForm instance.
48  """
49  self.form_representation.append(form_representation)
50  return self
51 
53  """! @brief Get all form representations maintained by the word form.
54  @return A Python list of form representations.
55  """
56  return self.form_representation
57 
58  def set_written_form(self, written_form, script_name=None):
59  """! @brief Set written form.
60  This attribute is owned by Representation.
61  @param written_form Written form.
62  @param script_name Script used for the written form.
63  @return WordForm instance.
64  """
65  form_representation = None
66  # Set first FormRepresentation instance that has no written form
67  for repr in self.get_form_representations():
68  if repr.get_writtenForm() is None:
69  form_representation = repr
70  break
71  if form_representation is None:
72  # Create a FormRepresentation instance
73  form_representation = self.create_form_representation()
74  self.add_form_representation(form_representation)
75  form_representation.set_writtenForm(written_form, script_name)
76  return self
77 
78  def get_written_forms(self, script_name=None):
79  """! @brief Get all written forms.
80  This attribute is owned by Representation.
81  @param script_name If this argument is given, get written form only if written using this script.
82  @return A Python list of FormRepresentation attributes 'writtenForm'.
83  """
84  written_forms = []
85  for repr in self.get_form_representations():
86  if repr.get_writtenForm(script_name) is not None:
87  written_forms.append(repr.get_writtenForm(script_name))
88  return written_forms
89 
90  def set_variant_form(self, variant_form):
91  """! @brief Set variant form.
92  This attribute is owned by FormRepresentation.
93  @param variant_form Variant form.
94  @return WordForm instance.
95  """
96  form_representation = None
97  # Set first FormRepresentation instance that has no variant form
98  for repr in self.get_form_representations():
99  if repr.get_variantForm() is None:
100  form_representation = repr
101  break
102  if form_representation is None:
103  # Create a FormRepresentation instance
104  form_representation = self.create_form_representation()
105  self.add_form_representation(form_representation)
106  form_representation.set_variantForm(variant_form)
107  return self
108 
109  def get_variant_forms(self):
110  """! @brief Get all variant forms.
111  This attribute is owned by FormRepresentation.
112  @return A Python list of FormRepresentation attributes 'variantForm'.
113  """
114  variant_forms = []
115  for repr in self.get_form_representations():
116  if repr.get_variantForm() is not None:
117  variant_forms.append(repr.get_variantForm())
118  return variant_forms
119 
120  def set_person(self, person):
121  """! @brief Set grammatical person.
122  @param person The grammatical person to set.
123  @return WordForm instance.
124  """
125  error_msg = "Person value '%s' is not allowed" % str(person)
126  # Check range of person value (also try with converted value from MDF to LMF)
127  value = check_attr_range(person, person_range, error_msg, mapping=pd_person)
128  self.person = value
129  return self
130 
131  def get_person(self):
132  """! @brief Get grammatical person.
133  @return WordForm attribute 'person'.
134  """
135  return self.person
136 
137  def set_anymacy(self, anymacy):
138  """! @brief Set grammatical anymacy.
139  @param anymacy The grammatical anymacy to set.
140  @return WordForm instance.
141  """
142  error_msg = "Anymacy value '%s' is not allowed" % str(anymacy)
143  # Check range of anymacy value (also try with converted value from MDF to LMF)
144  value = check_attr_range(anymacy, anymacy_range, error_msg, mapping=pd_anymacy)
145  self.anymacy = value
146  return self
147 
148  def get_anymacy(self):
149  """! @brief Get anymacy.
150  @return WordForm attribute 'anymacy'.
151  """
152  return self.anymacy
153 
154  def set_grammaticalNumber(self, grammatical_number):
155  """! @brief Set grammatical number.
156  @param grammatical_number The grammatical number to set.
157  @return WordForm instance.
158  """
159  error_msg = "Grammatical number value '%s' is not allowed" % grammatical_number
160  # Check range of grammatical number value (also try with converted value from MDF to LMF)
161  value = check_attr_range(grammatical_number, grammaticalNumber_range, error_msg, mapping=pd_grammaticalNumber)
162  self.grammaticalNumber = value
163  return self
164 
166  """! @brief Get grammatical number.
167  @return WordForm attribute 'grammaticalNumber'.
168  """
169  return self.grammaticalNumber
170 
171  def set_clusivity(self, clusivity):
172  """! @brief Set grammatical clusivity.
173  @param clusivity The grammatical clusivity to set.
174  @return WordForm instance.
175  """
176  error_msg = "Clusivity value '%s' is not allowed" % clusivity
177  # Check range of clusivity value (also try with converted value from MDF to LMF)
178  value = check_attr_range(clusivity, clusivity_range, error_msg, mapping=pd_clusivity)
179  self.clusivity = value
180  return self
181 
182  def get_clusivity(self):
183  """! @brief Get grammatical clusivity.
184  @return WordForm attribute 'clusivity'.
185  """
186  return self.clusivity
def check_attr_range
Check that attribute value is in specified range.
Definition: attr.py:23
def get_written_forms
Get all written forms.
Definition: word_form.py:78
def set_anymacy
Set grammatical anymacy.
Definition: word_form.py:137
"Word Form is a Form subclass representing a form that a lexeme can take when used in a sentence or a...
Definition: word_form.py:12
def create_form_representation
Create a form representation.
Definition: word_form.py:38
def set_grammaticalNumber
Set grammatical number.
Definition: word_form.py:154
def get_grammaticalNumber
Get grammatical number.
Definition: word_form.py:165
def set_clusivity
Set grammatical clusivity.
Definition: word_form.py:171
def set_person
Set grammatical person.
Definition: word_form.py:120
def get_clusivity
Get grammatical clusivity.
Definition: word_form.py:182
def get_variant_forms
Get all variant forms.
Definition: word_form.py:109
def get_person
Get grammatical person.
Definition: word_form.py:131
def get_form_representations
Get all form representations maintained by the word form.
Definition: word_form.py:52
def add_form_representation
Add a form representation to the word form.
Definition: word_form.py:44