parse_article_links
Extracts all legal references and citations within a specific article of Korean law, enabling analysis of cross-references.
Instructions
[분석] 조문 내 법령 참조 추출.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mst | No | 법령일련번호 | |
| lawId | No | 법령ID | |
| jo | Yes | 조문 번호 (예: '제38조') | |
| efYd | No | 시행일자 (YYYYMMDD) | |
| apiKey | No | 법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달 |
Implementation Reference
- src/tools/article-link-parser.ts:23-77 (handler)The main handler function for the parse_article_links tool. Fetches law article text via getLawText, then extracts inter-article references (제X조, 같은 조, 전항, 이 법 etc.) and formats them as a numbered list.
export async function parseArticleLinks( apiClient: LawApiClient, input: ParseArticleLinksInput ): Promise<{ content: Array<{ type: string, text: string }>, isError?: boolean }> { try { // 1. 조문 조회 const articleResult = await getLawText(apiClient, { mst: input.mst, lawId: input.lawId, jo: input.jo, efYd: input.efYd, apiKey: input.apiKey }) if (articleResult.isError || articleResult.content.length === 0) { return { content: [{ type: "text", text: "조문을 찾을 수 없습니다." }], isError: true } } const articleText = articleResult.content[0].text // 2. 조문 내 참조 파싱 const references = extractArticleReferences(articleText) // 3. 결과 포맷 let resultText = `🔗 조문 내 참조 링크 (${references.length}개)\n\n` if (references.length === 0) { resultText += "이 조문에는 다른 조문을 참조하는 내용이 없습니다.\n" } else { references.forEach((ref, idx) => { resultText += `${idx + 1}. ${ref.text}\n` resultText += ` → 참조: ${ref.reference}\n` if (ref.context) { resultText += ` 문맥: "${ref.context}"\n` } resultText += `\n` }) } return { content: [{ type: "text", text: truncateResponse(resultText) }] } } catch (error) { return formatToolError(error, "parse_article_links") } } - Zod schema defining inputs: mst (optional), lawId (optional, at least one required), jo (required, e.g. '제38조'), efYd (optional date), apiKey (optional).
export const ParseArticleLinksSchema = z.object({ mst: z.string().optional().describe("법령일련번호"), lawId: z.string().optional().describe("법령ID"), jo: z.string().describe("조문 번호 (예: '제38조')"), efYd: z.string().optional().describe("시행일자 (YYYYMMDD)"), apiKey: z.string().optional().describe("법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달") }).refine(data => data.mst || data.lawId, { message: "mst 또는 lawId 중 하나는 필수입니다" }) - src/tool-registry.ts:246-251 (registration)Registration entry mapping the name 'parse_article_links' to ParseArticleLinksSchema and the parseArticleLinks handler function.
{ name: "parse_article_links", description: "[분석] 조문 내 법령 참조 추출.", schema: ParseArticleLinksSchema, handler: parseArticleLinks }, - Helper function extractContext that extracts surrounding context around a regex match within the article text.
/** * 매칭된 텍스트 주변 문맥 추출 */ function extractContext(text: string, index: number, contextLength: number): string { const start = Math.max(0, index - contextLength) const end = Math.min(text.length, index + contextLength) let context = text.substring(start, end).trim() // 줄바꿈 제거 context = context.replace(/\n/g, " ") return context } - Helper function extractArticleReferences that parses article text for Korean legal references: 제X조, 같은/이/당해 조, 전/다음 항/호, 이 법/영/규칙/령 patterns.
function extractArticleReferences(text: string): Array<{ text: string reference: string context?: string }> { const references: Array<{ text: string, reference: string, context?: string }> = [] // 패턴 1: "제X조" const articlePattern = /제(\d+)조(의(\d+))?/g let match = articlePattern.exec(text) while (match) { const fullMatch = match[0] const context = extractContext(text, match.index, 30) references.push({ text: fullMatch, reference: fullMatch, context }) match = articlePattern.exec(text) } // 패턴 2: "같은 조", "이 조", "당해 조" const sameArticlePattern = /(같은|이|당해|해당)\s*조/g match = sameArticlePattern.exec(text) while (match) { const fullMatch = match[0] const context = extractContext(text, match.index, 30) references.push({ text: fullMatch, reference: "현재 조문", context }) match = sameArticlePattern.exec(text) } // 패턴 3: "전항", "전각호" const prevPattern = /(전|다음)\s*(항|각\s*호|호)/g match = prevPattern.exec(text) while (match) { const fullMatch = match[0] const context = extractContext(text, match.index, 30) references.push({ text: fullMatch, reference: match[1] === "전" ? "이전 항/호" : "다음 항/호", context }) match = prevPattern.exec(text) } // 패턴 4: "이 법", "이 영", "이 규칙" const lawPattern = /이\s*(법|영|규칙|령)/g match = lawPattern.exec(text) while (match) { const fullMatch = match[0] const context = extractContext(text, match.index, 30) references.push({ text: fullMatch, reference: "현행 법령 전체", context }) match = lawPattern.exec(text) } return references }