Python LMF library
 All Classes Namespaces Files Functions Variables
lexical_entry.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """! @package core
4 """
5 
6 from morphology.lemma import Lemma
7 from morphology.related_form import RelatedForm
8 from morphology.word_form import WordForm
9 from common.range import partOfSpeech_range
10 from config.mdf import ps_partOfSpeech
11 from utils.attr import check_attr_type, check_attr_range
12 from core.sense import Sense
13 from morphology.list_of_components import ListOfComponents
14 
15 class LexicalEntry():
16  """! "Lexical Entry is a class representing a lexeme in a given language and is a container for managing the Form and Sense classes. A Lexical Entry instance can contain one to many different forms and can have from zero to many different senses." (LMF)
17  """
18  def __init__(self, id='0'):
19  """! @brief Constructor.
20  LexicalEntry instances are owned by Lexicon.
21  @param id Unique IDentifier. If not provided, default value is 0.
22  @return A LexicalEntry instance.
23  """
24  self.homonymNumber = None
25  self.status = None
26  self.date = None
27  self.partOfSpeech = None
28  self.independentWord = None
29  self.bibliography = None
30  ## UID is managed at the Lexicon level
31  self.id = id
32  ## Sense instances are owned by LexicalEntry
33  # There is zero to many Sense instances per LexicalEntry
34  self.sense = []
35  ## Lemma instance is owned by LexicalEntry
36  # There is one Lemma instance by LexicalEntry instance
37  self.lemma = None # lemmatized form
38  ## RelatedForm instances are owned by LexicalEntry
39  # There is zero to many RelatedForm instances per LexicalEntry
40  self.related_form = []
41  ## WordForm instances are owned by LexicalEntry
42  # There is zero to many WordForm instances per LexicalEntry
43  self.word_form = []
44  ## Stem instances are owned by LexicalEntry
45  # There is zero to many Stem instances per LexicalEntry
46  self.stem = [] # ordered list
47  ## ListOfComponents instance is owned by LexicalEntry
48  # There is zero or one ListOfComponents instance per LexicalEntry
49  self.list_of_components = None
50  # Speaker id
51  self.targets = None
52  ## Pointer to an existing Speaker
53  # There is one Speaker pointer per LexicalEntry instance
54  self.__speaker = None
55 
56  def __del__(self):
57  """! @brief Destructor.
58  Release Sense, Lemma, RelatedForm, WordForm, Stem, ListOfComponents instances.
59  """
60  for sense in self.sense:
61  del sense
62  del self.sense[:]
63  for related_form in self.related_form:
64  del related_form
65  del self.related_form[:]
66  for word_form in self.word_form:
67  del word_form
68  del self.word_form[:]
69  for stem in self.stem:
70  del stem
71  del self.stem[:]
72  if self.lemma is not None:
73  del self.lemma
74  if self.list_of_components is not None:
75  del self.list_of_components
76  # Decrement the reference count on pointed objects
77  self.__speaker = None
78 
79  def set_partOfSpeech(self, part_of_speech, range=partOfSpeech_range, mapping=ps_partOfSpeech):
80  """! @brief Set grammatical category.
81  @param part_of_speech The grammatical category to set.
82  @param range A Python set giving all possible values of part of speech LMF attribute.
83  @param mapping A Python dictionary giving the mapping between MDF and LMF values.
84  @return LexicalEntry instance.
85  """
86  error_msg = "Part of speech value '%s' encountered for lexeme '%s' is not allowed" % (part_of_speech.encode('utf8'), self.get_lexeme().encode('utf8'))
87  # Check part of speech type
88  check_attr_type(part_of_speech, [str, unicode], error_msg)
89  # Check range of part of speech value (also try with converted value from MDF to LMF)
90  value = check_attr_range(part_of_speech.encode('utf8'), range, error_msg, mapping)
91  self.partOfSpeech = value
92  return self
93 
94  def get_partOfSpeech(self):
95  """! @brief Get grammatical category.
96  @return LexicalEntry attribute 'partOfSpeech'.
97  """
98  return self.partOfSpeech
99 
100  def set_status(self, status):
101  """! @brief Set lexical entry status.
102  @param status The status to set.
103  @return LexicalEntry instance.
104  """
105  self.status = status
106  return self
107 
108  def get_status(self):
109  """! @brief Get lexical entry status.
110  @return LexicalEntry attribute 'status'.
111  """
112  return self.status
113 
114  def set_date(self, date):
115  """! @brief Set lexical entry date.
116  @param status The date to set.
117  @return LexicalEntry instance.
118  """
119  self.date = date
120  return self
121 
122  def get_date(self):
123  """! @brief Get lexical entry date.
124  @return LexicalEntry attribute 'date'.
125  """
126  return self.date
127 
128  def set_homonymNumber(self, homonym_number):
129  """! @brief Set lexical entry homonym number.
130  @param homonym_number The homonym number to set.
131  @return LexicalEntry instance.
132  """
133  self.homonymNumber = homonym_number
134  return self
135 
136  def get_homonymNumber(self):
137  """! @brief Get lexical entry homonym number.
138  @return LexicalEntry attribute 'homonymNumber'.
139  """
140  return self.homonymNumber
141 
142  def set_bibliography(self, bibliography):
143  """! @brief Set lexical entry bibliography.
144  @param bibliography The bibliography to set.
145  @return LexicalEntry instance.
146  """
147  self.bibliography = bibliography
148  return self
149 
150  def get_bibliography(self):
151  """! @brief Get lexical entry bibliography.
152  @return LexicalEntry attribute 'bibliography'.
153  """
154  return self.bibliography
155 
156  def set_independentWord(self, independent_word):
157  """! @brief Set lexical entry independent word indication.
158  @param independent_word The independent word indication to set.
159  @return LexicalEntry instance.
160  """
161  error_msg = "Independent word '%s' encountered for lexeme '%s' is not allowed" % (str(independent_word), self.get_lexeme())
162  check_attr_type(independent_word, bool, error_msg)
163  self.independentWord = independent_word
164  return self
165 
167  """! @brief Get lexical entry independent word indication.
168  @return LexicalEntry attribute 'independentWord'.
169  """
170  return self.independentWord
171 
172  def get_id(self):
173  """! @brief Get Unique IDentifier.
174  @return LexicalEntry attribute 'id' followed by the homonym number.
175  """
176  homonymNumber = self.get_homonymNumber()
177  if homonymNumber is None:
178  homonymNumber = 1
179  return self.id + str(homonymNumber)
180 
181  def set_lexeme(self, lexeme):
182  """! @brief Set lexeme.
183  Attribute 'lexeme' is owned by Lemma.
184  @param lexeme The lexeme to set.
185  @return LexicalEntry instance.
186  """
187  # Create a Lemma instance if not yet created
188  if self.lemma is None:
189  self.lemma = Lemma()
190  self.lemma.set_lexeme(lexeme)
191  return self
192 
193  def get_lexeme(self):
194  """! @brief Get lexeme.
195  Attribute 'lexeme' is owned by Lemma.
196  @return Lemma attribute 'lexeme' if any.
197  """
198  if self.lemma is not None:
199  return self.lemma.get_lexeme()
200 
201  def create_related_form(self, lexeme, semantic_relation):
202  """! @brief Create a related form.
203  @param lexeme Related lexeme.
204  @param semantic_relation The semantic relation existing between this lexical entry and the related lexeme to create.
205  @return RelatedForm instance.
206  """
207  return RelatedForm(lexeme).set_semanticRelation(semantic_relation)
208 
209  def add_related_form(self, related_form):
210  """! @brief Add a related form to the lexical entry.
211  @param related_form The RelatedForm instance to add to the lexical entry.
212  @return LexicalEntry instance.
213  """
214  self.related_form.append(related_form)
215  return self
216 
217  def create_and_add_related_form(self, lexeme, semantic_relation):
218  """! @brief Create and add a related form to the lexical entry.
219  @param lexeme Related lexeme.
220  @param semantic_relation The semantic relation existing between this lexical entry and the related lexeme to create.
221  @return LexicalEntry instance.
222  """
223  # Check if this related form already exists
224  for related_form in self.get_related_forms():
225  if related_form.get_lexeme() == lexeme:
226  return self
227  self.related_form.append(RelatedForm(lexeme).set_semanticRelation(semantic_relation))
228  return self
229 
230  def find_related_forms(self, semantic_relation):
231  """! @brief Find related lexemes.
232  This attribute is owned by RelatedForm.
233  @param semantic_relation The semantic relation to consider to retrieve the related form.
234  @return A Python list of found RelatedForm attributes 'targets'.
235  """
236  found_lexemes = []
237  for related_form in self.get_related_forms():
238  if related_form.get_semanticRelation() == semantic_relation:
239  found_lexemes.append(related_form.get_lexeme())
240  return found_lexemes
241 
242  def get_related_forms(self, semantic_relation=None):
243  """! @brief Get all related forms maintained by the lexical entry.
244  @param semantic_relation The semantic relation to consider to retrieve the related forms.
245  @return A Python set of related forms.
246  """
247  if semantic_relation is None:
248  return self.related_form
249  found_forms = []
250  for related_form in self.related_form:
251  if related_form.get_semanticRelation() == semantic_relation:
252  found_forms.append(related_form)
253  return found_forms
254 
255  def get_last_related_form(self, semantic_relation=None):
256  """! @brief Get the previously registered related form.
257  @param semantic_relation The semantic relation to consider to retrieve the last related form.
258  @return The last element of LexicalEntry attribute 'related_form' that matches with semantic relation if provided.
259  """
260  if len(self.get_related_forms(semantic_relation)) >= 1:
261  return self.get_related_forms()[-1]
262 
264  """! @brief Get all form representations maintained by the lemma.
265  Attribute 'form_representation' is owned by Lemma.
266  @return Lemma attribute 'form_representation' if any.
267  """
268  if self.lemma is not None:
269  return self.lemma.get_form_representations()
270 
271  def set_variant_form(self, variant_form, type="unspecified"):
272  """! @brief Set variant form and type.
273  Attributes 'variantForm' and 'type' are owned by FormRepresentation, which is owned by Lemma.
274  @param variant_form Variant form.
275  @param type Type of variant, in range 'type_variant_range' defined in 'common/range.py'.
276  @return LexicalEntry instance.
277  """
278  # Create a Lemma instance if not yet created
279  if self.lemma is None:
280  self.lemma = Lemma()
281  self.lemma.set_variant_form(variant_form, type)
282  return self
283 
284  def get_variant_forms(self, type="unspecified"):
285  """! @brief Get all variant forms of specified type.
286  Attribute 'variantForm' is owned by FormRepresentation, which is owned by Lemma.
287  @return A Python list of FormRepresentation attributes 'variantForm' if type matches.
288  """
289  if self.lemma is not None:
290  return self.lemma.get_variant_forms(type)
291 
292  def set_variant_comment(self, comment, language=None):
293  """! @brief Set variant comment and language.
294  Attributes 'comment' and 'language' are owned by FormRepresentation, which is owned by Lemma.
295  @param comment Variant comment.
296  @param language Language of comment.
297  @return LexicalEntry instance.
298  """
299  # Create a Lemma instance if not yet created
300  if self.lemma is None:
301  self.lemma = Lemma()
302  self.lemma.set_variant_comment(comment, language)
303  return self
304 
305  def set_tone(self, tone):
306  """! @brief Set tone.
307  Attribute 'tone' is owned by FormRepresentation, which is owned by Lemma.
308  @param tone The tone to set.
309  @return LexicalEntry instance.
310  """
311  # Create a Lemma instance if not yet created
312  if self.lemma is None:
313  self.lemma = Lemma()
314  self.lemma.set_tone(tone)
315  return self
316 
317  def get_tones(self):
318  """! @brief Get all tones.
319  Attribute 'tone' is owned by FormRepresentation, which is owned by Lemma.
320  @return A Python list of FormRepresentation attributes 'tone' if any.
321  """
322  if self.lemma is not None:
323  return self.lemma.get_tones()
324 
325  def set_geographical_variant(self, geographical_variant):
326  """! @brief Set geographical variant.
327  Attribute 'geographicalVariant' is owned by FormRepresentation, which is owned by Lemma.
328  @param geographical_variant The geographical variant to set.
329  @return LexicalEntry instance.
330  """
331  # Create a Lemma instance if not yet created
332  if self.lemma is None:
333  self.lemma = Lemma()
334  self.lemma.set_geographical_variant(geographical_variant)
335  return self
336 
337  def set_phonetic_form(self, phonetic_form, script_name=None):
338  """! @brief Set phonetic form.
339  Attribute 'phoneticForm' is owned by FormRepresentation, which is owned by Lemma.
340  @param phonetic_form The phonetic form to set.
341  @param script_name The name of the script used to write the phonetic form, e.g. pinyin.
342  @return LexicalEntry instance.
343  """
344  # Create a Lemma instance if not yet created
345  if self.lemma is None:
346  self.lemma = Lemma()
347  self.lemma.set_phonetic_form(phonetic_form, script_name)
348  return self
349 
350  def get_phonetic_forms(self, script_name=None):
351  """! @brief Get all phonetic forms.
352  Attribute 'phoneticForm' is owned by FormRepresentation, which is owned by Lemma.
353  @param script_name If provided, get only phonetic forms that are written using this script.
354  @return A Python list of FormRepresentation attributes 'phoneticForm' if any.
355  """
356  if self.lemma is not None:
357  return self.lemma.get_phonetic_forms(script_name)
358 
359  def set_contextual_variation(self, contextual_variation):
360  """! @brief Set contextual variation.
361  Attribute 'contextualVariation' is owned by FormRepresentation, which is owned by Lemma.
362  @param contextual_variation The contextual variation to set.
363  @return LexicalEntry instance.
364  """
365  # Create a Lemma instance if not yet created
366  if self.lemma is None:
367  self.lemma = Lemma()
368  self.lemma.set_contextual_variation(contextual_variation)
369  return self
370 
372  """! @brief Get all contextual variations.
373  Attribute 'contextualVariation' is owned by FormRepresentation, which is owned by Lemma.
374  @return A Python list of FormRepresentation attributes 'contextualVariation' if any.
375  """
376  if self.lemma is not None:
377  return self.lemma.get_contextual_variations()
378 
379  def set_spelling_variant(self, spelling_variant):
380  """! @brief Set spelling variant.
381  Attribute 'spellingVariant' is owned by FormRepresentation, which is owned by Lemma.
382  @param spelling_variant The spelling variant to set.
383  @return LexicalEntry instance.
384  """
385  # Create a Lemma instance if not yet created
386  if self.lemma is None:
387  self.lemma = Lemma()
388  self.lemma.set_spelling_variant(spelling_variant)
389  return self
390 
392  """! @brief Get all spelling variants.
393  Attribute 'spellingVariant' is owned by FormRepresentation, which is owned by Lemma.
394  @return A Python list of FormRepresentation attributes 'spellingVariant' if any.
395  """
396  if self.lemma is not None:
397  return self.lemma.get_spelling_variants()
398 
399  def set_citation_form(self, citation_form, script_name=None):
400  """! @brief Set citation form.
401  Attribute 'citationForm' is owned by FormRepresentation, which is owned by Lemma.
402  @param citation_form The citation form to set.
403  @param script_name The name of the script used to write the citation form, e.g. devanagari.
404  @return LexicalEntry instance.
405  """
406  # Create a Lemma instance if not yet created
407  if self.lemma is None:
408  self.lemma = Lemma()
409  self.lemma.set_citation_form(citation_form, script_name)
410  return self
411 
412  def get_citation_forms(self, script_name=None):
413  """! @brief Get all citation forms.
414  Attribute 'citationForm' is owned by FormRepresentation, which is owned by Lemma.
415  @param script_name If provided, get only citation forms that are written using this script.
416  @return A Python list of FormRepresentation attributes 'citationForm' if any.
417  """
418  if self.lemma is not None:
419  return self.lemma.get_citation_forms(script_name)
420 
421  def set_dialect(self, dialect):
422  """! @brief Set dialect.
423  Attribute 'dialect' is owned by FormRepresentation, which is owned by Lemma.
424  @param dialect The dialect to set.
425  @return LexicalEntry instance.
426  """
427  # Create a Lemma instance if not yet created
428  if self.lemma is None:
429  self.lemma = Lemma()
430  self.lemma.set_dialect(dialect)
431  return self
432 
433  def set_transliteration(self, transliteration):
434  """! @brief Set transliteration.
435  Attribute 'transliteration' is owned by FormRepresentation, which is owned by Lemma.
436  @param transliteration The transliteration to set.
437  @return LexicalEntry instance.
438  """
439  # Create a Lemma instance if not yet created
440  if self.lemma is None:
441  self.lemma = Lemma()
442  self.lemma.set_transliteration(transliteration)
443  return self
444 
446  """! @brief Get all transliterations.
447  Attribute 'transliteration' is owned by FormRepresentation, which is owned by Lemma.
448  @return A Python list of FormRepresentation attributes 'transliteration' if any.
449  """
450  if self.lemma is not None:
451  return self.lemma.get_transliterations()
452 
453  def set_script_name(self, script_name):
454  """! @brief Set script name.
455  Attribute 'scriptName' is owned by FormRepresentation, which is owned by Lemma.
456  @param script_name The script name to set.
457  @return LexicalEntry instance.
458  """
459  # Create a Lemma instance if not yet created
460  if self.lemma is None:
461  self.lemma = Lemma()
462  self.lemma.set_script_name(script_name)
463  return self
464 
465  def create_sense(self, id=0):
466  """! @brief Create a sense.
467  @param id Identifier.
468  @return Sense instance.
469  """
470  return Sense(id)
471 
472  def add_sense(self, sense):
473  """! @brief Add a sense to the lexical entry.
474  @param sense The Sense instance to add to the lexical entry.
475  @return LexicalEntry instance.
476  """
477  self.sense.append(sense)
478  return self
479 
480  def create_and_add_sense(self, sense_number):
481  """! @brief Create and add a sense to the lexical entry.
482  @param sense_number Number of the sense to add.
483  @return LexicalEntry instance.
484  """
485  id = self.get_id() + "_" + str(sense_number)
486  self.add_sense(self.create_sense(id).set_senseNumber(sense_number))
487  return self
488 
489  def get_senses(self):
490  """! @brief Get all senses maintained by the lexical entry.
491  @return LexicalEntry attribute 'sense'.
492  """
493  return self.sense
494 
495  def get_last_sense(self):
496  """! @brief Get the previously registered sense.
497  @return The last element of LexicalEntry attribute 'sense'.
498  """
499  if len(self.get_senses()) >= 1:
500  return self.get_senses()[-1]
501 
502  def set_definition(self, definition, language=None):
503  """! @brief Set definition and language.
504  Attributes 'definition' and 'language' are owned by Definition, which is owned by Sense.
505  @param definition Definition.
506  @param language Language of definition.
507  @return LexicalEntry instance.
508  """
509  # Get the last Sense instance if any
510  sense = self.get_last_sense()
511  # If there is no Sense instance, create and add one
512  if sense is None:
513  sense = self.create_sense()
514  self.add_sense(sense)
515  sense.set_definition(definition, language)
516  return self
517 
518  def set_gloss(self, gloss, language=None):
519  """! @brief Set gloss and language.
520  Attributes 'gloss' and 'language' are owned by Definition, which is owned by Sense.
521  @param gloss Gloss.
522  @param language Language of gloss.
523  @return LexicalEntry instance.
524  """
525  # Get the last Sense instance if any
526  sense = self.get_last_sense()
527  # If there is no Sense instances, create and add one
528  if sense is None:
529  sense = self.create_sense()
530  self.add_sense(sense)
531  sense.set_gloss(gloss, language)
532  return self
533 
534  def set_note(self, note, type=None, language=None):
535  """! @brief Set note, type and language.
536  Attributes 'note', 'noteType' and 'language' are owned by Statement, which owned by Definition, itself owned by Sense.
537  @param note Note to set.
538  @param type Type of the note.
539  @param language Language of the note.
540  @return LexicalEntry instance.
541  """
542  # Get the last Sense instance if any
543  sense = self.get_last_sense()
544  # If there is no Sense instances, create and add one
545  if sense is None:
546  sense = self.create_sense()
547  self.add_sense(sense)
548  sense.set_note(note, type, language)
549  return self
550 
551  def find_notes(self, type, language=None):
552  """! @brief Find notes.
553  This attribute is owned by Statement, which owned by Definition, itself owned by Sense.
554  @param type Type of the note to consider to retrieve the note.
555  @param language If this argument is given, find note only if written in this language.
556  @return A Python list of found Statement attributes 'notes'.
557  """
558  found_notes = []
559  for sense in self.get_senses():
560  found_notes += sense.find_notes(type, language)
561  return found_notes
562 
563  def set_usage_note(self, usage_note, language=None):
564  """! @brief Set usage note and language.
565  Attributes 'usageNote' and 'language' are owned by Statement, which owned by Definition, itself owned by Sense.
566  @param usage_note Usage note to set.
567  @param language Language of the usage note.
568  @return LexicalEntry instance.
569  """
570  # Get the last Sense instance if any
571  sense = self.get_last_sense()
572  # If there is no Sense instances, create and add one
573  if sense is None:
574  sense = self.create_sense()
575  self.add_sense(sense)
576  sense.set_usage_note(usage_note, language)
577  return self
578 
579  def set_encyclopedic_information(self, encyclopedic_information, language=None):
580  """! @brief Set encyclopedic information and language.
581  Attributes 'encyclopedicInformation' and 'language' are owned by Statement, which owned by Definition, itself owned by Sense.
582  @param encyclopedic_information Encyclopedic information to set.
583  @param language Language of the encyclopedic information.
584  @return LexicalEntry instance.
585  """
586  # Get the last Sense instance if any
587  sense = self.get_last_sense()
588  # If there is no Sense instances, create and add one
589  if sense is None:
590  sense = self.create_sense()
591  self.add_sense(sense)
592  sense.set_encyclopedic_information(encyclopedic_information, language)
593  return self
594 
595  def set_restriction(self, restriction, language=None):
596  """! @brief Set restriction and language.
597  Attributes 'restriction' and 'language' are owned by Statement, which owned by Definition, itself owned by Sense.
598  @param restriction Restriction to set.
599  @param language Language of the restriction.
600  @return LexicalEntry instance.
601  """
602  # Get the last Sense instance if any
603  sense = self.get_last_sense()
604  # If there is no Sense instances, create and add one
605  if sense is None:
606  sense = self.create_sense()
607  self.add_sense(sense)
608  sense.set_restriction(restriction, language)
609  return self
610 
611  def set_borrowed_word(self, borrowed_word):
612  """! @brief Set source language (in English).
613  Attribute 'borrowedWord' is owned by Statement, which is owned by Definition, itself owned by Sense.
614  @param borrowed_word Source language.
615  @return LexicalEntry instance.
616  """
617  # Get the last Sense instance if any
618  sense = self.get_last_sense()
619  # If there is no Sense instance, create and add one
620  if sense is None:
621  sense = self.create_sense()
622  self.add_sense(sense)
623  sense.set_borrowed_word(borrowed_word)
624  return self
625 
626  def get_borrowed_word(self):
627  """! @brief Get source language (in English).
628  This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
629  @return Statement attribute 'borrowedWord'.
630  """
631  # Get the last Sense instance if any
632  sense = self.get_last_sense()
633  # If there is a Sense instance, get source language
634  if sense is not None:
635  return sense.get_borrowed_word()
636 
637  def set_written_form(self, written_form):
638  """! @brief Set loan word.
639  Attribute 'writtenForm' is owned by Statement, which is owned by Definition, itself owned by Sense.
640  @param written_form Loan word.
641  @return LexicalEntry instance.
642  """
643  # Get the last Sense instance if any
644  sense = self.get_last_sense()
645  # If there is no Sense instance, create and add one
646  if sense is None:
647  sense = self.create_sense()
648  self.add_sense(sense)
649  sense.set_written_form(written_form)
650  return self
651 
652  def get_written_form(self):
653  """! @brief Get loan word.
654  This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
655  @return Statement attribute 'writtenForm'.
656  """
657  # Get the last Sense instance if any
658  sense = self.get_last_sense()
659  # If there is a Sense instance, get loan word
660  if sense is not None:
661  return sense.get_written_form()
662 
663  def set_etymology(self, etymology):
664  """! @brief Set etymology.
665  Attribute 'etymology' is owned by Statement, which is owned by Definition, itself owned by Sense.
666  @param etymology Etymology.
667  @return LexicalEntry instance.
668  """
669  # Get the last Sense instance if any
670  sense = self.get_last_sense()
671  # If there is no Sense instance, create and add one
672  if sense is None:
673  sense = self.create_sense()
674  self.add_sense(sense)
675  sense.set_etymology(etymology)
676  return self
677 
678  def get_etymology(self):
679  """! @brief Get etymology.
680  This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
681  @return The first found Statement attribute 'etymology'.
682  """
683  for sense in self.get_senses():
684  if sense.get_etymology() is not None:
685  return sense.get_etymology()
686 
687  def set_etymology_comment(self, etymology_comment, term_source_language=None):
688  """! @brief Set etymology comment and language.
689  Attributes 'etymologyComment' and 'termSourceLanguage' are owned by Statement, which is owned by Definition, itself owned by Sense.
690  @param etymology_comment Etymology comment.
691  @param term_source_language Language of the comment.
692  @return LexicalEntry instance.
693  """
694  # Get the last Sense instance if any
695  sense = self.get_last_sense()
696  # If there is no Sense instance, create and add one
697  if sense is None:
698  sense = self.create_sense()
699  self.add_sense(sense)
700  sense.set_etymology_comment(etymology_comment, term_source_language)
701  return self
702 
703  def get_etymology_comment(self, term_source_language=None):
704  """! @brief Get etymology comment.
705  This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
706  @param term_source_language The language of the etymology comment to retrieve.
707  @return The first found Statement attribute 'etymologyComment'.
708  """
709  for sense in self.get_senses():
710  if sense.get_etymology_comment(term_source_language) is not None:
711  return sense.get_etymology_comment(term_source_language)
712 
714  """! @brief Get language used for the etymology comment.
715  This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
716  @return Statement attribute 'termSourceLanguage'.
717  """
718  # Get the last Sense instance if any
719  sense = self.get_last_sense()
720  # If there is a Sense instance, get etymology comment language
721  if sense is not None:
722  return sense.get_term_source_language()
723 
724  def set_etymology_gloss(self, etymology_gloss):
725  """! @brief Set etymology gloss.
726  Attribute 'etymologyGloss' is owned by Statement, which is owned by Definition, itself owned by Sense.
727  @param etymology_gloss Etymology gloss.
728  @return LexicalEntry instance.
729  """
730  # Get the last Sense instance if any
731  sense = self.get_last_sense()
732  # If there is no Sense instance, create and add one
733  if sense is None:
734  sense = self.create_sense()
735  self.add_sense(sense)
736  sense.set_etymology_gloss(etymology_gloss)
737  return self
738 
740  """! @brief Get etymology gloss.
741  This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
742  @return Statement attribute 'etymologyGloss'.
743  """
744  # Get the last Sense instance if any
745  sense = self.get_last_sense()
746  # If there is a Sense instance, get etymology gloss
747  if sense is not None:
748  return sense.get_etymology_gloss()
749 
750  def set_etymology_source(self, etymology_source):
751  """! @brief Set etymology source.
752  Attribute 'etymologySource' is owned by Statement, which is owned by Definition, itself owned by Sense.
753  @param etymology_source Etymology source.
754  @return LexicalEntry instance.
755  """
756  # Get the last Sense instance if any
757  sense = self.get_last_sense()
758  # If there is no Sense instance, create and add one
759  if sense is None:
760  sense = self.create_sense()
761  self.add_sense(sense)
762  sense.set_etymology_source(etymology_source)
763  return self
764 
766  """! @brief Get etymology source.
767  This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
768  @return Statement attribute 'etymologySource'.
769  """
770  # Get the last Sense instance if any
771  sense = self.get_last_sense()
772  # If there is a Sense instance, get etymology source
773  if sense is not None:
774  return sense.get_etymology_source()
775 
776  def set_scientific_name(self, scientific_name):
777  """! @brief Set scientific_name.
778  Attribute 'scientificName' is owned by Statement, which is owned by Definition, itself owned by Sense.
779  @param scientific_name Scientific name.
780  @return LexicalEntry instance.
781  """
782  # Get the last Sense instance if any
783  sense = self.get_last_sense()
784  # If there is no Sense instance, create and add one
785  if sense is None:
786  sense = self.create_sense()
787  self.add_sense(sense)
788  sense.set_scientific_name(scientific_name)
789  return self
790 
792  """! @brief Get scientific name.
793  This attribute is owned by Statement, which is owned by Definition, itself owned by Sense.
794  @return Statement attribute 'scientificName'.
795  """
796  # Get the last Sense instance if any
797  sense = self.get_last_sense()
798  # If there is a Sense instance, get scientific name
799  if sense is not None:
800  return sense.get_scientific_name()
801 
802  def create_word_form(self):
803  """! @brief Create a word form.
804  @return WordForm instance.
805  """
806  return WordForm()
807 
808  def add_word_form(self, word_form):
809  """! @brief Add a word form to the lexical entry.
810  @param word_form The WordForm instance to add to the lexical entry.
811  @return LexicalEntry instance.
812  """
813  self.word_form.append(word_form)
814  return self
815 
816  def get_word_forms(self):
817  """! @brief Get all word forms maintained by the lexical entry.
818  @return A Python list of word forms.
819  """
820  return self.word_form
821 
822  def set_paradigm(self, written_form, script_name=None, person=None, anymacy=None, grammatical_number=None, clusivity=None):
823  """! @brief Set paradigm.
824  Attributes 'writtenForm' and 'scriptName' are owned by FormRepresentation, wich is owned by WordForm.
825  Attributes 'person', 'anymacy', 'grammaticalNumber' and 'clusivity' are owned by WordForm.
826  @param written_form The paradigm to set.
827  @param script_name Script used for the written form.
828  @param person Person, e.g. first person.
829  @param anymacy Anymacy, e.g. animate or inanimate.
830  @param grammatical_number Grammatical number, e.g. singular or plural.
831  @param clusivity Clusivity, e.g. inclusive or exclusive.
832  @return LexicalEntry instance.
833  """
834  word_form = None
835  # Find corresponding word form
836  for form in self.get_word_forms():
837  if form.get_person() == person and form.get_anymacy() == anymacy and form.get_grammaticalNumber() == grammatical_number and form.get_clusivity() == clusivity:
838  # Add a paradigm as a written form to an existing word form
839  word_form = form
840  break
841  if word_form is None:
842  # Create a WordForm instance
843  word_form = self.create_word_form()
844  self.add_word_form(word_form)
845  if person is not None:
846  word_form.set_person(person)
847  if anymacy is not None:
848  word_form.set_anymacy(anymacy)
849  if grammatical_number is not None:
850  word_form.set_grammaticalNumber(grammatical_number)
851  if clusivity is not None:
852  word_form.set_clusivity(clusivity)
853  word_form.set_written_form(written_form, script_name)
854  return self
855 
856  def find_paradigms(self, script_name=None, person=None, anymacy=None, grammatical_number=None, clusivity=None):
857  """! @brief Find paradigms.
858  Attribute 'scriptName' is owned by FormRepresentation, wich is owned by WordForm.
859  Attributes 'person', 'anymacy', 'grammaticalNumber' and 'clusivity' are owned by WordForm.
860  Attribute 'writtenForm' to retrieve is owned by FormRepresentation, wich is owned by WordForm.
861  @param script_name If this argument is given, get paradigm written form only if written using this script.
862  @param person Person, e.g. first person.
863  @param anymacy Anymacy, e.g. animate or inanimate.
864  @param grammatical_number Grammatical number, e.g. singular or plural.
865  @param clusivity Clusivity, e.g. inclusive or exclusive.
866  @return A Python list of FormRepresentation attributes 'writtenForm'.
867  """
868  written_forms = []
869  # Find corresponding word form
870  for form in self.get_word_forms():
871  if form.get_person() == person and form.get_anymacy() == anymacy and form.get_grammaticalNumber() == grammatical_number and form.get_clusivity() == clusivity:
872  written_forms += form.get_written_forms(script_name)
873  return written_forms
874 
875  def set_paradigm_label(self, paradigm_label):
876  """! @brief Set paradigm label.
877  Attribute 'paradigmLabel' is owned by Paradigm, which is owned by Sense.
878  @param paradigm_label Paradigm label.
879  @return LexicalEntry instance.
880  """
881  # Get the last Sense instance if any
882  sense = self.get_last_sense()
883  # If there is no Sense instance, create and add one
884  if sense is None:
885  sense = self.create_sense()
886  self.add_sense(sense)
887  sense.set_paradigm_label(paradigm_label)
888  return self
889 
890  def set_paradigm_form(self, paradigm, language=None):
891  """! @brief Set paradigm form.
892  Attribute 'paradigm' is owned by Paradigm, which is owned by Sense.
893  @param paradigm Paradigm form.
894  @param language Language of the paradigm form.
895  @return LexicalEntry instance.
896  """
897  # Get the last Sense instance if any
898  sense = self.get_last_sense()
899  # If there is no Sense instance, create and add one
900  if sense is None:
901  sense = self.create_sense()
902  self.add_sense(sense)
903  sense.set_paradigm_form(paradigm, language)
904  return self
905 
906  def set_morphology(self, morphology):
907  """! @brief Set morphology.
908  Attribute 'morphology' is owned by Paradigm, which is owned by Sense.
909  @param morphology Morphology.
910  @return LexicalEntry instance.
911  """
912  # Get the last Sense instance if any
913  sense = self.get_last_sense()
914  # If there is no Sense instance, create and add one
915  if sense is None:
916  sense = self.create_sense()
917  self.add_sense(sense)
918  sense.set_morphology(morphology)
919  return self
920 
921  def get_paradigms(self):
922  """! @brief Get all paradigms.
923  This attribute is owned by Sense.
924  @return Sense attribute 'paradigm'.
925  """
926  paradigms = []
927  for sense in self.get_senses():
928  paradigms += sense.get_paradigms()
929  return paradigms
930 
931  def get_morphologies(self):
932  """! @brief Get all morphologies.
933  This attribute is owned by Paradigm, which is owned by Sense.
934  @return A Python list of Paradigm attributes 'morphology'.
935  """
936  morphologies = []
937  for sense in self.get_senses():
938  for paradigm in sense.get_paradigms():
939  if paradigm.get_morphology() is not None:
940  morphologies.append(paradigm.get_morphology())
941  return morphologies
942 
943  def create_example(self, reference=None):
944  """! @brief Create a context.
945  Attribute 'targets' is owned by Context, itself owend by Sense.
946  @param reference The example reference to set. If not provided, default value is None.
947  @return LexicalEntry instance.
948  """
949  # Get the last Sense instance if any
950  sense = self.get_last_sense()
951  # If there is no Sense instance, create and add one
952  if sense is None:
953  sense = self.create_sense()
954  self.add_sense(sense)
955  sense.create_example(reference)
956  return self
957 
958  def create_and_add_example(self, written_form, language=None, script_name=None):
959  """! @brief Add an example to a new context and set its written form, language and script.
960  Attributes 'writtenForm', 'language' and 'scriptName' are owned by TextRepresentation, which is owned by Context, itself owend by Sense.
961  @param written_form The written form to set.
962  @param language Language used for the written form.
963  @param script_name The name of the script used to write the example, e.g. devanagari.
964  @return LexicalEntry instance.
965  """
966  # Get the last Sense instance if any
967  sense = self.get_last_sense()
968  # If there is no Sense instance, create and add one
969  if sense is None:
970  sense = self.create_sense()
971  self.add_sense(sense)
972  sense.create_and_add_example(written_form, language, script_name)
973  return self
974 
975  def add_example(self, written_form, language=None, script_name=None):
976  """! @brief Add an example to an existing context and set its written form, language and script.
977  Attributes 'writtenForm', 'language' and 'scriptName' are owned by TextRepresentation, which is owned by Context, itself owend by Sense.
978  @param written_form The written form to set.
979  @param language Language used for the written form.
980  @param script_name The name of the script used to write the example, e.g. devanagari.
981  @return LexicalEntry instance.
982  """
983  # Get the last Sense instance if any
984  sense = self.get_last_sense()
985  # If there is no Sense instance, create and add one
986  if sense is None:
987  sense = self.create_sense()
988  self.add_sense(sense)
989  sense.add_example(written_form, language, script_name)
990  return self
991 
992  def set_example_comment(self, comment):
993  """! @brief Set comment of an existing example.
994  Attribute 'comment' is owned by TextRepresentation, which is owned by Context, itself owend by Sense.
995  @param comment The comment to set.
996  @return LexicalEntry instance.
997  """
998  # Get the last Sense instance if any
999  sense = self.get_last_sense()
1000  # If there is no Sense instance, create and add one
1001  if sense is None:
1002  sense = self.create_sense()
1003  self.add_sense(sense)
1004  sense.set_example_comment(comment)
1005  return self
1006 
1007  def set_semantic_domain(self, semantic_domain, language=None):
1008  """! @brief Set semantic domain and language.
1009  Attributes 'semanticDomain' and 'language' are owned by SubjectField, which is owned by Sense.
1010  @param semantic_domain The semantic domain to set.
1011  @param language Language used to describe the semantic domain.
1012  @return LexicalEntry instance.
1013  """
1014  # Get the last Sense instance if any
1015  sense = self.get_last_sense()
1016  # If there is no Sense instance, create and add one
1017  if sense is None:
1018  sense = self.create_sense()
1019  self.add_sense(sense)
1020  sense.set_semantic_domain(semantic_domain, language)
1021  return self
1022 
1023  def get_semantic_domains(self, language=None):
1024  """! @brief Get all semantic domains.
1025  This attribute is owned by SubjectField, which is owned by Sense.
1026  @param language If this argument is given, get only semantic domains that are described using this language.
1027  @return A Python list of filtered SubjectField attributes 'semanticDomain'.
1028  """
1029  semantic_domains = []
1030  for sense in self.get_senses():
1031  for subject_field in sense.get_subject_fields():
1032  if subject_field.get_semanticDomain(language) is not None:
1033  semantic_domains.append(subject_field.get_semanticDomain(language))
1034  semantic_domains += subject_field.get_sub_domains(language)
1035  return semantic_domains
1036 
1037  def set_translation(self, translation, language=None):
1038  """! @brief Set translation and language.
1039  Attributes 'translation' and 'language' are owned by Equivalent, which is owned by Sense.
1040  @param translation The translation to set.
1041  @param language Language used for the translation.
1042  @return LexicalEntry instance.
1043  """
1044  # Get the last Sense instance if any
1045  sense = self.get_last_sense()
1046  # If there is no Sense instance, create and add one
1047  if sense is None:
1048  sense = self.create_sense()
1049  self.add_sense(sense)
1050  sense.set_translation(translation, language)
1051  return self
1052 
1053  def set_audio(self, media_type="audio", file_name=None, author=None, quality=None, start_position="T00:00:00", duration=None, external_reference=None, audio_file_format=None):
1054  """! @brief Set audio resource.
1055  Attributes 'mediaType', 'fileName', 'author', 'quality', 'startPosition', 'durationOfEffectiveSpeech', 'externalReference', 'audioFileFormat' are owned by Material/Audio, which is owned by FormRepresentation, itself owend by Lemma.
1056  @param media_type The media type to set.
1057  @param file_name Name of the audio file.
1058  @param author Author of the recording.
1059  @param quality Quality of the recording, in range 'quality_range' defined in 'common/range.py'.
1060  @param start_position Start position of the form in the recording, in format 'Thh:mm:ss,msms', e.g. "T00:05:00".
1061  @param duration Duration of the effcetive speech, in format 'PThhHmmMssS', e.g. "PT00:05:00".
1062  @param external_reference Reference of the audio file, if not directly provided.
1063  @param audio_file_format Format of the audio file, e.g. "wav".
1064  @return LexicalEntry instance.
1065  """
1066  # Create a Lemma instance if not yet created
1067  if self.lemma is None:
1068  self.lemma = Lemma()
1069  self.lemma.set_audio(media_type, file_name, author, quality, start_position, duration, external_reference, audio_file_format)
1070  return self
1071 
1072  def is_subentry(self):
1073  """! @brief Check if this lexical entry is a subentry.
1074  @return 'True' if it is a subentry, 'False' otherwise.
1075  """
1076  for related_form in self.get_related_forms():
1077  # If one of the related form is a main entry, it means that the current lexical entry is a subentry
1078  if related_form.get_semanticRelation() == "main entry":
1079  return True
1080  return False
1081 
1082  def has_subentries(self):
1083  """! @brief Check if this lexical entry has subentries.
1084  @return 'True' if it has subentries, 'False' otherwise.
1085  """
1086  for related_form in self.get_related_forms():
1087  # If one of the related form is a subentry, it means that the current lexical entry is a main entry
1088  if related_form.get_semanticRelation() == "subentry":
1089  return True
1090  return False
1091 
1092  def get_subentries(self):
1093  """! @brief Get subentries of this lexical entry.
1094  @return A Python list of LexicalEntry.
1095  """
1096  subentries = []
1097  for related_form in self.get_related_forms():
1098  if related_form.get_semanticRelation() == "subentry":
1099  subentries.append(related_form.get_lexical_entry())
1100  return subentries
1101 
1102  def get_main_entry(self):
1103  """! @brief If this lexical entry is a subentry, get its main entry.
1104  @return A LexicalEntry if it exists, 'None' otherwise.
1105  """
1106  for related_form in self.get_related_forms():
1107  if related_form.get_semanticRelation() == "main entry":
1108  return related_form.get_lexical_entry()
1109 
1110  def create_and_add_component(self, position, lexeme):
1111  """! @brief Create and add a component to the lexical entry.
1112  @param position The position of the component in the multiword expression.
1113  @param lexeme Related lexeme.
1114  @return LexicalEntry instance.
1115  """
1116  if self.list_of_components is None:
1117  self.list_of_components = ListOfComponents()
1118  self.list_of_components.create_and_add_component(position, lexeme)
1119  return self
1120 
1121  def get_components(self):
1122  """! @brief If this lexical entry is a multiword expression, get its components.
1123  @return A list of components if any, an empty list otherwise.
1124  """
1125  if self.list_of_components is None:
1126  return []
1127  return self.list_of_components.get_components()
1128 
1129  def is_component(self):
1130  """! @brief Check if this lexical entry is a component.
1131  @return 'True' if it is a component, 'False' otherwise.
1132  """
1133  for related_form in self.get_related_forms():
1134  # If one of the related form is a complex predicate, it means that the current lexical entry is a component
1135  if related_form.get_semanticRelation() == "complex predicate":
1136  return True
1137  return False
1138 
1139  def get_speaker(self):
1140  """! @brief Get speaker.
1141  @return LexicalEntry private attribute '__speaker'.
1142  """
1143  return self.__speaker
def create_and_add_related_form
Create and add a related form to the lexical entry.
def get_lexeme
Get lexeme.
def get_senses
Get all senses maintained by the lexical entry.
"Lexical Entry is a class representing a lexeme in a given language and is a container for managing t...
def set_dialect
Set dialect.
def get_variant_forms
Get all variant forms of specified type.
def create_and_add_component
Create and add a component to the lexical entry.
date
def check_attr_type
Check that attribute value is of specified type.
Definition: attr.py:9
def get_borrowed_word
Get source language (in English).
def create_and_add_example
Add an example to a new context and set its written form, language and script.
id
UID is managed at the Lexicon level.
def set_etymology
Set etymology.
def set_paradigm_form
Set paradigm form.
def set_scientific_name
Set scientific_name.
def set_etymology_comment
Set etymology comment and language.
def set_status
Set lexical entry status.
def set_semantic_domain
Set semantic domain and language.
def get_bibliography
Get lexical entry bibliography.
def add_word_form
Add a word form to the lexical entry.
def get_status
Get lexical entry status.
def set_translation
Set translation and language.
def check_attr_range
Check that attribute value is in specified range.
Definition: attr.py:23
def create_word_form
Create a word form.
def get_etymology_comment
Get etymology comment.
def get_related_forms
Get all related forms maintained by the lexical entry.
def get_id
Get Unique IDentifier.
def set_audio
Set audio resource.
def set_restriction
Set restriction and language.
def get_independentWord
Get lexical entry independent word indication.
list_of_components
ListOfComponents instance is owned by LexicalEntry There is zero or one ListOfComponents instance per...
def create_example
Create a context.
def get_subentries
Get subentries of this lexical entry.
def get_word_forms
Get all word forms maintained by the lexical entry.
def get_phonetic_forms
Get all phonetic forms.
stem
Stem instances are owned by LexicalEntry There is zero to many Stem instances per LexicalEntry...
sense
Sense instances are owned by LexicalEntry There is zero to many Sense instances per LexicalEntry...
def set_gloss
Set gloss and language.
def set_paradigm
Set paradigm.
def get_etymology_gloss
Get etymology gloss.
def get_tones
Get all tones.
def get_speaker
Get speaker.
targets
def set_written_form
Set loan word.
def create_sense
Create a sense.
def get_spelling_variants
Get all spelling variants.
def create_and_add_sense
Create and add a sense to the lexical entry.
def set_encyclopedic_information
Set encyclopedic information and language.
def get_components
If this lexical entry is a multiword expression, get its components.
def set_script_name
Set script name.
def get_morphologies
Get all morphologies.
def set_partOfSpeech
Set grammatical category.
def get_term_source_language
Get language used for the etymology comment.
def add_related_form
Add a related form to the lexical entry.
def set_lexeme
Set lexeme.
independentWord
def set_example_comment
Set comment of an existing example.
def set_independentWord
Set lexical entry independent word indication.
lemma
Lemma instance is owned by LexicalEntry There is one Lemma instance by LexicalEntry instance...
def set_phonetic_form
Set phonetic form.
def set_homonymNumber
Set lexical entry homonym number.
status
related_form
RelatedForm instances are owned by LexicalEntry There is zero to many RelatedForm instances per Lexic...
def is_component
Check if this lexical entry is a component.
def get_partOfSpeech
Get grammatical category.
def get_scientific_name
Get scientific name.
def set_tone
Set tone.
def set_geographical_variant
Set geographical variant.
def get_transliterations
Get all transliterations.
def get_homonymNumber
Get lexical entry homonym number.
def get_written_form
Get loan word.
def set_borrowed_word
Set source language (in English).
bibliography
def set_date
Set lexical entry date.
def get_paradigms
Get all paradigms.
def get_main_entry
If this lexical entry is a subentry, get its main entry.
def set_morphology
Set morphology.
def is_subentry
Check if this lexical entry is a subentry.
def set_etymology_gloss
Set etymology gloss.
__speaker
Pointer to an existing Speaker There is one Speaker pointer per LexicalEntry instance.
def set_spelling_variant
Set spelling variant.
def get_etymology
Get etymology.
def get_last_sense
Get the previously registered sense.
def get_semantic_domains
Get all semantic domains.
def get_etymology_source
Get etymology source.
def set_contextual_variation
Set contextual variation.
def get_contextual_variations
Get all contextual variations.
def set_variant_form
Set variant form and type.
partOfSpeech
def set_note
Set note, type and language.
def set_paradigm_label
Set paradigm label.
def create_related_form
Create a related form.
def has_subentries
Check if this lexical entry has subentries.
def add_sense
Add a sense to the lexical entry.
def set_citation_form
Set citation form.
def __init__
Constructor.
def find_related_forms
Find related lexemes.
def set_definition
Set definition and language.
def get_citation_forms
Get all citation forms.
def get_form_representations
Get all form representations maintained by the lemma.
def find_notes
Find notes.
def set_bibliography
Set lexical entry bibliography.
def find_paradigms
Find paradigms.
def set_etymology_source
Set etymology source.
def get_last_related_form
Get the previously registered related form.
def set_transliteration
Set transliteration.
def set_variant_comment
Set variant comment and language.
def add_example
Add an example to an existing context and set its written form, language and script.
def get_date
Get lexical entry date.
homonymNumber
def __del__
Destructor.
word_form
WordForm instances are owned by LexicalEntry There is zero to many WordForm instances per LexicalEntr...
def set_usage_note
Set usage note and language.