2021-09-10 08:40:59 +00:00
|
|
|
import os.path
|
|
|
|
import lxml.etree as lxml
|
|
|
|
import unittest
|
|
|
|
|
2021-09-10 11:49:34 +00:00
|
|
|
from conversion_utils.jos_msds_and_properties import SpecificationsBuilder, MsdToProperties, Msd
|
2021-09-10 08:40:59 +00:00
|
|
|
|
|
|
|
class JosMsdToPropertiesTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
specifications_file_name = os.path.join(os.path.dirname(__file__), '../resources/msd-sl.spc.xml')
|
|
|
|
builder = SpecificationsBuilder()
|
|
|
|
self.specifications = builder.build(specifications_file_name)
|
|
|
|
self.converter = MsdToProperties()
|
|
|
|
|
|
|
|
def test_en_en(self):
|
2021-09-10 11:49:34 +00:00
|
|
|
properties = self.converter.convert(self.specifications, Msd('Ncfpd', 'en'), 'miza', 'en')
|
2021-09-10 08:40:59 +00:00
|
|
|
self.assertEqual(properties.language, 'en')
|
|
|
|
self.assertEqual(properties.category, 'noun')
|
|
|
|
self.assertEqual(properties.lexeme_feature_map, {'type':'common', 'gender':'feminine'})
|
|
|
|
self.assertEqual(properties.form_feature_map, {'number':'plural', 'case':'dative'})
|
|
|
|
|
|
|
|
def test_en_sl(self):
|
2021-09-10 11:49:34 +00:00
|
|
|
properties = self.converter.convert(self.specifications, Msd('Ncfpd', 'en'), 'miza', 'sl')
|
2021-09-10 08:40:59 +00:00
|
|
|
self.assertEqual(properties.language, 'sl')
|
|
|
|
self.assertEqual(properties.category, 'samostalnik')
|
|
|
|
self.assertEqual(properties.lexeme_feature_map, {'vrsta':'občno_ime', 'spol':'ženski'})
|
|
|
|
self.assertEqual(properties.form_feature_map, {'število':'množina', 'sklon':'dajalnik'})
|
|
|
|
|
|
|
|
def test_sl_en(self):
|
2021-09-10 11:49:34 +00:00
|
|
|
properties = self.converter.convert(self.specifications, Msd('Sozmd', 'sl'), 'miza', 'en')
|
2021-09-10 08:40:59 +00:00
|
|
|
self.assertEqual(properties.language, 'en')
|
|
|
|
self.assertEqual(properties.category, 'noun')
|
|
|
|
self.assertEqual(properties.lexeme_feature_map, {'type':'common', 'gender':'feminine'})
|
|
|
|
self.assertEqual(properties.form_feature_map, {'number':'plural', 'case':'dative'})
|
|
|
|
|
|
|
|
def test_sl_sl(self):
|
2021-09-10 11:49:34 +00:00
|
|
|
properties = self.converter.convert(self.specifications, Msd('Sozmd', 'sl'), 'miza', 'sl')
|
2021-09-10 08:40:59 +00:00
|
|
|
self.assertEqual(properties.language, 'sl')
|
|
|
|
self.assertEqual(properties.category, 'samostalnik')
|
|
|
|
self.assertEqual(properties.lexeme_feature_map, {'vrsta':'občno_ime', 'spol':'ženski'})
|
|
|
|
self.assertEqual(properties.form_feature_map, {'število':'množina', 'sklon':'dajalnik'})
|
|
|
|
|
|
|
|
def test_exception_feature_level(self): # testing level exception: ('pronoun', 8, 'ti')
|
2021-09-10 11:49:34 +00:00
|
|
|
properties = self.converter.convert(self.specifications, Msd('Pp2-sd--y', 'en'), 'ti', 'sl')
|
2021-09-10 08:40:59 +00:00
|
|
|
self.assertEqual(properties.language, 'sl')
|
|
|
|
self.assertEqual(properties.category, 'zaimek')
|
|
|
|
self.assertEqual(properties.lexeme_feature_map, {'vrsta':'osebni', 'oseba':'druga'})
|
|
|
|
self.assertEqual(properties.form_feature_map, {'število':'ednina', 'sklon':'dajalnik', 'naslonskost':'klitična'})
|
|
|
|
|
|
|
|
def test_normal_feature_level(self): # invalid msd, but useful for testing contrast with previous test
|
2021-09-10 11:49:34 +00:00
|
|
|
properties = self.converter.convert(self.specifications, Msd('Pp2-pd--y', 'en'), 'vi', 'sl')
|
2021-09-10 08:40:59 +00:00
|
|
|
self.assertEqual(properties.language, 'sl')
|
|
|
|
self.assertEqual(properties.category, 'zaimek')
|
|
|
|
self.assertEqual(properties.lexeme_feature_map, {'vrsta':'osebni', 'oseba':'druga', 'naslonskost':'klitična'})
|
|
|
|
self.assertEqual(properties.form_feature_map, {'število':'množina', 'sklon':'dajalnik'})
|
|
|
|
|
|
|
|
def test_featureless(self):
|
2021-09-10 11:49:34 +00:00
|
|
|
properties = self.converter.convert(self.specifications, Msd('V', 'sl'), 'in', 'en')
|
2021-09-10 08:40:59 +00:00
|
|
|
self.assertEqual(properties.language, 'en')
|
|
|
|
self.assertEqual(properties.category, 'conjunction')
|
|
|
|
self.assertEqual(properties.lexeme_feature_map, {})
|
|
|
|
self.assertEqual(properties.form_feature_map, {})
|