n8nのワークフロー、あれは沼です。気をつけないと時間が溶けてしまいます。
考え出すとキリが無いため、いっそのこととClaudeとGeminiという下請けに相談すると「はいよろこんで」となりました。
ええのかそれで…
実はn8nワークフローは内部的にJSONのコードで保持しており、普通にダウンロードできるので、これをClaudeやGeminiの見えるところにおいてから、それをClaudeに読み込ませました。その上でGoogleスプレッドシートを使っているので、それをスクショしてテーブル関係も理解してもらってから作業スタート。
- 一応設定していたクールタイム(記事取得後一定時間は取りに行かないようにする)はまだ機能してなかったのでどうしたら良いのか?
- クールタイムチェックのフィルターノードを追加し、該当するサイトはフィード取得スキップすればいいじゃない
- 複数サイトから同内容のものが入ってくるようになってきたので、内容面での重複を排除したい
- 一旦文字列類似度(Levenshtein距離など)を使って類似性をざっくりチェックして、類似度の高いものはまずスキップ
- さらにAIで疑わしいもののを判定させる
と、それなりの提案を出してきたので採用、実装させたところ今のところスッキリしたみたいでよかったです。
ただ、これをやり出すと発生するのがCodeノードが増えて行きかねないこと。そしてこれ…
1
2
3
4
5
6
7
8
9
10
11
12
13
| {
"parameters": {
"jsCode": "// 簡易類似度チェック - タイトルとキーワードベース\nconst currentItems = items;\nconst duplicates = [];\nconst unique = [];\n\nfor (let i = 0; i < currentItems.length; i++) {\n const currentItem = currentItems[i];\n const currentTitle = currentItem.json.output || '';\n \n let isDuplicate = false;\n \n // 同じバッチ内での重複チェック\n for (let j = 0; j < i; j++) {\n const compareItem = currentItems[j];\n const compareTitle = compareItem.json.output || '';\n \n // タイトルの類似度チェック(簡易版)\n const similarity = calculateSimilarity(currentTitle, compareTitle);\n \n if (similarity > 0.7) { // 70%以上類似\n isDuplicate = true;\n break;\n }\n }\n \n if (isDuplicate) {\n duplicates.push(currentItem);\n } else {\n unique.push(currentItem);\n }\n}\n\n// 文字列類似度計算(簡易版)\nfunction calculateSimilarity(str1, str2) {\n if (!str1 || !str2) return 0;\n \n // 正規化\n const s1 = str1.toLowerCase().replace(/[^\\w\\s]/g, '').trim();\n const s2 = str2.toLowerCase().replace(/[^\\w\\s]/g, '').trim();\n \n if (s1 === s2) return 1;\n \n // 単語ベース類似度\n const words1 = s1.split(/\\s+/);\n const words2 = s2.split(/\\s+/);\n \n const commonWords = words1.filter(word => words2.includes(word));\n const totalWords = Math.max(words1.length, words2.length);\n \n return totalWords > 0 ? commonWords.length / totalWords : 0;\n}\n\nreturn unique;"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-384,
-240
],
"id": "simple-similarity-check",
"name": "簡易類似度チェック"
},
|
ノーコードでやるのが醍醐味だったろうに、どんどんコード化していく本末転倒状態w
まあ、これでかなり重複記事も減らせて満足です。