2 changes: 1 addition & 1 deletion python/plugins/processing/otb/OTBAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def defineCharacteristicsFromFile(self):
self.name = dom_model.find('longname').text
self.group = dom_model.find('group').text

ProcessingLog.addToLog(ProcessingLog.LOG_INFO, "Reading parameters for %s" % self.appkey)
#ProcessingLog.addToLog(ProcessingLog.LOG_INFO, "Reading parameters for %s" % self.appkey)

rebu = None
the_result = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(dp0
S'ALG_DESC'
p1
VThis algorithm is made to perform powerfull batch search and replace operations inside a string.\u000a\u000aThe user passes a string to be modified, and a string representation of a Python dictionnary with keys as strings to search and values as keys to replace.\u000a\u000aWhen running the algorithm, the following example input string and dictionnary is proposed by default to help the user understand the concept:\u000a\u000ainput string = "John has a blue car."\u000aReplace dictionnary = {"John": "Mary", "blue": "red", "car": "bike"}\u000aGenerated output = "Mary has a red bike."\u000a\u000a\u000a
p2
sS'replaceDict'
p3
VA string representation of a Python dictionnary. \u000a\u000aSimple example : {"John": "Mary", "blue": "red"}\u000awill replace all the occurences of "John" by "Mary" and all the blue by "red" .\u000a\u000aThe Python module "re" is used to give the power of regular expressions. So you can use complex search string and replace string with regexp syntax. The following example shows how to parse a date :\u000a\u000ainput = "2014-03-27"\u000areplace dictionnary = {r"([0-9]{4})-([0-9]{2})-([0-9]{2})" : r"\u005c3/\u005c2/\u005c1" }\u000aoutput = "27/03/2014"\u000a
p4
sS'verbose'
p5
VIf True, the processing dialog will print the input, replace dictionnary and the output in the message box.
p6
sS'ALG_CREATOR'
p7
VMicha�l DOUCHIN ( 3liz.com )\u000a@kimaidou
p8
sS'ignore_case'
p9
VIf True, the search and replace will be case insensitive. Which means that if you search "Bob" and want to replace it with "John", all the "bob" or "boB" will also be replaced.
p10
sS'ALG_HELP_CREATOR'
p11
VMicha�l DOUCHIN ( 3liz.com )\u000a@kimaidou
p12
sS'output'
p13
VThe modified string with all search strings replaced by the given values.
p14
sS'input'
p15
VThe string which must be modified by replacing string(s) by other string(s)
p16
s.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
##[3liz]=group
##Batch string replace via regex dictionnary=name
##input=string John has a blue car.
##ignore_case=boolean True
##verbose=boolean False
##replaceDict=string {'John': 'Mary', 'blue': 'red', 'car': 'bike'}
##output=output string

import ast
import re

if not input: input = ''
if not replaceDict: replaceDict = '{}'

if verbose:
progress.setText('INPUT = \n%s\n' % input)
progress.setText('REPLACE DICT = \n%s\n' % replaceDict)

reOption = re.MULTILINE
if ignore_case:
reOption = reOption|re.IGNORECASE

# Set output string
output = input

# Get replaceDict string
# and convert it to dict
d = ast.literal_eval(replaceDict)

# Only replace strings if d is a dict
if d and isinstance(d, dict):
for k, v in d.items():
# Replace search string by value
r = re.compile(k, reOption)
output = r.sub(v, output)
else:
progress.setText('ERROR - Replace dict does not represent a dictionnary. String not changed !' )

if verbose:
progress.setText('OUTPUT = \n%s\n' % output)