Replaced JOS XML specifications with preprocessed pickle

This commit is contained in:
cyp
2021-09-30 00:22:43 +02:00
parent eca02ebdd3
commit a088025026
9 changed files with 38 additions and 37878 deletions
+20 -2
View File
@@ -1,8 +1,12 @@
import lxml.etree as lxml
import re
import pickle
import importlib.resources as pkg_resources
from conversion_utils.utils import xpath_find, get_xml_id
JOS_SPECIFICATIONS_PICKLE_RESOURCE = 'jos_specifications.pickle'
## Positions of lexeme-level features for each category
LEXEME_FEATURE_MAP = {'noun':{1,2},
'verb':{1,2},
@@ -219,8 +223,22 @@ class Msd:
class Converter:
"""Converter between Msd and Properties objects."""
def __init__(self, specifications):
self.specifications = specifications
def __init__(self, xml_file_name=None):
if (xml_file_name is None):
if (pkg_resources.is_resource('conversion_utils.resources', JOS_SPECIFICATIONS_PICKLE_RESOURCE)):
try:
with pkg_resources.open_binary('conversion_utils.resources', JOS_SPECIFICATIONS_PICKLE_RESOURCE) as pickle_file:
self.specifications = pickle.load(pickle_file)
except:
exit('Could not parse specifications pickle file installed.')
else:
exit('No pickle installed or xml provided.')
else:
parser = SpecificationsParser()
try:
self.specifications = parser.parse(xml_file_name)
except:
exit('Could not parse specifications xml file provided.')
def msd_to_properties(self, msd, language, lemma=None):
"""Convert Msd to Properties (possibly in the other language)."""