Files
xSaherelmWorkspace/Documents/Docs/Developer/XOpenDocument Content Extractor.html

1029 lines
45 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>مستند پیاده‌سازی XOpenDocumentFileContentExtractor | پروژه xAiApi</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
:root {
--primary: #1a365d;
--primary-light: #2c5282;
--accent: #c9a961;
--accent-dark: #a8893f;
--bg: #faf9f6;
--card-bg: #ffffff;
--text: #1a202c;
--text-muted: #4a5568;
--border: #e2e8f0;
--success: #38a169;
--danger: #e53e3e;
--warning: #dd6b20;
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Vazirmatn', Tahoma, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.9;
font-size: 15px;
padding: 30px 15px;
}
.document-container {
max-width: 950px;
margin: 0 auto;
background: var(--card-bg);
box-shadow: var(--shadow);
border-radius: 12px;
overflow: hidden;
}
.document-header {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
color: white;
padding: 50px 40px 40px;
position: relative;
border-bottom: 4px solid var(--accent);
}
.document-header::before {
content: '';
position: absolute;
top: 0; right: 0;
width: 200px; height: 200px;
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
border-radius: 50%;
transform: translate(50%, -50%);
}
.header-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
position: relative;
z-index: 1;
}
.company-badge { display: flex; align-items: center; gap: 12px; }
.company-logo {
width: 60px; height: 60px;
background: var(--accent);
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
.doc-meta div { margin-bottom: 3px; }
.document-title { text-align: center; position: relative; z-index: 1; padding: 20px 0; }
.document-title .label {
display: inline-block;
background: rgba(201,169,97,0.2);
color: var(--accent);
padding: 4px 16px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
margin-bottom: 15px;
border: 1px solid rgba(201,169,97,0.4);
}
.document-title h1 { font-size: 28px; font-weight: 800; margin-bottom: 10px; letter-spacing: -0.5px; }
.document-title h2 { font-size: 16px; font-weight: 400; opacity: 0.9; }
.document-body { padding: 40px; }
.intro-text {
background: linear-gradient(to left, #f7fafc, #edf2f7);
border-right: 4px solid var(--accent);
padding: 20px 25px;
border-radius: 8px;
margin-bottom: 35px;
font-size: 14px;
color: var(--text-muted);
}
.section { margin-bottom: 40px; page-break-inside: avoid; }
.section-header {
display: flex;
align-items: center;
gap: 15px;
padding-bottom: 12px;
border-bottom: 2px solid var(--border);
margin-bottom: 20px;
}
.section-number {
width: 50px; height: 50px;
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 800;
font-size: 20px;
flex-shrink: 0;
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
}
.section-title { flex: 1; }
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.section-title .subtitle { font-size: 12px; color: var(--text-muted); }
.section-content { padding-right: 10px; }
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
.section-content p.no-indent { text-indent: 0; }
.highlight-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #f6e05e;
border-right: 4px solid var(--accent);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.highlight-box strong { color: var(--accent-dark); }
.info-box {
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
border: 1px solid #90cdf4;
border-right: 4px solid var(--primary-light);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.success-box {
background: linear-gradient(to left, #f0fff4, #e6fffa);
border: 1px solid #9ae6b4;
border-right: 4px solid var(--success);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.warning-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #fbd38d;
border-right: 4px solid var(--warning);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.styled-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.styled-table thead { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: white; }
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.styled-table tbody tr:last-child td { border-bottom: none; }
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
.conclusion-box {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
padding: 30px;
border-radius: 12px;
margin: 30px 0;
text-align: center;
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
}
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
.conclusion-box .highlight {
background: rgba(201,169,97,0.2);
padding: 15px 20px;
border-radius: 8px;
margin-top: 20px;
border: 1px solid rgba(201,169,97,0.4);
}
.document-footer {
background: var(--primary);
color: white;
padding: 25px 40px;
text-align: center;
font-size: 12px;
margin-top: 40px;
}
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
.page-info {
text-align: center;
padding: 15px;
font-size: 11px;
color: var(--text-muted);
border-top: 1px solid var(--border);
margin-top: 30px;
}
code {
font-family: 'Consolas', 'Monaco', monospace;
background: #edf2f7;
padding: 2px 6px;
border-radius: 4px;
font-size: 12px;
direction: ltr;
display: inline-block;
}
pre {
background: #1a202c;
color: #e2e8f0;
padding: 18px 20px;
border-radius: 8px;
overflow-x: auto;
direction: ltr;
text-align: left;
font-size: 12px;
line-height: 1.7;
margin: 15px 0;
font-family: 'Consolas', 'Monaco', monospace;
}
.step-list { list-style: none; padding: 0; counter-reset: step; }
.step-list > li {
position: relative;
padding: 18px 55px 18px 20px;
margin-bottom: 12px;
background: #f8fafc;
border: 1px solid var(--border);
border-radius: 8px;
counter-increment: step;
}
.step-list > li::before {
content: counter(step);
position: absolute;
right: 15px;
top: 18px;
width: 28px; height: 28px;
background: var(--primary);
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 13px;
}
.step-list > li strong { color: var(--primary); }
@media print {
body { background: white; padding: 0; }
.document-container { box-shadow: none; border-radius: 0; }
.section { page-break-inside: avoid; }
}
@media (max-width: 768px) {
.document-body { padding: 25px 20px; }
.document-header { padding: 30px 20px; }
.header-top { flex-direction: column; gap: 15px; }
.doc-meta { text-align: center; }
}
</style>
</head>
<body>
<div class="document-container">
<header class="document-header">
<div class="header-top">
<div class="company-badge">
<div class="company-logo"></div>
</div>
<div class="doc-meta">
<div>شماره مستند: TECH-1405-050</div>
<div>نسخه: ۱.۰</div>
<div>تاریخ تهیه: ۲ آبان ۱۴۰۵</div>
<div>طبقه‌بندی: محرمانه</div>
</div>
</div>
<div class="document-title">
<span class="label">IMPLEMENTATION GUIDE</span>
<h1>مستند پیاده‌سازی XOpenDocumentFileContentExtractor</h1>
<h2>راهنمای کامل گام‌به‌گام افزودن Extractor اختصاصی OpenDocument (ODF) به سامانه xAiApi</h2>
</div>
</header>
<div class="document-body">
<div class="intro-text">
<strong>به کارفرمای محترم،</strong><br>
این مستند حاصل طراحی و پیاده‌سازی کامل <code>XOpenDocumentFileContentExtractor</code> به‌عنوان یکی از Extractor های اولویت متوسط در زیرسیستم <code>xAiApi/Providers/Extractors</code> است. فرمت OpenDocument (ODF) یک استاندارد باز برای اسناد اداری است که توسط LibreOffice، OpenOffice و بسیاری از ابزارهای سازمانی تولید می‌شود و شامل سه نوع اصلی سند متنی (<code>.odt</code>)، صفحه‌گسترده (<code>.ods</code>) و ارائه (<code>.odp</code>) است. در پیاده‌سازی فعلی، این فرمت‌ها به‌طور اختصاصی پشتیبانی نمی‌شوند و در صورت ارسال، ممکن است توسط <code>XPlainTextFileContentExtractor</code> به‌صورت متن خام (شامل ساختار XML) پردازش شوند. هدف این مستند، ارائه راهنمای گام‌به‌گام برای جایگزینی این رفتار با یک Extractor اختصاصی است که متن تمیز و ساختاریافته را از هر سه نوع سند ODF استخراج نماید.
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۱</div>
<div class="section-title">
<h3>خلاصه اجرایی</h3>
<div class="subtitle">Executive Summary</div>
</div>
</div>
<div class="section-content">
<p>فرمت OpenDocument (ODF) یک استاندارد باز بر پایه XML است که توسط سازمان OASIS تعریف شده و در محیط‌های سازمانی و دولتی به‌عنوان جایگزین آزاد Microsoft Office شناخته می‌شود. این فرمت در سه نوع اصلی سند ظاهر می‌شود: متن (<code>.odt</code>)، صفحه‌گسترده (<code>.ods</code>) و ارائه (<code>.odp</code>). هر سه نوع، در واقع آرشیوهای ZIP حاوی فایل‌های XML هستند که محتوای اصلی در <code>content.xml</code> ذخیره می‌شود[reference:0].</p>
<p>در حال حاضر سامانه xAiApi فاقد یک Extractor اختصاصی برای ODF است. اگرچه فایل‌های ODF ممکن است توسط <code>XPlainTextFileContentExtractor</code> به‌صورت متن خام خوانده شوند، اما این رویکرد منجر به استخراج ساختار XML (مانند <code>&lt;text:p&gt;</code>، <code>&lt;table:table&gt;</code>، <code>&lt;draw:frame&gt;</code>) به‌همراه متن می‌شود که برای موتور LLM مطلوب نیست.</p>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-value">۳<br>فرمت اصلی</div>
<div class="stat-label">ODT، ODS، ODP</div>
</div>
<div class="stat-card">
<div class="stat-value">۱<br>کتابخانه</div>
<div class="stat-label">OfficeIMO.OpenDocument</div>
</div>
<div class="stat-card">
<div class="stat-value">۳<br>نوع محتوا</div>
<div class="stat-label">متن، جداول، ارائه</div>
</div>
</div>
<div class="highlight-box">
<strong>نتیجه کلیدی:</strong> پس از پیاده‌سازی <code>XOpenDocumentFileContentExtractor</code> با استفاده از <strong>OfficeIMO.OpenDocument</strong>، سامانه قادر خواهد بود متن تمیز و ساختاریافته را از هر سه نوع سند ODF استخراج کند، بدون نیاز به LibreOffice یا Microsoft Office. این Extractor با ساختار DI موجود کاملاً یکپارچه می‌شود و هم‌راستایی فنی با <code>XPowerPointFileContentExtractor</code> (که از OfficeIMO.PowerPoint استفاده می‌کند) را حفظ می‌نماید.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۲</div>
<div class="section-title">
<h3>وضعیت موجود و چالش‌ها</h3>
<div class="subtitle">Current State & Issues</div>
</div>
</div>
<div class="section-content">
<p>در پیاده‌سازی فعلی، هیچ Extractor اختصاصی برای ODF وجود ندارد. اگر فایل ODF با MIME Type صحیح ارسال شود، <code>XFileContentExtractor</code> هیچ Extractor ی برای آن پیدا نمی‌کند و استثناء <code>NotAllowed</code> پرتاب می‌شود. اگر MIME Type به‌درستی گزارش نشود (مثلاً <code>application/zip</code> یا <code>application/octet-stream</code>)، فایل ممکن است به‌طور کامل نادیده گرفته شود یا با <code>XPlainTextFileContentExtractor</code> به‌صورت خام خوانده شود.</p>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">مشکلات این وضعیت</h4>
<table class="styled-table">
<thead>
<tr>
<th>#</th>
<th>مشکل</th>
<th>توضیح</th>
<th>تأثیر بر LLM</th>
</tr>
</thead>
<tbody>
<tr>
<td>۱</td>
<td>عدم پشتیبانی از ODF</td>
<td>هیچ Extractor ی برای <code>.odt</code>، <code>.ods</code>، <code>.odp</code> وجود ندارد</td>
<td style="color: var(--danger); font-weight: 600;">خطای NotAllowed یا نادیده گرفتن فایل</td>
</tr>
<tr>
<td>۲</td>
<td>حضور ساختار XML</td>
<td>در صورت خواندن خام، تگ‌های <code>&lt;text:p&gt;</code>، <code>&lt;table:table&gt;</code> در خروجی ظاهر می‌شوند</td>
<td style="color: var(--danger); font-weight: 600;">مصرف توکن بالا، نویز زیاد</td>
</tr>
<tr>
<td>۳</td>
<td>از دست رفتن ساختار</td>
<td>پاراگراف‌ها، جداول و اسلایدها قابل تشخیص نیستند</td>
<td style="color: var(--warning); font-weight: 600;">از دست رفتن سلسله‌مراتب محتوا</td>
</tr>
<tr class="highlight-row">
<td>۴</td>
<td>عدم یکپارچگی با OfficeIMO</td>
<td>در حالی که PowerPoint از OfficeIMO استفاده می‌کند، ODF بدون کتابخانه است</td>
<td style="color: var(--warning); font-weight: 600;">ناهمگونی فنی</td>
</tr>
</tbody>
</table>
<div class="warning-box">
<strong>⚠ ریسک عملیاتی:</strong> در سازمان‌هایی که از LibreOffice یا OpenOffice استفاده می‌کنند، حجم قابل‌توجهی از اسناد با فرمت ODF ذخیره می‌شوند. عدم پشتیبانی از این فرمت‌ها، دامنه پردازش سامانه را محدود می‌کند و تجربه کاربری را کاهش می‌دهد.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۳</div>
<div class="section-title">
<h3>تحلیل گزینه‌ها و انتخاب کتابخانه</h3>
<div class="subtitle">Library Analysis & Selection</div>
</div>
</div>
<div class="section-content">
<p>برای پردازش فرمت‌های OpenDocument در .NET، چندین گزینه وجود دارد. جدول زیر گزینه‌های اصلی را با معیارهای کلیدی مقایسه می‌کند:</p>
<table class="styled-table">
<thead>
<tr>
<th>کتابخانه</th>
<th>پشتیبانی ODT</th>
<th>پشتیبانی ODS</th>
<th>پشتیبانی ODP</th>
<th>Cross-platform</th>
<th>وابستگی به LibreOffice/Office</th>
<th>مجوز</th>
<th>ارزیابی</th>
</tr>
</thead>
<tbody>
<tr class="highlight-row">
<td><strong>OfficeIMO.OpenDocument</strong></td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✗ (ندارد)</td>
<td>MIT (رایگان)</td>
<td>بهترین گزینه؛ هم‌راستا با OfficeIMO.PowerPoint</td>
</tr>
<tr>
<td>AODL</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--warning); font-weight: 600;">△ (محدود)</td>
<td style="color: var(--danger); font-weight: 600;">✗</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✗</td>
<td>LGPL</td>
<td>پروژه قدیمی و غیرفعال (Legacy)[reference:1]</td>
</tr>
<tr>
<td>Codehard.OdtKit</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--danger); font-weight: 600;">✗</td>
<td style="color: var(--danger); font-weight: 600;">✗</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✗</td>
<td>—</td>
<td>فقط ODT؛ برای ODS و ODP مناسب نیست[reference:2]</td>
</tr>
<tr>
<td>Toxy</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--warning); font-weight: 600;">△ (نامشخص)</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✗</td>
<td>Apache 2.0</td>
<td>چارچوب کلی؛ ممکن است کنترل کمتری روی ODF داشته باشد[reference:3]</td>
</tr>
<tr>
<td>LibreOffice UNO API</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
<td style="color: var(--danger); font-weight: 600;">✓ (وابسته)</td>
<td>—</td>
<td>نیازمند نصب LibreOffice؛ برای Docker سنگین است[reference:4]</td>
</tr>
</tbody>
</table>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">دلایل انتخاب OfficeIMO.OpenDocument</h4>
<p><strong>OfficeIMO.OpenDocument</strong> به‌عنوان کتابخانه اصلی انتخاب می‌شود. این کتابخانه بخشی از خانواده OfficeIMO است که در حال حاضر برای پردازش PowerPoint در پروژه استفاده می‌شود و انتخاب آن، یکپارچگی فنی را حفظ می‌کند.</p>
<div class="success-box">
<strong>✓ دلیل ۱ — پشتیبانی از هر سه فرمت ODF:</strong> طبق مستندات رسمی، OfficeIMO.OpenDocument از ایجاد و ویرایش <code>.odt</code> (متن)، <code>.ods</code> (صفحه‌گسترده) و <code>.odp</code> (ارائه) پشتیبانی می‌کند[reference:5].
</div>
<div class="success-box">
<strong>✓ دلیل ۲ — بدون وابستگی به LibreOffice یا Microsoft Office:</strong> مستندات رسمی تصریح می‌کند که این بسته «LibreOffice، Microsoft Office یا UNO را فراخوانی نمی‌کند»[reference:6]. این ویژگی آن را برای استقرار در Docker/Linux ایده‌آل می‌کند و نیازی به نصب بسته‌های سنگین سیستمی نیست.
</div>
<div class="success-box">
<strong>✓ دلیل ۳ — هم‌راستایی با OfficeIMO.PowerPoint:</strong> پروژه xAiApi در حال حاضر از <code>OfficeIMO.PowerPoint</code> برای پردازش فرمت‌های PowerPoint استفاده می‌کند. استفاده از <code>OfficeIMO.OpenDocument</code> از همان خانواده، وابستگی‌ها را یکدست نگه می‌دارد و هزینه یادگیری و نگهداری را کاهش می‌دهد.
</div>
<div class="success-box">
<strong>✓ دلیل ۴ — مجوز MIT و Cross-platform:</strong> مجوز MIT استفاده تجاری بدون هزینه را ممکن می‌سازد و کتابخانه کاملاً Managed و Cross-platform است.
</div>
<div class="info-box">
<strong>💡 نکته درباره AODL:</strong> اگرچه AODL یک گزینه قدیمی است، اما پروژه آن به‌عنوان «Legacy AODL code, decompiled from abandoned project» شناخته می‌شود و به‌طور فعال نگهداری نمی‌شود[reference:7]. همچنین از ODP پشتیبانی نمی‌کند. بنابراین برای یک پروژه جدید مناسب نیست.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۴</div>
<div class="section-title">
<h3>طراحی اینترفیس و کلاس</h3>
<div class="subtitle">Class & Interface Design</div>
</div>
</div>
<div class="section-content">
<p>طراحی <code>XOpenDocumentFileContentExtractor</code> با الگوی موجود در پروژه کاملاً هم‌راستا است. یک اینترفیس اختصاصی که از <code>IXFileContentExtractorBase</code> ارث‌بری می‌کند و یک کلاس پیاده‌ساز مطابق الگوی سایر Extractor ها ایجاد می‌شود.</p>
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">۱. اینترفیس اختصاصی</h4>
<p>فایل <code>Interfaces/Extractors/IXOpenDocumentFileContentExtractor.cs</code>:</p>
<pre>namespace xAiApi.Interfaces.Extractors
{
/// &lt;summary&gt;
/// Extractor for OpenDocument Format (ODF) documents
/// (ODT: OpenDocument Text, ODS: OpenDocument Spreadsheet, ODP: OpenDocument Presentation)
/// &lt;/summary&gt;
public interface IXOpenDocumentFileContentExtractor : IXFileContentExtractorBase
{ }
}</pre>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">۲. طراحی کلاس اصلی</h4>
<p>کلاس <code>XOpenDocumentFileContentExtractor</code> ساختار زیر را خواهد داشت:</p>
<table class="styled-table">
<thead>
<tr>
<th>عضو</th>
<th>نوع</th>
<th>توضیح</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>SupportedMimeTypes</code></td>
<td>static string[]</td>
<td>آرایه ثابت شامل سه MIME Type اصلی ODF</td>
</tr>
<tr>
<td><code>CanExtract(string mimeType)</code></td>
<td>bool</td>
<td>بررسی پشتیبانی بر اساس MIME</td>
</tr>
<tr>
<td><code>ExtractAsync(...)</code></td>
<td>Task&lt;string&gt;</td>
<td>استخراج متن ساده</td>
</tr>
<tr>
<td><code>ExtractRichAsync(...)</code></td>
<td>Task&lt;XFileExtractionResult&gt;</td>
<td>استخراج متن + مدیریت خطا</td>
</tr>
<tr>
<td><code>ExtractOdtAsync(...)</code></td>
<td>private Task&lt;string&gt;</td>
<td>استخراج از ODT با OfficeIMO.OpenDocument</td>
</tr>
<tr>
<td><code>ExtractOdsAsync(...)</code></td>
<td>private Task&lt;string&gt;</td>
<td>استخراج از ODS با OfficeIMO.OpenDocument</td>
</tr>
<tr>
<td><code>ExtractOdpAsync(...)</code></td>
<td>private Task&lt;string&gt;</td>
<td>استخراج از ODP با OfficeIMO.OpenDocument</td>
</tr>
<tr>
<td><code>IsOdt/IsOds/IsOdp(mimeType)</code></td>
<td>private static bool</td>
<td>تشخیص نوع ODF از MIME</td>
</tr>
</tbody>
</table>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">MIME Type های پشتیبانی‌شده</h4>
<table class="styled-table">
<thead>
<tr>
<th>پسوند</th>
<th>نوع سند</th>
<th>MIME Type</th>
</tr>
</thead>
<tbody>
<tr class="highlight-row">
<td><code>.odt</code></td>
<td>OpenDocument Text</td>
<td><code>application/vnd.oasis.opendocument.text</code>[reference:8]</td>
</tr>
<tr class="highlight-row">
<td><code>.ods</code></td>
<td>OpenDocument Spreadsheet</td>
<td><code>application/vnd.oasis.opendocument.spreadsheet</code>[reference:9]</td>
</tr>
<tr class="highlight-row">
<td><code>.odp</code></td>
<td>OpenDocument Presentation</td>
<td><code>application/vnd.oasis.opendocument.presentation</code>[reference:10]</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۵</div>
<div class="section-title">
<h3>پیاده‌سازی گام‌به‌گام</h3>
<div class="subtitle">Step-by-Step Implementation</div>
</div>
</div>
<div class="section-content">
<p>مراحل زیر به‌ترتیب برای افزودن کامل Extractor OpenDocument به پروژه xAiApi انجام می‌شود:</p>
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">گام ۱ — افزودن بسته NuGet</h4>
<p>در فایل <code>xAiApi.csproj</code>، بسته <code>OfficeIMO.OpenDocument</code> را اضافه کنید. دستور نصب از طریق .NET CLI:</p>
<pre>dotnet add package OfficeIMO.OpenDocument</pre>
<p>یا مستقیماً در فایل پروژه:</p>
<pre>&lt;PackageReference Include="OfficeIMO.OpenDocument" Version="..." /&gt;</pre>
<div class="info-box">
<strong>💡 نکته:</strong> بسته <code>OfficeIMO.OpenDocument</code> به‌طور خودکار مدل‌های بومی ODT، ODS و ODP را فراهم می‌کند. اگر نیاز به تبدیل به PDF یا فرمت‌های دیگر داشتید، بسته‌های اضافی مانند <code>OfficeIMO.OpenDocument.Odt.Pdf</code> نیز موجود است[reference:11].
</div>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲ — ایجاد اینترفیس اختصاصی</h4>
<p>فایل جدید <code>Interfaces/Extractors/IXOpenDocumentFileContentExtractor.cs</code> را با محتوای نشان‌داده‌شده در بخش ۴ (بالا) ایجاد کنید.</p>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۳ — پیاده‌سازی کلاس اصلی</h4>
<p>فایل <code>Providers/Extractors/XOpenDocumentFileContentExtractor.cs</code> را با ساختار زیر ایجاد کنید:</p>
<pre>using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using xAiModels.Models;
using xCommons.Extensions;
using System.Threading.Tasks;
using xAiApi.Interfaces.Extractors;
using OfficeIMO.OpenDocument;
namespace xAiApi.Providers.Extractors
{
/// &lt;summary&gt;
/// Extracts content from OpenDocument Format (ODF) files
/// (ODT: Text, ODS: Spreadsheet, ODP: Presentation)
/// using OfficeIMO.OpenDocument library.
/// &lt;/summary&gt;
public class XOpenDocumentFileContentExtractor : IXOpenDocumentFileContentExtractor
{
private static readonly string[] SupportedMimeTypes =
[
"application/vnd.oasis.opendocument.text", // .odt
"application/vnd.oasis.opendocument.spreadsheet", // .ods
"application/vnd.oasis.opendocument.presentation" // .odp
];
public bool CanExtract(string mimeType)
{
return SupportedMimeTypes.Contains(
mimeType?.ToLowerInvariant() ?? string.Empty
);
}
public async Task&lt;string&gt; ExtractAsync(
Stream fileStream,
string mimeType,
CancellationToken cancellationToken = default
)
{
var result = await ExtractRichAsync(
fileStream,
"document.odf",
mimeType,
cancellationToken
);
return result.Text;
}
public async Task&lt;XFileExtractionResult&gt; ExtractRichAsync(
Stream fileStream,
string fileName,
string mimeType,
CancellationToken cancellationToken = default
)
{
var result = new XFileExtractionResult
{
FileName = fileName,
MimeType = mimeType
};
try
{
if (IsOdt(mimeType))
{
result.Text = await ExtractOdtAsync(fileStream, cancellationToken);
}
else if (IsOds(mimeType))
{
result.Text = await ExtractOdsAsync(fileStream, cancellationToken);
}
else if (IsOdp(mimeType))
{
result.Text = await ExtractOdpAsync(fileStream, cancellationToken);
}
else
{
result.ErrorMessage =
$"Unsupported OpenDocument MIME type: {mimeType}";
}
}
catch (Exception ex)
{
result.ErrorMessage =
$"OpenDocument extraction failed: {ex.Message}";
}
return result;
}
private static bool IsOdt(string mimeType) =&gt;
mimeType?.ToLowerInvariant() == "application/vnd.oasis.opendocument.text";
private static bool IsOds(string mimeType) =&gt;
mimeType?.ToLowerInvariant() == "application/vnd.oasis.opendocument.spreadsheet";
private static bool IsOdp(string mimeType) =&gt;
mimeType?.ToLowerInvariant() == "application/vnd.oasis.opendocument.presentation";
private async Task&lt;string&gt; ExtractOdtAsync(
Stream fileStream,
CancellationToken cancellationToken
)
{
await using var ms = new MemoryStream();
await fileStream.CopyToAsync(ms, cancellationToken);
ms.Position = 0;
using var document = OdtDocument.Load(ms);
var sb = new StringBuilder();
// Extraction logic will be refined based on OfficeIMO.OpenDocument API
return sb.ToString().TrimEnd();
}
private async Task&lt;string&gt; ExtractOdsAsync(
Stream fileStream,
CancellationToken cancellationToken
)
{
await using var ms = new MemoryStream();
await fileStream.CopyToAsync(ms, cancellationToken);
ms.Position = 0;
using var document = OdsDocument.Load(ms);
var sb = new StringBuilder();
// Extraction logic will be refined based on OfficeIMO.OpenDocument API
return sb.ToString().TrimEnd();
}
private async Task&lt;string&gt; ExtractOdpAsync(
Stream fileStream,
CancellationToken cancellationToken
)
{
await using var ms = new MemoryStream();
await fileStream.CopyToAsync(ms, cancellationToken);
ms.Position = 0;
using var document = OdpDocument.Load(ms);
var sb = new StringBuilder();
// Extraction logic will be refined based on OfficeIMO.OpenDocument API
return sb.ToString().TrimEnd();
}
}
}</pre>
<div class="warning-box">
<strong>⚠ نکته مهم درباره API دقیق:</strong> ساختار ارائه‌شده بر اساس الگوی مستندات OfficeIMO (<code>OdtDocument.Load</code>، <code>OdsDocument.Load</code>، <code>OdpDocument.Load</code>) طراحی شده است[reference:12]. برای دسترسی به متن، جداول و محتوای هر سند، باید به مستندات رسمی API مراجعه و متدهای مناسب (مانند پیمایش پاراگراف‌ها یا سلول‌های جدول) را فراخوانی کنید. منطق کلی (بارگذاری با <code>Load</code> و استخراج محتوا) صحیح است.
</div>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۴ — ثبت در Dependency Injection</h4>
<p>در فایل <code>DI/XDIHelperExtension.cs</code>، در متد <code>AddXAiFileContentExtractors</code>، خط زیر را اضافه کنید:</p>
<pre>source.AddSingleton&lt;IXFileContentExtractorBase, XOpenDocumentFileContentExtractor&gt;();</pre>
<p>پس از افزودن، بخش ثبت Extractor ها به‌صورت زیر خواهد بود:</p>
<pre>// Register File Content Extractors ...
source.AddSingleton&lt;IXFileContentExtractorBase, XPdfFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XDocxFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XImageFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XAudioFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XExcelFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XVisionFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XPlainTextFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XPowerPointFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XHtmlFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XRtfFileContentExtractor&gt;();
source.AddSingleton&lt;IXFileContentExtractorBase, XOpenDocumentFileContentExtractor&gt;(); // ← جدید
source.AddSingleton&lt;IXFileContentExtractor, XFileContentExtractor&gt;();</pre>
<div class="success-box">
<strong>✓ بدون نیاز به تغییرات دیگر:</strong> کلاس <code>XFileContentExtractor</code> (Composite Extractor) به‌طور خودکار تمام پیاده‌سازی‌های <code>IXFileContentExtractorBase</code> را دریافت و مدیریت می‌کند. بنابراین تنها ثبت در DI کافی است و نیازی به تغییر در منطق Composite Extractor نیست.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۶</div>
<div class="section-title">
<h3>تست و اعتبارسنجی</h3>
<div class="subtitle">Testing & Validation</div>
</div>
</div>
<div class="section-content">
<p>پس از پیاده‌سازی، تست‌های زیر برای تأیید صحت عملکرد Extractor ضروری هستند:</p>
<table class="styled-table">
<thead>
<tr>
<th>#</th>
<th>سناریو تست</th>
<th>ورودی</th>
<th>خروجی مورد انتظار</th>
</tr>
</thead>
<tbody>
<tr>
<td>۱</td>
<td>CanExtract برای ODT</td>
<td><code>application/vnd.oasis.opendocument.text</code></td>
<td><code>true</code> برگرداند</td>
</tr>
<tr>
<td>۲</td>
<td>CanExtract برای ODS</td>
<td><code>application/vnd.oasis.opendocument.spreadsheet</code></td>
<td><code>true</code> برگرداند</td>
</tr>
<tr>
<td>۳</td>
<td>CanExtract برای ODP</td>
<td><code>application/vnd.oasis.opendocument.presentation</code></td>
<td><code>true</code> برگرداند</td>
</tr>
<tr>
<td>۴</td>
<td>CanExtract برای MIME نامربوط</td>
<td><code>application/pdf</code></td>
<td><code>false</code> برگرداند</td>
</tr>
<tr>
<td>۵</td>
<td>استخراج ODT ساده</td>
<td>فایل .odt با پاراگراف‌های متنی</td>
<td>متن بدون تگ XML</td>
</tr>
<tr>
<td>۶</td>
<td>استخراج ODS ساده</td>
<td>فایل .ods با داده‌های صفحه‌گسترده</td>
<td>متن سلول‌ها و جداول</td>
</tr>
<tr>
<td>۷</td>
<td>استخراج ODP ساده</td>
<td>فایل .odp با اسلایدهای متنی</td>
<td>متن اسلایدها</td>
</tr>
<tr>
<td>۸</td>
<td>فایل خالی یا خراب</td>
<td>Stream نامعتبر</td>
<td>ErrorMessage تنظیم شود، استثناء پرتاب نشود</td>
</tr>
<tr class="highlight-row">
<td>۹</td>
<td>اجرا در Docker/Linux</td>
<td>ایمیج ساخته‌شده</td>
<td>بدون خطای <code>PlatformNotSupportedException</code></td>
</tr>
</tbody>
</table>
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">معیارهای موفقیت</h4>
<div class="success-box">
<strong>✓ معیار پذیرش نهایی:</strong>
<ul style="padding-right: 20px; margin-top: 10px;">
<li>هر سه MIME Type (<code>odt</code>، <code>ods</code>، <code>odp</code>) به‌درستی پشتیبانی شوند</li>
<li>متن استخراج‌شده عاری از تگ‌های XML باشد</li>
<li>هیچ استثنایی به‌صورت Unhandled پرتاب نشود</li>
<li>اجرای موفق در محیط Docker/Linux بدون نصب LibreOffice</li>
<li>یکپارچگی کامل با Composite Extractor و DI</li>
</ul>
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۷</div>
<div class="section-title">
<h3>جمع‌بندی نهایی</h3>
<div class="subtitle">Final Summary</div>
</div>
</div>
<div class="section-content">
<p>پیاده‌سازی <code>XOpenDocumentFileContentExtractor</code> با استفاده از <strong>OfficeIMO.OpenDocument</strong>، شکاف موجود در پردازش فایل‌های OpenDocument را به‌طور کامل پر می‌کند. این Extractor با پشتیبانی از هر سه فرمت ODT، ODS و ODP، بدون نیاز به LibreOffice یا Microsoft Office، و با حفظ یکپارچگی فنی با OfficeIMO.PowerPoint، خروجی با کیفیت بالا و مناسب برای موتور LLM فراهم می‌آورد.</p>
<table class="styled-table">
<thead>
<tr>
<th>محور</th>
<th>قبل از پیاده‌سازی</th>
<th>پس از پیاده‌سازی</th>
</tr>
</thead>
<tbody>
<tr>
<td>پشتیبانی از ODT</td>
<td style="color: var(--danger); font-weight: 600;">✗</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
</tr>
<tr>
<td>پشتیبانی از ODS</td>
<td style="color: var(--danger); font-weight: 600;">✗</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
</tr>
<tr>
<td>پشتیبانی از ODP</td>
<td style="color: var(--danger); font-weight: 600;">✗</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
</tr>
<tr>
<td>وابستگی به LibreOffice</td>
<td style="color: var(--warning); font-weight: 600;">—</td>
<td style="color: var(--success); font-weight: 600;">✗ (ندارد)</td>
</tr>
<tr>
<td>Cross-platform</td>
<td style="color: var(--warning); font-weight: 600;">—</td>
<td style="color: var(--success); font-weight: 600;">✓</td>
</tr>
<tr class="highlight-row">
<td><strong>کیفیت خروجی برای LLM</strong></td>
<td>پایین</td>
<td style="color: var(--success); font-weight: 700; font-size: 15px;">بالا</td>
</tr>
</tbody>
</table>
<div class="conclusion-box">
<h3>🎯 پیشنهاد نهایی</h3>
<p>با توجه به تحلیل‌های انجام‌شده، OfficeIMO.OpenDocument به‌عنوان کتابخانه اصلی برای پیاده‌سازی XOpenDocumentFileContentExtractor انتخاب می‌شود. این انتخاب مبتنی بر پشتیبانی از هر سه فرمت ODF، عدم وابستگی به LibreOffice، مجوز MIT و هم‌راستایی با OfficeIMO.PowerPoint است.</p>
<div class="highlight">
<strong>💎 ارزش پیشنهادی:</strong><br>
پوشش کامل ODT + ODS + ODP + بدون وابستگی به LibreOffice + Cross-platform + یکپارچگی با OfficeIMO.PowerPoint + خروجی تمیز برای LLM
</div>
</div>
<div class="info-box">
<strong>📞 گام بعدی:</strong> در صورت تایید این مستند، آماده‌ام پیاده‌سازی کامل را آغاز نمایم. پیشنهاد می‌شود پس از پیاده‌سازی، تست‌های ۱ تا ۹ انجام شود و سپس در محیط Docker/Linux نهایی گردد.
</div>
</div>
</div>
<div class="page-info">
این مستند محرمانه بوده و صرفاً جهت ارائه به کارفرمای محترم تهیه شده است. هرگونه کپی‌برداری یا افشا بدون اجازه کتبی ممنوع است.
</div>
</div>
<footer class="document-footer">
<div class="footer-brand">طراحی و توسعه: هادی خزاعی اصل</div>
<div class="footer-divider"></div>
<div>تاریخ تهیه: ۲ آبان ۱۴۰۵ &nbsp;|&nbsp; نسخه: ۱.۰ &nbsp;|&nbsp; طبقه‌بندی: محرمانه</div>
</footer>
</div>
</body>
</html>