| Total Complexity | 5 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | 1 | """ |
|
| 3 | This module contains a basic WordSource Model |
||
| 4 | """ |
||
| 5 | 1 | import re |
|
| 6 | 1 | from loglan_db.model_db import t_name_word_sources |
|
| 7 | |||
| 8 | |||
| 9 | 1 | class BaseWordSource: |
|
| 10 | """Word Source from BaseWord.origin for Prims""" |
||
| 11 | 1 | __tablename__ = t_name_word_sources |
|
| 12 | 1 | PATTERN_SOURCE = r"\d+\/\d+\w" |
|
| 13 | |||
| 14 | 1 | def __init__(self, source): |
|
| 15 | |||
| 16 | 1 | compatibility_search = re.search(self.PATTERN_SOURCE, source) |
|
| 17 | |||
| 18 | 1 | if compatibility_search: |
|
| 19 | 1 | self.coincidence = int(compatibility_search[0][:-1].split("/")[0]) |
|
| 20 | 1 | self.length = int(compatibility_search[0][:-1].split("/")[1]) |
|
| 21 | 1 | self.language = compatibility_search[0][-1:] |
|
| 22 | else: |
||
| 23 | 1 | self.coincidence = self.length = self.language = None |
|
| 24 | |||
| 25 | 1 | transcription_search = re.search(rf"(?!{self.PATTERN_SOURCE}) .+", source) |
|
| 26 | 1 | self.transcription = str(transcription_search[0]).strip() if transcription_search else None |
|
| 27 | |||
| 28 | 1 | LANGUAGES = { |
|
| 29 | "E": "English", |
||
| 30 | "C": "Chinese", |
||
| 31 | "H": "Hindi", |
||
| 32 | "R": "Russian", |
||
| 33 | "S": "Spanish", |
||
| 34 | "F": "French", |
||
| 35 | "J": "Japanese", |
||
| 36 | "G": "German", } |
||
| 37 | |||
| 38 | 1 | @property |
|
| 39 | 1 | def as_string(self) -> str: |
|
| 40 | """ |
||
| 41 | Format WordSource as string, for example, '3/5R mesto' |
||
| 42 | Returns: |
||
| 43 | str |
||
| 44 | """ |
||
| 45 | 1 | if not all([self.coincidence, self.length, self.language, self.transcription]): |
|
| 46 | 1 | return str() |
|
| 47 | return f"{self.coincidence}/{self.length}{self.language} {self.transcription}" |
||
| 48 |