Skip to content

diffの適用をロバストに #196

Description

@na-trium-144

空白の違い、強調の有無やコードブロックの引用符の有無などの違いを無視して適用するようにする。

diff-match-patchを使うといいらしい (ってgeminiが言ってた)

const DiffMatchPatch = require('diff-match-patch');
const dmp = new DiffMatchPatch();

// match_threshold: 0.0は完全一致、1.0は全く無関係でもマッチ
dmp.Match_Threshold = 0.5; 
// match_distance: どのくらい離れた場所まで探しに行くか
dmp.Match_Distance = 1000; 

const originalText = "明日の会議は、**10時**から開始します。";
const searchBlock = "明日の会議は、10時から開始"; // ** が抜けている

const pos = dmp.match_main(originalText, searchBlock, 0);

if (pos !== -1) {
  console.log(`マッチした開始位置: ${pos}`);
  // ここで置換処理を行う
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions