Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
Added code to turn a network using German font names to an English sp…
Browse files Browse the repository at this point in the history
…eaking one
  • Loading branch information
seuretm committed Jun 19, 2019
1 parent 13aebab commit 1e14917
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ocrd_typegroups_classifier/data/classmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ def __init__(self, basemap):
def forget_class(self, target):
del self.id2cl[self.cl2id[target]]
del self.cl2id[target]

def translate(self, dictionary):
for name in self.cl2id:
if not name in dictionary:
continue
n = self.cl2id[name]
del self.cl2id[name]
self.cl2id[dictionary[name]] = n
self.id2cl[n] = dictionary[name]

def get_target_transform(self, dataset_classes):
""" Creates a transform from a map (class name to id) to the
Expand Down
20 changes: 20 additions & 0 deletions translate-model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ocrd_typegroups_classifier.typegroups_classifier import TypegroupsClassifier


translation = {
'griechisch': 'greek',
'hebräisch': 'hebrew',
'kursiv': 'italic',
'andere_schrift': 'other_font',
'nicht_schrift': 'not_a_font'
}


tgc = TypegroupsClassifier.load('ocrd_typegroups_classifier/models/classifier.tgc')
# backup
tgc.save('ocrd_typegroups_classifier/models/classifier-german-speaking.tgc')

print(tgc.classMap)
tgc.classMap.translate(translation)
print(tgc.classMap)
tgc.save('ocrd_typegroups_classifier/models/classifier.tgc')

0 comments on commit 1e14917

Please sign in to comment.