microsoft/TypeAgent
Publicmirrored from https://github.com/microsoft/TypeAgentAvailable
python/kp/knowpro/convindex.py
76lines · modecode
| 1 | # Copyright (c) Microsoft Corporation. |
| 2 | # Licensed under the MIT License. |
| 3 | |
| 4 | from dataclasses import dataclass, field |
| 5 | from typing import Callable |
| 6 | |
| 7 | from .interfaces import ( |
| 8 | # Interfaces. |
| 9 | IConversation, |
| 10 | IMessage, |
| 11 | ITermToSemanticRefIndex, |
| 12 | ITermToSemanticRefIndexData, |
| 13 | # Other imports. |
| 14 | IndexingEventHandlers, |
| 15 | IndexingResults, |
| 16 | Knowledge, |
| 17 | KnowledgeType, |
| 18 | MessageIndex, |
| 19 | ScoredSemanticRef, |
| 20 | SemanticRef, |
| 21 | TextLocation, |
| 22 | TextRange, |
| 23 | ) |
| 24 | |
| 25 | |
| 26 | def text_range_from_location( |
| 27 | message_index: MessageIndex, |
| 28 | chunk_index: int = 0, |
| 29 | ) -> TextRange: |
| 30 | return TextRange( |
| 31 | start=TextLocation(message_index, chunk_index), |
| 32 | end=None, |
| 33 | ) |
| 34 | |
| 35 | |
| 36 | type KnowledgeValidator = Callable[ |
| 37 | [ |
| 38 | KnowledgeType, # knowledge_type |
| 39 | Knowledge, # knowledge |
| 40 | ], |
| 41 | bool, |
| 42 | ] |
| 43 | |
| 44 | |
| 45 | def add_metadata_to_index[TMessage: IMessage]( |
| 46 | messages: list[TMessage], |
| 47 | semantic_refs: list[SemanticRef], |
| 48 | semantic_ref_index: ITermToSemanticRefIndex, |
| 49 | knowledge_validator: KnowledgeValidator | None = None, |
| 50 | ) -> None: |
| 51 | raise NotImplementedError |
| 52 | |
| 53 | |
| 54 | @dataclass |
| 55 | class ConversationIndex(ITermToSemanticRefIndex): |
| 56 | _map: dict[str, list[ScoredSemanticRef]] |
| 57 | |
| 58 | def __init__(self, data: ITermToSemanticRefIndexData | None = None): |
| 59 | self._map = {} |
| 60 | if data: |
| 61 | self.deserialize(data) |
| 62 | |
| 63 | # TODO: More methods |
| 64 | |
| 65 | def deserialize(self, data: ITermToSemanticRefIndexData) -> None: |
| 66 | raise NotImplementedError |
| 67 | |
| 68 | |
| 69 | # ... |
| 70 | |
| 71 | |
| 72 | async def build_conversation_index( |
| 73 | conversation: IConversation, |
| 74 | event_handler: IndexingEventHandlers | None = None, |
| 75 | ) -> IndexingResults: |
| 76 | raise NotImplementedError |
| 77 | |