Added support for translating msds or properties

This commit is contained in:
Cyprian Laskowski 2021-10-12 17:44:55 +02:00
parent a088025026
commit 6b63b9940e
5 changed files with 50 additions and 4 deletions

View File

@ -291,3 +291,9 @@ class Converter:
i += 1
msd_code += position_map[position]
return Msd(msd_code, language)
def translate_msd(self, msd, language):
return self.properties_to_msd(self.msd_to_properties(msd, language), language)
def translate_properties(self, properties, language):
return self.msd_to_properties(self.properties_to_msd(properties, language), language)

View File

@ -1,7 +1,6 @@
import os.path
import unittest
from conversion_utils.jos_msds_and_properties import SpecificationsParser, Converter, Msd
from conversion_utils.jos_msds_and_properties import Converter, Msd
class JosMsdToPropertiesTestCase(unittest.TestCase):

View File

@ -1,7 +1,6 @@
import os.path
import unittest
from conversion_utils.jos_msds_and_properties import SpecificationsParser, Converter, Properties
from conversion_utils.jos_msds_and_properties import Converter, Properties
class JosPropertiesToMsdTestCase(unittest.TestCase):

View File

@ -0,0 +1,18 @@
import unittest
from conversion_utils.jos_msds_and_properties import Converter, Msd
class JosMsdToPropertiesTestCase(unittest.TestCase):
def setUp(self):
self.converter = Converter()
def test_en_sl(self):
msd_sl = self.converter.translate_msd(Msd('Ncfpd', 'en'), 'sl')
self.assertEqual(msd_sl.language, 'sl')
self.assertEqual(msd_sl.code, 'Sozmd')
def test_sl_en(self):
msd_en = self.converter.translate_msd(Msd('Sozmd', 'sl'), 'en')
self.assertEqual(msd_en.language, 'en')
self.assertEqual(msd_en.code, 'Ncfpd')

View File

@ -0,0 +1,24 @@
import unittest
from conversion_utils.jos_msds_and_properties import Converter, Properties
class JosPropertiesToMsdTestCase(unittest.TestCase):
def setUp(self):
self.converter = Converter()
def test_en_sl(self):
properties_en = Properties('noun', {'type':'common', 'gender':'feminine'}, {'number':'dual', 'case':'dative'}, 'en')
properties_sl = self.converter.translate_properties(properties_en, 'sl')
self.assertEqual(properties_sl.category, 'samostalnik')
self.assertEqual(properties_sl.lexeme_feature_map, {'vrsta':'občno_ime', 'spol':'ženski'})
self.assertEqual(properties_sl.form_feature_map, {'število':'dvojina', 'sklon':'dajalnik'})
self.assertEqual(properties_sl.language, 'sl')
def test_sl_en(self):
properties_sl = Properties('samostalnik', {'vrsta':'občno_ime', 'spol':'ženski'}, {'število':'dvojina', 'sklon':'dajalnik'}, 'sl')
properties_en = self.converter.translate_properties(properties_sl, 'en')
self.assertEqual(properties_en.category, 'noun')
self.assertEqual(properties_en.lexeme_feature_map, {'type':'common', 'gender':'feminine'})
self.assertEqual(properties_en.form_feature_map, {'number':'dual', 'case':'dative'})
self.assertEqual(properties_en.language, 'en')