a 'Îgb ã@sdddlZddlmZddlmZmZddlmZm Z ddl m Z Gdd„deƒZ Gd d „d e ƒZ dS) éN)ÚNDArray)ÚOptionalÚList)ÚABCÚabstractmethodé)Ú split_textc@sŠeZdZdZeddœdd„Zeeedœdd„ƒƒZ eddœd d „ƒZ eeed œd d „ƒZ ede e dœdd„ƒZeeedœdd„ƒZdS)ÚBaseContextPartitionera¼ A base class for partitioning a context into sources. Attributes: context (str): The context to partition. Methods: num_sources(self) -> int: Property. The number of sources within the context. split_context(self) -> None: Split the context into sources. get_source(self, index: int) -> str: Get a represention of the source corresponding to a given index. get_context(self, mask: Optional[NDArray] = None) -> str: Get a version of the context ablated according to the given mask. sources(self) -> List[str]: Property. A list of all sources within the context. N)ÚcontextÚreturncCs ||_dS©N)r )Úselfr ©rú>/mnt/userdata/context_cite/context_cite/context_partitioner.pyÚ__init__szBaseContextPartitioner.__init__©r cCsdS)zThe number of sources.Nr©r rrrÚ num_sources sz"BaseContextPartitioner.num_sourcescCsdS)zSplit the context into sources.NrrrrrÚ split_context%sz$BaseContextPartitioner.split_context©Úindexr cCsdS)z@Get a represention of the source corresponding to a given index.Nr©r rrrrÚ get_source)sz!BaseContextPartitioner.get_source©ÚmaskcCsdS)zAGet a version of the context ablated according to the given mask.Nr)r rrrrÚ get_context-sz"BaseContextPartitioner.get_contextcs‡fdd„tˆjƒDƒS)zA list of all sources.csg|]}ˆ |¡‘qSr)r)Ú.0ÚirrrÚ 4óz2BaseContextPartitioner.sources..)ÚrangerrrrrÚsources1szBaseContextPartitioner.sources)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚstrrÚpropertyrÚintrrrrrrrr!rrrrr sr cs‚eZdZdZdeeddœ‡fdd„ Zdd„Zed d „ƒZed d „ƒZ ee d œdd„ƒZ e edœdd„Z de edœdd„Z‡ZS)ÚSimpleContextPartitionerze A simple context partitioner that splits the context into sources based on a separator. ÚsentenceN)r Ú source_typer cstƒ |¡||_i|_dSr )Úsuperrr+Ú_cache)r r r+©Ú __class__rrr=s z!SimpleContextPartitioner.__init__cCs,t|j|jƒ\}}}||jd<||jd<dS)z9Split text into parts and cache the parts and separators.ÚpartsÚ separatorsN)rr r+r-)r r0r1Ú_rrrrBs z&SimpleContextPartitioner.split_contextcCs"|j d¡dur| ¡|jdS)Nr0©r-Úgetrrrrrr0HszSimpleContextPartitioner.partscCs"|j d¡dur| ¡|jdS)Nr1r3rrrrr1Nsz#SimpleContextPartitioner.separatorsrcCs t|jƒSr )Úlenr0rrrrrTsz$SimpleContextPartitioner.num_sourcesrcCs |j|Sr )r0rrrrrXsz#SimpleContextPartitioner.get_sourcercCst|durtj|jtd}t |j¡|}t |j¡|}d}tt||ƒƒD]$\}\}}|dkrf||7}||7}qJ|S)N)ÚdtypeÚr) ÚnpÚonesrÚboolÚarrayr1r0Ú enumerateÚzip)r rr1r0r rÚ separatorÚpartrrrr z$SimpleContextPartitioner.get_context)r*)N)r"r#r$r%r&rrr'r0r1r(rrrrrÚ __classcell__rrr.rr)7s  r))Únumpyr8Ú numpy.typingrÚtypingrrÚabcrrÚutilsrr r)rrrrÚs   /