2121class PreVele (Block ):
2222 """Change all comparatives to vele-x and superlatives to převele-x."""
2323
24- def __init__ (self , morphodita_path = 'models/morphodita/cs/' ,
24+ def __init__ (self , synonyms , antonyms , morphodita_path = 'models/morphodita/cs/' ,
2525 morphodita_model = 'czech-morfflex-131112.dict' ,
2626 ** kwargs ):
2727 """Create the PreVele block object."""
2828 super ().__init__ (** kwargs )
29+ self .antonyms = self .load_vocab (antonyms )
30+ self .synonyms = self .load_vocab (synonyms )
2931 self .morphodita = MorphoDiTa (model = morphodita_path + morphodita_model )
3032
33+ def load_vocab (self , filename ):
34+ vocab = {}
35+ with open (filename ) as f :
36+ for line in f :
37+ (key , val ) = line .strip ().split ('\t ' )
38+ vocab [key ] = val
39+ return vocab
40+
3141 def process_tree (self , tree ):
3242
3343 # apply process_node on all nodes
@@ -42,7 +52,7 @@ def process_tree(self, tree):
4252 tree .text = tree .compute_text ()
4353
4454 def process_node (self , node ):
45- antonym = ANTONYMS .get (node .lemma )
55+ antonym = self . antonyms .get (node .lemma )
4656 if antonym is not None :
4757 if node .xpos [11 ] == 'N' :
4858 if node .form .lower ().startswith ('ne' ):
@@ -56,6 +66,14 @@ def process_node(self, node):
5666 node .xpos = node .xpos [:10 ] + 'N' + node .xpos [11 :]
5767 node .form = 'ne' + forms [0 ].form
5868
69+ synonym = self .synonyms .get (node .lemma )
70+ if synonym is not None :
71+ forms = self .morphodita .forms_of_lemma (synonym , node .xpos )
72+ if forms :
73+ node .lemma = synonym
74+ node .form = forms [0 ].form
75+
76+
5977 degree = node .feats ["Degree" ]
6078 if degree in ("Sup" , "Cmp" ):
6179 new_xpos = node .xpos [:9 ] + '1' + node .xpos [10 :]
0 commit comments