이 문서는 https://tiddlywiki.com/languages/ko-KR/에서 티들리위키의 정적 HTML 표현의 일부입니다

makepatches and applypatches Operator (Examples)

2023년 3월 4일 오후 4:03

These examples use the example texts in Hamlet, taken from https://neil.fraser.name/software/diff_match_patch/demos/patch.html

Shakespeare's originalHamlet: Do you see yonder cloud that's almost in shape of a camel? Polonius: By the mass, and 'tis like a camel, indeed. Hamlet: Methinks it is like a weasel. Polonius: It is backed like a weasel. Hamlet: Or like a whale? Polonius: Very like a whale. – Shakespeare
Modern EnglishHamlet: Do you see the cloud over there that's almost the shape of a camel? Polonius: By golly, it is like a camel, indeed. Hamlet: I think it looks like a weasel. Polonius: It is shaped like a weasel. Hamlet: Or like a whale? Polonius: It's totally like a whale. – Shakespeare
Trekkie's CopyKirk: Do you see yonder cloud that's almost in shape of a Klingon? Spock: By the mass, and 'tis like a Klingon, indeed. Kirk: Methinks it is like a Vulcan. Spock: It is backed like a Vulcan. Kirk: Or like a Romulan? Spock: Very like a Romulan. – Trekkie

Use makepatches to generate the set of patches to transform Shakepeare's original into Modern English:

[{Hamlet##Shakespeare-old}makepatches{Hamlet##Shakespeare-new}]

Use applypatches to apply the patches to Shakespeare's original text:

[{Hamlet##Shakespeare-old}makepatches{Hamlet##Shakespeare-new}] :map[{Hamlet##Shakespeare-old}applypatches<currentTiddler>]

In the above example, the Map Filter Run Prefix is used to pass the patches information as a parameter to applypatches. Inside :map, currentTiddler is set to the input title (i.e. the previously generated patches).

The patch information from the Shakepeare texts can also be used to transform the Trekkie's Copy to a Modern English version:

[{Hamlet##Shakespeare-old}makepatches{Hamlet##Shakespeare-new}] :map[{Hamlet##Trekkie-old}applypatches<currentTiddler>]

The above examples used the character mode of makepatches. The word mode yields very similar results in this case, even when applied to the Trekkie's Copy.

[{Hamlet##Shakespeare-old}makepatches:words{Hamlet##Shakespeare-new}]

[{Hamlet##Shakespeare-old}makepatches:words{Hamlet##Shakespeare-new}] :map[{Hamlet##Trekkie-old}applypatches<currentTiddler>]

The lines mode doesn't work as well in this application:

[{Hamlet##Shakespeare-old}makepatches:lines{Hamlet##Shakespeare-new}]

[{Hamlet##Shakespeare-old}makepatches:lines{Hamlet##Shakespeare-new}] :map[{Hamlet##Trekkie-old}applypatches<currentTiddler>]

It is better suited as a very fast algorithm to detect line-wise incremental changes to texts and store only the changes instead of multiple versions of the whole texts.