You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PaddleSpeech/tools/watermark.py

21 lines
709 B

# add watermark for text
def watermark(content, pattern):
m = list(zip(pattern * (len(content) // len(pattern) + 1), content))
return ''.join([x for t in m
for x in t] + [pattern[len(content) % len(pattern)]])
# remove cyclic watermark in text
def iwatermark(content):
e = [x for i, x in enumerate(content) if i % 2 == 0]
o = [x for i, x in enumerate(content) if i % 2 != 0]
for i in range(1, len(e) // 2 + 1):
if e[i:] == e[:-i]:
return ''.join(o)
return ''.join(e)
if __name__ == "__main__":
print(watermark('跟世龙对齐 Triton 开发计划', 'hbzs'))
print(iwatermark('h跟b世z龙s对h齐b zTsrhibtzosnh b开z发s计h划b'))