kd-engine 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kd_engine-1.0.0.dist-info/METADATA +19 -0
- kd_engine-1.0.0.dist-info/RECORD +118 -0
- kd_engine-1.0.0.dist-info/WHEEL +5 -0
- kd_engine-1.0.0.dist-info/entry_points.txt +2 -0
- kd_engine-1.0.0.dist-info/licenses/LICENSE-MIT +21 -0
- kd_engine-1.0.0.dist-info/top_level.txt +1 -0
- ytk/__init__.py +2 -0
- ytk/__main__.py +21 -0
- ytk/batch/__init__.py +39 -0
- ytk/batch/runner.py +1149 -0
- ytk/cache/__init__.py +34 -0
- ytk/cache/v2.py +562 -0
- ytk/cleaning/density.py +40 -0
- ytk/cleaning/fillers.py +18 -0
- ytk/cleaning/sentence_boundary.py +30 -0
- ytk/cleaning/service.py +62 -0
- ytk/cli.py +1281 -0
- ytk/commands/__init__.py +3 -0
- ytk/commands/merge.py +600 -0
- ytk/config.py +757 -0
- ytk/dedup/service.py +166 -0
- ytk/doctor.py +891 -0
- ytk/dotenv.py +334 -0
- ytk/errors.py +38 -0
- ytk/extraction/service.py +451 -0
- ytk/extraction/strategies/base.py +16 -0
- ytk/extraction/strategies/code_block.py +285 -0
- ytk/extraction/strategies/heuristic.py +791 -0
- ytk/extraction/strategies/local_model.py +56 -0
- ytk/extraction/text_context.py +177 -0
- ytk/extraction/visual_context.py +159 -0
- ytk/ingestion/adapters/__init__.py +1 -0
- ytk/ingestion/adapters/_common.py +865 -0
- ytk/ingestion/adapters/base.py +160 -0
- ytk/ingestion/adapters/bilibili.py +271 -0
- ytk/ingestion/adapters/douyin.py +445 -0
- ytk/ingestion/adapters/tiktok.py +102 -0
- ytk/ingestion/adapters/xiaohongshu.py +758 -0
- ytk/ingestion/adapters/youtube.py +74 -0
- ytk/ingestion/browser_acquired.py +220 -0
- ytk/ingestion/http_client.py +43 -0
- ytk/ingestion/local_import.py +202 -0
- ytk/ingestion/media.py +468 -0
- ytk/ingestion/providers/asr.py +902 -0
- ytk/ingestion/providers/base.py +13 -0
- ytk/ingestion/providers/dtk_client.py +816 -0
- ytk/ingestion/providers/minimax.py +350 -0
- ytk/ingestion/providers/transcript_api.py +336 -0
- ytk/ingestion/providers/xhs_client.py +646 -0
- ytk/ingestion/providers/ytdlp.py +400 -0
- ytk/ingestion/registry.py +189 -0
- ytk/ingestion/resolver.py +417 -0
- ytk/ingestion/search.py +56 -0
- ytk/ingestion/service.py +167 -0
- ytk/ingestion/subtitles.py +602 -0
- ytk/ingestion/transcript_cache.py +212 -0
- ytk/ingestion/url_parser.py +53 -0
- ytk/ingestion/video_frames.py +292 -0
- ytk/ingestion/ytdlp_acquire.py +754 -0
- ytk/logging.py +383 -0
- ytk/models/common.py +20 -0
- ytk/models/content.py +451 -0
- ytk/models/knowledge.py +43 -0
- ytk/models/migrations.py +262 -0
- ytk/models/skill.py +13 -0
- ytk/models/source.py +265 -0
- ytk/models/topic.py +18 -0
- ytk/models/transcript.py +30 -0
- ytk/ocr/__init__.py +65 -0
- ytk/ocr/engine.py +245 -0
- ytk/ocr/layout.py +347 -0
- ytk/ocr/pipeline.py +440 -0
- ytk/ocr/rapidocr_engine.py +144 -0
- ytk/pipeline/acquisition_checkpoint.py +240 -0
- ytk/pipeline/artifacts.py +18 -0
- ytk/pipeline/orchestrator.py +598 -0
- ytk/pipeline/processing_identity.py +18 -0
- ytk/pipeline/retry.py +728 -0
- ytk/pipeline/runners.py +578 -0
- ytk/pipeline/state.py +1107 -0
- ytk/pipeline/v2.py +1863 -0
- ytk/py.typed +1 -0
- ytk/quality/__init__.py +9 -0
- ytk/quality/completeness.py +260 -0
- ytk/renderers/base.py +9 -0
- ytk/renderers/citation_alignment.py +617 -0
- ytk/renderers/evidence_formatter.py +362 -0
- ytk/renderers/json_renderer.py +13 -0
- ytk/renderers/jsonl_renderer.py +18 -0
- ytk/renderers/knowledge_doc_renderer.py +1984 -0
- ytk/renderers/markdown_renderer.py +540 -0
- ytk/renderers/obsidian_renderer.py +138 -0
- ytk/renderers/skill_package.py +21 -0
- ytk/renderers/source_links.py +309 -0
- ytk/renderers/summary_renderer.py +163 -0
- ytk/renderers/v2.py +171 -0
- ytk/renderers/v2_jsonl.py +165 -0
- ytk/renderers/v2_markdown.py +477 -0
- ytk/renderers/v2_obsidian.py +113 -0
- ytk/renderers/v2_summary.py +220 -0
- ytk/segmentation/change_points.py +50 -0
- ytk/segmentation/embeddings.py +45 -0
- ytk/segmentation/service.py +318 -0
- ytk/skill_builder/__init__.py +1 -0
- ytk/skill_builder/builder.py +419 -0
- ytk/skill_builder/templates/SKILL.md.j2 +85 -0
- ytk/skill_builder/templates/evals/evals.json.j2 +25 -0
- ytk/skill_builder/templates/examples/example-input.md.j2 +5 -0
- ytk/skill_builder/templates/examples/example-output.md.j2 +8 -0
- ytk/skill_builder/templates/references/commands.md.j2 +34 -0
- ytk/skill_builder/templates/references/concepts.md.j2 +22 -0
- ytk/skill_builder/templates/references/configs.md.j2 +31 -0
- ytk/skill_builder/templates/references/evidence-policy.md.j2 +27 -0
- ytk/skill_builder/templates/references/source-summary.md.j2 +24 -0
- ytk/skill_builder/templates/scripts/build_skill.py.j2 +14 -0
- ytk/skill_builder/templates/scripts/validate_output.py.j2 +136 -0
- ytk/skill_builder/templates.py +29 -0
- ytk/text_normalization.py +44 -0
ytk/cleaning/service.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from ytk.cleaning.density import technical_density_score
|
|
2
|
+
from ytk.cleaning.sentence_boundary import (
|
|
3
|
+
RuleBasedSentenceBoundaryBackend,
|
|
4
|
+
SentenceBoundaryBackend,
|
|
5
|
+
)
|
|
6
|
+
from ytk.models.content import ContentBlock, ImageRegionLocator, ParagraphLocator, TimeRangeLocator
|
|
7
|
+
from ytk.models.transcript import TranscriptSegment
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CleaningService:
|
|
11
|
+
def __init__(self, boundary_backend: SentenceBoundaryBackend | None = None) -> None:
|
|
12
|
+
self._boundary_backend = boundary_backend or RuleBasedSentenceBoundaryBackend()
|
|
13
|
+
|
|
14
|
+
def clean(self, segments: list[TranscriptSegment]) -> list[TranscriptSegment]:
|
|
15
|
+
return [self._boundary_backend.clean_segment(segment) for segment in segments]
|
|
16
|
+
|
|
17
|
+
def clean_blocks(self, blocks: list[ContentBlock] | tuple[ContentBlock, ...]) -> list[ContentBlock]:
|
|
18
|
+
"""v2 block entry (T11.2): clean text while keeping block identity/locator.
|
|
19
|
+
|
|
20
|
+
Raw text is preserved; ``cleaned_text`` is a derived field only. The
|
|
21
|
+
mapping stays strictly 1:1 so evidence can never drift to another block.
|
|
22
|
+
"""
|
|
23
|
+
cleaned: list[ContentBlock] = []
|
|
24
|
+
for block in blocks:
|
|
25
|
+
probe = self._probe_segment(block)
|
|
26
|
+
normalized = self._boundary_backend.clean_segment(probe).cleaned_text
|
|
27
|
+
cleaned.append(block.model_copy(update={"cleaned_text": normalized}))
|
|
28
|
+
return cleaned
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def _probe_segment(block: ContentBlock) -> TranscriptSegment:
|
|
32
|
+
locator = block.locator
|
|
33
|
+
if isinstance(locator, TimeRangeLocator):
|
|
34
|
+
start, end = locator.time.start, locator.time.end
|
|
35
|
+
elif isinstance(locator, ParagraphLocator):
|
|
36
|
+
start = end = float(locator.paragraph)
|
|
37
|
+
elif isinstance(locator, ImageRegionLocator):
|
|
38
|
+
start = end = 0.0
|
|
39
|
+
else: # video frame
|
|
40
|
+
start = end = float(getattr(locator, "time", 0.0))
|
|
41
|
+
return TranscriptSegment(
|
|
42
|
+
text=block.cleaned_text or block.raw_text,
|
|
43
|
+
raw_text=block.raw_text,
|
|
44
|
+
cleaned_text=None,
|
|
45
|
+
start=start,
|
|
46
|
+
end=end,
|
|
47
|
+
source="manual",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def _normalized_sentence(self, text: str) -> str:
|
|
51
|
+
probe = TranscriptSegment(
|
|
52
|
+
text=text,
|
|
53
|
+
raw_text=text,
|
|
54
|
+
cleaned_text=None,
|
|
55
|
+
start=0.0,
|
|
56
|
+
end=0.0,
|
|
57
|
+
source="manual",
|
|
58
|
+
)
|
|
59
|
+
return self._boundary_backend.clean_segment(probe).cleaned_text or ""
|
|
60
|
+
|
|
61
|
+
def score_sentence(self, text: str) -> float:
|
|
62
|
+
return technical_density_score(self._normalized_sentence(text))
|