From 217ec6a2c04dcae7f396f0ba3d0ca8cd6a59f65e Mon Sep 17 00:00:00 2001 From: chrys87 Date: Thu, 22 Sep 2016 16:50:26 +0200 Subject: [PATCH] Update punctuationManager.py --- src/fenrir-package/core/punctuationManager.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fenrir-package/core/punctuationManager.py b/src/fenrir-package/core/punctuationManager.py index 2bd78be8..e8077c7a 100644 --- a/src/fenrir-package/core/punctuationManager.py +++ b/src/fenrir-package/core/punctuationManager.py @@ -30,18 +30,19 @@ class punctuationManager(): def shutdown(self): pass def removeUnused(self, text): - resultText = text.translate(text.maketrans(string.punctuation, ' '*len(string.punctuation))) - return resultText + return text.translate(text.maketrans(string.punctuation, ' '*len(string.punctuation))) def useCustomDict(self, text, customDict): resultText = text - for key,item in customDict.items(): - resultText = resultText.replace(str(key),str(item)) + if customDict: + for key,item in customDict.items(): + resultText = resultText.replace(str(key),str(item)) return resultText def usePunctuationDict(self, text, punctuationDict, punctuation): resultText = str(text) - for key,item in punctuationDict.items(): - if key in punctuation: - resultText = resultText.replace(str(key),' ' +str(item) +' ') + if punctuationDict and punctuation != '': + for key,item in punctuationDict.items(): + if key in punctuation: + resultText = resultText.replace(str(key),' ' +str(item) +' ') return resultText def proceedPunctuation(self, text, ignoreLevel=False):