MCPcopy Create free account
hub / github.com/SamuelZ12/longcut / findTopicForSegment

Function findTopicForSegment

lib/transcript-export.ts:64–88  ·  view source on GitHub ↗
(
  segment: TranscriptSegment,
  topics: Topic[] | undefined
)

Source from the content-addressed store, hash-verified

62}
63
64function findTopicForSegment(
65 segment: TranscriptSegment,
66 topics: Topic[] | undefined
67): string | undefined {
68 if (!topics?.length) {
69 return undefined;
70 }
71
72 const start = segment.start;
73 const end = segment.start + segment.duration;
74
75 for (const topic of topics) {
76 const overlaps = topic.segments.some((segmentRange) => {
77 const overlapStart = Math.max(start, segmentRange.start);
78 const overlapEnd = Math.min(end, segmentRange.end);
79 return overlapEnd - overlapStart > Math.min(segment.duration, segmentRange.end - segmentRange.start) * 0.3;
80 });
81
82 if (overlaps) {
83 return topic.title ?? undefined;
84 }
85 }
86
87 return undefined;
88}
89
90function sanitizeText(text: string): string {
91 return text.replace(/\s+/g, ' ').trim();

Callers 1

generateCsvContentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected