古いバージョンのテキスト (text1) から一連の xml タグを復元し、それらを同じテキスト (text2) の最新バージョンに埋め込もうとしています。
例えば:
text1 = "this <verb>is</verb> an example of a sentence"
text2 = "this is an <noun>example</noun> of a <noun>sentence</noun>"
desired_output = "this <verb>is</verb> an <noun>example</noun> of a <noun>sentence</noun>"
今のところ、difflib を使用して両方のバージョンをコードで別々に出力することができました。
diff = difflib.unified_diff(text1, text2, lineterm='')
print ('\n'.join(list(diff)))
これにより、次のことが得られます。
- this <verb>is</verb> an example of a sentence
+ this is an <noun>example</noun> of a <noun>sentence</noun>
-
私の質問は、文字列を文字列に埋め込むにはどうすればよい+
ですか?