Redmine #1487: looked for min other id in structures

This commit is contained in:
Cyprian Laskowski 2021-03-15 16:00:28 +01:00
parent 2e9b4a5d0a
commit 08c291b5db

View File

@ -135,11 +135,22 @@ class Pipeline:
wani_main(namespace) wani_main(namespace)
def _find_min_other_id(self, key):
try:
root = lxml.parse(self.file_map[key])
other_ids = [int(oid) for oid in root.xpath('syntactic_structure[@type="other"]/@id')]
min_id = min(other_ids)
except:
min_id = 109 # This is the current value in structures.xml, and is not expected to change. Ugly, but code shouldn't reach here ...
return min_id
def do_assign_multiple_first(self): def do_assign_multiple_first(self):
assign_multiple(self.file_map['tei-multiple'], self.file_map['mwes-1'], self.file_map['tei-multiple-ids-1']) min_other_id = self._find_min_other_id('structures-old')
assign_multiple(self.file_map['tei-multiple'], self.file_map['mwes-1'], self.file_map['tei-multiple-ids-1'], min_other_id)
def do_assign_multiple_second(self): def do_assign_multiple_second(self):
assign_multiple(self.file_map['tei-multiple'], self.file_map['mwes-2'], self.file_map['tei-multiple-ids-2']) min_other_id = self._find_min_other_id('structures-new')
assign_multiple(self.file_map['tei-multiple'], self.file_map['mwes-2'], self.file_map['tei-multiple-ids-2'], min_other_id)
def do_create_structures(self): def do_create_structures(self):
input_file_name = self.file_map['structures-old'] input_file_name = self.file_map['structures-old']
@ -172,5 +183,4 @@ class Pipeline:
shutil.copyfile(self.file_map[file_key], file_name) shutil.copyfile(self.file_map[file_key], file_name)
def cleanup(self): def cleanup(self):
print(self.tmp_directory)
shutil.rmtree(self.tmp_directory, True) shutil.rmtree(self.tmp_directory, True)