{
  "name": "WF02-\uc120\ud589\uae30\uc220\uac80\uc0c9",
  "id": "iFAXSkfG5Rh0b8Qh",
  "description": "KIPRIS API \uae30\ubc18 \uc120\ud589\uae30\uc220 \uac80\uc0c9 \ubc0f \ucee8\ud14d\uc2a4\ud2b8 \uc0dd\uc131 \uc6cc\ud06c\ud50c\ub85c\uc6b0",
  "active": false,
  "nodes": [
    {
      "id": "webhook-trigger",
      "name": "\uc120\ud589\uae30\uc220 \uac80\uc0c9 Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "wf02-prior-art-search",
        "responseMode": "lastNode"
      }
    },
    {
      "id": "prepare-query",
      "name": "\uac80\uc0c9 \ucffc\ub9ac \uc900\ube44",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "parameters": {
        "jsCode": "// \uc120\ud589\uae30\uc220 \uac80\uc0c9\uc744 \uc704\ud55c \ucffc\ub9ac \uc900\ube44\nconst data = $input.first().json;\n\n// \uac80\uc0c9 \ud0a4\uc6cc\ub4dc \ucd94\ucd9c\nconst keywords = data.keywords || [];\nconst title = data.invention_title || '';\nconst technicalField = data.technical_field || '';\n\n// KIPRIS \uac80\uc0c9 \ucffc\ub9ac \uc0dd\uc131\nconst searchQuery = {\n  patent_id: data.patent_id,\n  invention_title: title,\n  keywords: keywords.slice(0, 5),\n  ipc_codes: data.suggested_ipc || [],\n  search_terms: `${title} ${keywords.join(' ')}`.trim(),\n  technical_field: technicalField,\n  original_data: data\n};\n\nreturn [{ json: searchQuery }];"
      }
    },
    {
      "id": "check-api-key",
      "name": "API \ud0a4 \ud655\uc778",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        440,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "api-key-check",
              "leftValue": "={{ $vars.KIPRIS_API_KEY }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "kipris-api",
      "name": "KIPRIS API \ud638\ucd9c",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        -100
      ],
      "parameters": {
        "method": "GET",
        "url": "http://plus.kipris.or.kr/kipo-api/kipi/patUtiModInfoSearchSevice/getWordSearch",
        "qs": {
          "word": "={{ $json.search_terms }}",
          "patent": "true",
          "utility": "true",
          "numOfRows": "10",
          "pageNo": "1",
          "ServiceKey": "={{ $vars.KIPRIS_API_KEY }}"
        },
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      }
    },
    {
      "id": "mock-data",
      "name": "Mock \uc120\ud589\uae30\uc220 \ub370\uc774\ud130",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        100
      ],
      "parameters": {
        "jsCode": "// KIPRIS API \ud0a4\uac00 \uc5c6\uc744 \uacbd\uc6b0 Mock \ub370\uc774\ud130 \ubc18\ud658\nconst data = $input.first().json;\n\nconst mockPriorArts = [\n  {\n    applicationNumber: '10-2023-0001234',\n    inventionTitle: `${data.invention_title || '\uad00\ub828 \uae30\uc220'} \uad00\ub828 \uc120\ud589\uae30\uc220 1`,\n    applicantName: '\uc0bc\uc131\uc804\uc790 \uc8fc\uc2dd\ud68c\uc0ac',\n    ipcCode: data.ipc_codes?.[0] || 'G06F',\n    applicationDate: '2023-01-15',\n    relevanceScore: 0.85,\n    abstract: '\ubcf8 \ubc1c\uba85\uc740 \uad00\ub828 \uae30\uc220 \ubd84\uc57c\uc758 \uc120\ud589\uae30\uc220\ub85c\uc11c, \uc720\uc0ac\ud55c \uae30\uc220\uc801 \ud2b9\uc9d5\uc744 \uac00\uc9c0\uace0 \uc788\uc2b5\ub2c8\ub2e4.'\n  },\n  {\n    applicationNumber: '10-2022-0005678',\n    inventionTitle: `${data.invention_title || '\uad00\ub828 \uae30\uc220'} \uad00\ub828 \uc120\ud589\uae30\uc220 2`,\n    applicantName: 'LG\uc804\uc790 \uc8fc\uc2dd\ud68c\uc0ac',\n    ipcCode: data.ipc_codes?.[0] || 'G06F',\n    applicationDate: '2022-06-20',\n    relevanceScore: 0.72,\n    abstract: '\ubcf8 \ubc1c\uba85\uc740 \uc720\uc0ac\ud55c \uacfc\uc81c\ub97c \ud574\uacb0\ud558\uae30 \uc704\ud55c \ub2e4\ub978 \uc811\uadfc \ubc29\uc2dd\uc744 \uc81c\uc2dc\ud569\ub2c8\ub2e4.'\n  },\n  {\n    applicationNumber: '10-2021-0009012',\n    inventionTitle: `${data.invention_title || '\uad00\ub828 \uae30\uc220'} \uad00\ub828 \uc120\ud589\uae30\uc220 3`,\n    applicantName: '\ud55c\uad6d\uc804\uc790\ud1b5\uc2e0\uc5f0\uad6c\uc6d0',\n    ipcCode: data.ipc_codes?.[1] || 'G06N',\n    applicationDate: '2021-12-05',\n    relevanceScore: 0.65,\n    abstract: '\ubcf8 \ubc1c\uba85\uc740 \uae30\ucd08 \uae30\uc220\ub85c\uc11c \ubcf8 \ubc1c\uba85\uc758 \ubc30\uacbd\uc774 \ub418\ub294 \uae30\uc220\uc744 \uc81c\uacf5\ud569\ub2c8\ub2e4.'\n  }\n];\n\nreturn [{\n  json: {\n    ...data,\n    prior_arts: mockPriorArts,\n    search_status: 'mock',\n    search_date: new Date().toISOString()\n  }\n}];"
      }
    },
    {
      "id": "parse-xml",
      "name": "XML \ud30c\uc2f1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        880,
        -100
      ],
      "parameters": {
        "jsCode": "// KIPRIS API XML \uc751\ub2f5 \ud30c\uc2f1\nconst data = $input.first().json;\nconst originalData = data.original_data || data;\n\n// XML \ud30c\uc2f1 \ub85c\uc9c1 (\uc2e4\uc81c KIPRIS API \uc751\ub2f5 \uad6c\uc870\uc5d0 \ub9de\uac8c \uc870\uc815 \ud544\uc694)\nlet priorArts = [];\n\ntry {\n  const response = data.body || data;\n  // KIPRIS API \uc751\ub2f5 \uad6c\uc870\uc5d0 \ub530\ub978 \ud30c\uc2f1\n  if (response && response.response && response.response.body) {\n    const items = response.response.body.items?.item || [];\n    priorArts = (Array.isArray(items) ? items : [items]).map((item, idx) => ({\n      applicationNumber: item.applicationNumber || '',\n      inventionTitle: item.inventionTitle || '',\n      applicantName: item.applicantName || '',\n      ipcCode: item.ipcNumber || '',\n      applicationDate: item.applicationDate || '',\n      relevanceScore: 0.8 - (idx * 0.1),\n      abstract: item.astrtCont || ''\n    }));\n  }\n} catch (e) {\n  // \ud30c\uc2f1 \uc2e4\ud328 \uc2dc \ube48 \ubc30\uc5f4\n  priorArts = [];\n}\n\nreturn [{\n  json: {\n    ...originalData,\n    prior_arts: priorArts,\n    search_status: 'kipris',\n    search_date: new Date().toISOString()\n  }\n}];"
      }
    },
    {
      "id": "merge-results",
      "name": "\uacb0\uacfc \ubcd1\ud569",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1100,
        0
      ],
      "parameters": {
        "mode": "passThrough"
      }
    },
    {
      "id": "calc-relevance",
      "name": "\uad00\ub828\ub3c4 \uc810\uc218 \uacc4\uc0b0",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1320,
        0
      ],
      "parameters": {
        "jsCode": "// \uc120\ud589\uae30\uc220 \uad00\ub828\ub3c4 \uc810\uc218 \uacc4\uc0b0 \ubc0f \uc815\ub82c\nconst data = $input.first().json;\nconst priorArts = data.prior_arts || [];\nconst keywords = data.keywords || [];\n\n// \ud0a4\uc6cc\ub4dc \ub9e4\uce6d \uae30\ubc18 \uad00\ub828\ub3c4 \uc7ac\uacc4\uc0b0\nconst scoredArts = priorArts.map(art => {\n  let score = art.relevanceScore || 0.5;\n  \n  // \ud0a4\uc6cc\ub4dc \ub9e4\uce6d \ubcf4\ub108\uc2a4\n  const artText = `${art.inventionTitle} ${art.abstract}`.toLowerCase();\n  keywords.forEach(keyword => {\n    if (artText.includes(keyword.toLowerCase())) {\n      score += 0.05;\n    }\n  });\n  \n  return {\n    ...art,\n    relevanceScore: Math.min(score, 1.0)\n  };\n});\n\n// \uad00\ub828\ub3c4 \uc21c\uc73c\ub85c \uc815\ub82c\nconst sortedArts = scoredArts.sort((a, b) => b.relevanceScore - a.relevanceScore);\n\nreturn [{\n  json: {\n    ...data,\n    prior_arts: sortedArts,\n    prior_arts_count: sortedArts.length\n  }\n}];"
      }
    },
    {
      "id": "build-context",
      "name": "\ucee8\ud14d\uc2a4\ud2b8 \uc0dd\uc131",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1540,
        0
      ],
      "parameters": {
        "jsCode": "// \uba85\uc138\uc11c \uc0dd\uc131\uc744 \uc704\ud55c \uc120\ud589\uae30\uc220 \ucee8\ud14d\uc2a4\ud2b8 \uad6c\uc131\nconst data = $input.first().json;\nconst priorArts = data.prior_arts || [];\n\n// \uc120\ud589\uae30\uc220 \uc694\uc57d \ud14d\uc2a4\ud2b8 \uc0dd\uc131\nconst priorArtSummary = priorArts.slice(0, 5).map((art, idx) => \n  `[\uc120\ud589\uae30\uc220 ${idx + 1}] ${art.inventionTitle}\\n` +\n  `  - \ucd9c\uc6d0\ubc88\ud638: ${art.applicationNumber}\\n` +\n  `  - \ucd9c\uc6d0\uc778: ${art.applicantName}\\n` +\n  `  - IPC: ${art.ipcCode}\\n` +\n  `  - \uad00\ub828\ub3c4: ${(art.relevanceScore * 100).toFixed(0)}%\\n` +\n  `  - \uc694\uc57d: ${art.abstract}`\n).join('\\n\\n');\n\n// \ucc28\ubcc4\ud654 \ud3ec\uc778\ud2b8 \ubd84\uc11d\nconst differentiationPoints = [\n  '\ubcf8 \ubc1c\uba85\ub9cc\uc758 \uace0\uc720\ud55c \uae30\uc220\uc801 \ud2b9\uc9d5',\n  '\uc120\ud589\uae30\uc220 \ub300\ube44 \uac1c\uc120\ub41c \ud6a8\uacfc',\n  '\uc0c8\ub85c\uc6b4 \uad6c\uc131\uc694\uc18c \ub610\ub294 \uc870\ud569'\n];\n\nconst context = {\n  patent_id: data.patent_id,\n  invention_title: data.invention_title || data.original_data?.invention_title,\n  technical_field: data.technical_field || data.original_data?.technical_field,\n  problem_to_solve: data.original_data?.problem_to_solve,\n  solution_description: data.original_data?.solution_description,\n  advantages: data.original_data?.advantages,\n  keywords: data.keywords,\n  suggested_ipc: data.ipc_codes || data.suggested_ipc,\n  prior_arts: priorArts,\n  prior_art_summary: priorArtSummary,\n  prior_arts_count: priorArts.length,\n  differentiation_points: differentiationPoints,\n  search_status: data.search_status,\n  search_date: data.search_date\n};\n\nreturn [{ json: context }];"
      }
    },
    {
      "id": "set-output",
      "name": "\ucd9c\ub825 \ub370\uc774\ud130 \uc124\uc815",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1760,
        0
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "status",
              "name": "status",
              "value": "prior_art_complete",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true
      }
    },
    {
      "id": "convert-to-json-file",
      "name": "\uc120\ud589\uae30\uc220 JSON \ubcc0\ud658",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1980,
        0
      ],
      "parameters": {
        "jsCode": "// \uc120\ud589\uae30\uc220 \uac80\uc0c9 \uacb0\uacfc\ub97c JSON \ud30c\uc77c\ub85c \ubcc0\ud658\nconst data = $input.first().json;\n\nconst priorArtReport = {\n  patent_id: data.patent_id,\n  invention_title: data.invention_title,\n  search_date: data.search_date || new Date().toISOString(),\n  search_status: data.search_status,\n  prior_arts_count: data.prior_arts_count,\n  prior_arts: data.prior_arts,\n  prior_art_summary: data.prior_art_summary,\n  differentiation_points: data.differentiation_points\n};\n\nreturn [{\n  json: data,\n  binary: {\n    data: Buffer.from(JSON.stringify(priorArtReport, null, 2)).toString('base64')\n  }\n}];"
      }
    },
    {
      "id": "google-drive-upload-prior-art",
      "name": "Google Drive \uc5c5\ub85c\ub4dc (\uc120\ud589\uae30\uc220)",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2200,
        0
      ],
      "parameters": {
        "operation": "upload",
        "folderId": {
          "__rl": true,
          "value": "={{ $vars.GOOGLE_DRIVE_PRIOR_ART_FOLDER_ID }}",
          "mode": "id"
        },
        "name": "=\uc120\ud589\uae30\uc220_{{ $json.patent_id }}_{{ $now.format('yyyyMMdd') }}.json",
        "options": {
          "mimeType": "application/json"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "google-sheets-update-prior-art",
      "name": "Google Sheets \uc120\ud589\uae30\uc220 URL \uc5c5\ub370\uc774\ud2b8",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        2420,
        0
      ],
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "={{ $vars.GOOGLE_SHEETS_TRACKING_ID }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "\uc81c\ucd9c\uc774\ub825",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Patent ID": "={{ $json.patent_id }}",
            "\uc120\ud589\uae30\uc220 URL": "={{ $('Google Drive \uc5c5\ub85c\ub4dc (\uc120\ud589\uae30\uc220)').item.json.webViewLink }}"
          }
        },
        "options": {
          "updateLookupColumn": "Patent ID"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "set-output-with-urls",
      "name": "URL \ud3ec\ud568 \ucd9c\ub825 \uc124\uc815",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2640,
        0
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "prior_art_drive_url",
              "name": "prior_art_drive_url",
              "value": "={{ $('Google Drive \uc5c5\ub85c\ub4dc (\uc120\ud589\uae30\uc220)').item.json.webViewLink }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true
      }
    },
    {
      "id": "call-wf03",
      "name": "WF03 \uba85\uc138\uc11c\uc0dd\uc131 \ud638\ucd9c",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2860,
        0
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.N8N_WEBHOOK_URL }}/wf03-generate-patent-spec",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "\uc120\ud589\uae30\uc220 \uac80\uc0c9 Webhook": {
      "main": [
        [
          {
            "node": "\uac80\uc0c9 \ucffc\ub9ac \uc900\ube44",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\uac80\uc0c9 \ucffc\ub9ac \uc900\ube44": {
      "main": [
        [
          {
            "node": "API \ud0a4 \ud655\uc778",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API \ud0a4 \ud655\uc778": {
      "main": [
        [
          {
            "node": "KIPRIS API \ud638\ucd9c",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mock \uc120\ud589\uae30\uc220 \ub370\uc774\ud130",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "KIPRIS API \ud638\ucd9c": {
      "main": [
        [
          {
            "node": "XML \ud30c\uc2f1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "XML \ud30c\uc2f1": {
      "main": [
        [
          {
            "node": "\uad00\ub828\ub3c4 \uc810\uc218 \uacc4\uc0b0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mock \uc120\ud589\uae30\uc220 \ub370\uc774\ud130": {
      "main": [
        [
          {
            "node": "\uad00\ub828\ub3c4 \uc810\uc218 \uacc4\uc0b0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\uad00\ub828\ub3c4 \uc810\uc218 \uacc4\uc0b0": {
      "main": [
        [
          {
            "node": "\ucee8\ud14d\uc2a4\ud2b8 \uc0dd\uc131",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ucee8\ud14d\uc2a4\ud2b8 \uc0dd\uc131": {
      "main": [
        [
          {
            "node": "\ucd9c\ub825 \ub370\uc774\ud130 \uc124\uc815",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ucd9c\ub825 \ub370\uc774\ud130 \uc124\uc815": {
      "main": [
        [
          {
            "node": "\uc120\ud589\uae30\uc220 JSON \ubcc0\ud658",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\uc120\ud589\uae30\uc220 JSON \ubcc0\ud658": {
      "main": [
        [
          {
            "node": "Google Drive \uc5c5\ub85c\ub4dc (\uc120\ud589\uae30\uc220)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive \uc5c5\ub85c\ub4dc (\uc120\ud589\uae30\uc220)": {
      "main": [
        [
          {
            "node": "Google Sheets \uc120\ud589\uae30\uc220 URL \uc5c5\ub370\uc774\ud2b8",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets \uc120\ud589\uae30\uc220 URL \uc5c5\ub370\uc774\ud2b8": {
      "main": [
        [
          {
            "node": "URL \ud3ec\ud568 \ucd9c\ub825 \uc124\uc815",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "URL \ud3ec\ud568 \ucd9c\ub825 \uc124\uc815": {
      "main": [
        [
          {
            "node": "WF03 \uba85\uc138\uc11c\uc0dd\uc131 \ud638\ucd9c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "version": "1.3.0",
    "created": "2026-01-10",
    "updated": "2026-01-14",
    "project": "MAIPatent",
    "workflow_sequence": 2,
    "next_workflow": "WF03-patent-generation",
    "trigger_connection": "HTTP Request to WF03 Webhook",
    "kipris_api_status": "active_with_fallback",
    "kipris_api_variable": "$vars.KIPRIS_API_KEY",
    "google_drive_folder": "02_\uc120\ud589\uae30\uc220",
    "note": "$env -> $vars \ubcc0\uacbd (n8n Cloud \ud658\uacbd\ubcc0\uc218 \uc811\uadfc \uc81c\ud55c \ud574\uacb0)"
  }
}