/ core / attention / __pycache__ / multi_source_correlator.cpython-314.pyc
multi_source_correlator.cpython-314.pyc
  1  +
  2  �=giGm���Rt^RIt^RIt^RIt^RIHtHt^RIHtHt^RI	H
  3  t
  4  ^RIHtH
t
HtHtHtHt^RIHt^RIHtHtHt!RR	]4t]!R
  5  R44t]!RR
44t]!RR44t!RR4tRRRllt]R8Xd:]!R4]!4t ] PC^�R7t"]!]"PG44R#R#)a"
  6  Multi-Source Correlator
  7  
  8  Correlates events across multiple data sources to triangulate high-confidence insights:
  9  - Claude sessions (text transcripts)
 10  - Monologue voice transcripts (with intonation context)
 11  - Comet browser history (what was being researched)
 12  
 13  Time-aligned correlation reveals:
 14  - What you were researching when you had an insight
 15  - Voice emphasis that corroborates text-based signals
 16  - Validation-seeking moments with full context
 17  
 18  Usage:
 19      correlator = MultiSourceCorrelator()
 20      report = correlator.correlate(hours_back=168)
 21  N)�	dataclass�field)�datetime�	timedelta)�Path)�Dict�List�Optional�Set�Tuple�Any)�Enum)�SignalWordDetector�SignalDetection�detect_signalsc�&�]tRt^ tRtRtRtRtRtR#)�EventSourcezSources of events.�claude_session�	monologue�
comet_browser�N)	�__name__�
 22  __module__�__qualname__�__firstlineno__�__doc__�CLAUDE_SESSION�	MONOLOGUE�
COMET_BROWSER�__static_attributes__r��I/Users/rcerf/repos/Sovereign_OS/core/attention/multi_source_correlator.pyrr s���%�N��I�#�Mr rc�da�]tRt^'toRtRtRtRtRtRt	Rt
 23  Rt]!]
R7tRtV3RltRtVtR#)�SourceEventzA single event from any source.N��?��default_factoryc�D�VPf\4VnR#R#�N)�tags�set)�selfs&r!�
__post_init__�SourceEvent.__post_init__:s���9�9����D�I�r c�<�V^8�dQh/S[;R&S[;R&S[;R&S[S[,;R&S[S[,;R&S[S[,;R&S[S[,;R&S[S[,;R&S[S[,;R	&S[;R
 24  &S[S[,;R&#)��source�	timestamp�content�
 25  session_id�browser_url�
browser_title�browser_context�speaker�signals�weightr))rr�strr	r�floatr
 26  )�format�
__classdict__s"�r!�__annotate__�SourceEvent.__annotate__'s�����
�����	�
 27  �L����
�$���#��%���C�=�'���c�]�)���c�]�!���o�
&�-�� 
��!�"�c�(�/�#r )r))rrrrrr3r4r5r6r7r8r9rr*r)r,�__annotate_func__r�__classdictcell__�r=s@r!r#r#'sE����)�!%�J�!%�K�#'�M�%)�O�!�G�*.�G��F��3�/�D��'�r r#c��a�]tRt^?toRt]!]R7t]!]R7t]!]R7t	Rt
 28  Rt]!]R7t
RtRtRt]V3RlRl4tV3RlR	ltV3R
 29  lRltV3RltR
tVtR#)�CorrelatedMomentz&A moment where multiple sources align.r%r$�Fc� <�V^8�dQhRS[/#�r/�return)�int)r<r=s"�r!r>�CorrelatedMoment.__annotate__Us���	�	�c�	r c��^pVP'd
 30  V^,
pVP'd
 31  V^,
pVP'd
 32  V^,
pV#)z.Number of sources contributing to this moment.)�
claude_events�monologue_events�browser_events)r+�counts& r!�source_count�CorrelatedMoment.source_countTsM���������Q�J�E�� � � ��Q�J�E������Q�J�E��r c�0<�V^8�dQhRS[S[,/#rG�r	r:)r<r=s"�r!r>rJ`s�����X�c�]�r c���VP'dYVPUu.uF"qP'gKVPNK$	ppV'dRPVR,4#R#uupi)z1Get what was being researched during this moment.z | :N�NN)rNr5�join)r+�e�titless&  r!�get_browser_context�$CorrelatedMoment.get_browser_context`sS������/3�/B�/B�V�/B�!�o�o�o�a�o�o�/B�F�V���z�z�&��*�-�-���Ws
 33  �A-�A-c�6<�V^8�dQhRS[S[S[3,/#rG)rr:r)r<r=s"�r!r>rJhs���
 34  �
 35  ��c�3�h��
 36  r c���RVPP4RVPRVPRVPR\VP4RVPRVPRVP4RVPR	,Uu.uFqPR
 37  ,NK	upRVPR	,Uu.uFqPR
 38  ,NK	up/
 39  #uupiuupi)r1rP�combined_weight�
 40  confidence�topics�
is_aha_moment�is_validation_seekingr6�claude_content:Nr/N�N��N�monologue_content)
r1�	isoformatrPr]r^�listr_r`rarYrLr2rM)r+rWs& r!�to_dict�CorrelatedMoment.to_dicths�������1�1�3��D�-�-��t�3�3��$�/�/��d�4�;�;�'��T�/�/�#�T�%?�%?��t�7�7�9���8J�8J�2�8N�O�8N�1�y�y����8N�O��4�;P�;P�QS�;T�!U�;T�a�)�)�D�/�/�;T�!U�
 41 42  ��P��!Us�C$&�C)*c��<�V^8�dQh/S[;R&S[;R&S[S[,;R&S[S[,;R&S[S[,;R&S[;R&S[;R&S[S[,;R&S[;R	&S[;R
 43  &S[;R&#)r/r1�window_secondsrLrMrNr]r^r_r`ra�is_research_corroborated)rr;rr#r
 44  r:�bool)r<r=s"�r!r>rJ?s����������	���$�B���;�'�E����%�C��� �����
��H�1��"��#�$ �'�%�&#�*�'r rN)rrrrrrrgrLrMrNr]r^r*r_r`rarl�propertyrPrYrhr@rrArBs@r!rDrD?s�����0�
 45  (-�T�'B�M�*/��*E��(-�d�(C�N�!�O��J��S�1�F� �M�"'��%*��
�	��	���
 46  �
 47  �S�r rDc�a�]tRt^wtoRt]!]R7t]!]R7t]!]R7t	]!]R7t
 48  ]!]R7t^t
^t^tV3RlRltV3RltRtVtR#)�CorrelationReportz*Full report from multi-source correlation.r%c� <�V^8�dQhRS[/#rG)r:)r<r=s"�r!r>�CorrelationReport.__annotate__�s���; �; �S�; r c�.	�RRVPR
RVPRVPR2R.pVPR4VPP4Fwr#VPRVR	VR
 49  24K	VPR4VP'EdQVPR4VPR,EFpVPR
VPPR424VPRVPR
RVPR24VP4'd#VPRVP424VPR,F)pVPRVPR,R24K+	VPR,F)pVPRVPR,R24K+	EK	VPR4VP'd�VPR4VPR4VPR,F�pVPR
VPPR424VP4'd#VPRVP424VPR,F)pVPRVPR,R24K+	K�	VPR4VP 'd�VPR4VPR4VP R,F�pVPR
VPPR424VPRVP424VP;'g
VPR,F)pVPRVPR,R24K+	K�	VPR4VP"'d�VPR 4\%VP"P4R!R"7R#,F=wrgVPR
V24VR$,FpVPR%V24K	K?	R&P'V4#)'z!# Multi-Source Correlation Report�*z.0fz hours, z	 events, z correlated moments*�z
 50  ## Sourcesz- **z**: z eventsz'## Aha Moments (Multi-Source Confirmed)�N�
 51  Nz
 52  ### z%Y-%m-%d %H:%Mz
*Confidence: z.0%z, Sources: z**Researching:** :N�Nz
 53  > :Ni,Nz...z
 54  
 55  *Voice:* rcz## Validation-Seeking Momentsz8*Times you asked 'what do you think?' with full context*z
**Context:** z> z!## Research-Corroborated Insightsz:*Insights where browser history shows supporting research*z**Researched:** z## Topics and Related Researchc�(�\V^,4)#)rx)�len)�xs&r!�<lambda>�/CorrelationReport.to_markdown.<locals>.<lambda>�s��C��!��I�:r ��key:N�N:N�Nz- �
 56  )�time_window_hours�total_events�multi_source_moments�append�
sources_found�items�aha_momentsr1�strftimer^rPrYrLr2rM�validation_seeking�research_corroborated�topic_research_map�sortedrV)	r+�linesr0rO�moment�event�topic�urls�urls	&        r!�to_markdown�CorrelationReport.to_markdown�s��/���&�&�s�+�8�D�4E�4E�3F�i�PT�Pi�Pi�Oj�j~���
 57  ��	���\�"�!�/�/�5�5�7�M�F��L�L�4��x�t�E�7�'�:�;�8�
���R�������L�L�B�C��*�*�3�/�/�����v�f�&6�&6�&?�&?�@P�&Q�%R�S�T����}�V�->�->�s�,C�;�v�Ob�Ob�Nc�cd�e�f��-�-�/�/��L�L�#4�V�5O�5O�5Q�4R�!S�T�#�1�1�"�5�5�E��L�L�4��
�
�d�(;�'<�C�!@�A�6�#�4�4�R�8�8�E��L�L�;�u�}�}�T�/B�.C�3�!G�H�9�0�
�L�L����"�"�"��L�L�8�9��L�L�S�T��1�1�#�6�6�����v�f�&6�&6�&?�&?�@P�&Q�%R�S�T��-�-�/�/��L�L�=��1K�1K�1M�0N�!O�P�#�1�1�"�5�5�E��L�L�2�e�m�m�D�&9�%:�#�!>�?�6�	7�
�L�L����%�%�%��L�L�<�=��L�L�U�V��4�4�S�9�9�����v�f�&6�&6�&?�&?�@P�&Q�%R�S�T����/��0J�0J�0L�/M�N�O�$�2�2�M�M�f�6M�6M�r�R�R�E��L�L�2�e�m�m�D�&9�%:�#�!>�?�S�:�
 58  
�L�L����"�"�"��L�L�9�:�%�d�&=�&=�&C�&C�&E�)=� ?�?B� D� D������v�e�W�-�.���8�8�C��L�L�2�c�U��,�$� D��y�y���r c�<�V^8�dQh/S[;R&S[S[S[3,;R&S[S[,;R&S[S[,;R&S[S[,;R&S[S[,;R&S[S[S[S[,3,;R&S[;R&S[;R	&S[;R
 59  &#)r/r�r�r�r�r��high_confidence_momentsr�r��correlated_eventsr�)r;rr:rIrrD)r<r=s"�r!r>rrws����������S��>�!�	��&�'�E���-�.�L�� � 0�1�O��"�"2�3�Q���S�$�s�)�^�,�J��$��%�&��'�(�!�)r rN)rrrrrrrgr�r�r�r��dictr�r�r�r�r�r@rrArBs@r!rprpwsh����4�
 60  +0��*E�K�16�t�1L��49�$�4O��7<�D�6Q��05�T�/J���L��� !��; �; �-�r rpc�ha�]tRt^�toRt]P!4R,t]P!4R,t]P!4R,t	Rt
 61  RV3RlRlltRV3R	lR
 62  lltV3RlRlt
V3R
lRltV3RlRltRtV3RlRltV3RlRltV3RlRltV3RlRltRtVtR#)�MultiSourceCorrelatora
 63  Correlates events across Claude sessions, Monologue, and Comet browser.
 64  
 65  The key insight: when you have an "aha" moment that appears in Claude text,
 66  is emphasized in your voice (Monologue), AND was preceded by specific research
 67  (Comet), that's a high-confidence validated insight.
 68  z%repos/Sovereign_Estate/daily/sessionszwLibrary/Mobile Documents/iCloud~md~obsidian/Documents/Sovereign_Estate/research/cognitive-capture/monologue-transcriptsz1Library/Application Support/Comet/Default/Historyi,Nc�\<�V^8�dQhRS[S[,RS[S[,RS[S[,/#)r/�sessions_dir�
monologue_dir�comet_history_pathrS)r<r=s"�r!r>�"MultiSourceCorrelator.__annotate__�s:���E�E��s�m�E� ��}�E�%�S�M�	Er c��V'd\V4MVPVnV'd\V4MVPVnV'd\V4MVP
 69  Vn\4Vn.Vn	/Vn
 70  R#r()r�DEFAULT_SESSIONS_DIRr��DEFAULT_MONOLOGUE_DIRr��DEFAULT_COMET_HISTORY�
comet_historyr�signal_detector�_events�_events_by_time)r+r�r�r�s&&&&r!�__init__�MultiSourceCorrelator.__init__�sg��3?�D��.�D�D]�D]���4A�T�-�0�t�Ga�Ga���9K�T�"4�5�QU�Qk�Qk���1�3���+-���BD��r c�2<�V^8�dQhRS[RS[RS[RS[/#)r/�
 71  hours_back�correlation_window�
 72  min_weightrH�r;rp)r<r=s"�r!r>r��s9���Q
 73  �Q
 74  ��Q
 75  �"�Q
 76  ��	Q
 77 78  
 79  �Q
 80  r c�N�T;'g
VPp\P!4\VR7,
 81  p.Vn/pVPV4pVPP
V4\V4VR&VPV4pVPP
V4\V4VR&VPV4p	VPP
V	4\V	4VR&VPPRR7VP4VPWC4p
 82  .p.p.p
.pV
 83  F�pVPV4VP'dVPV4VP 'dVPV4VP"'dV
PV4VP$R8�gK�VPV4K�	VP'V
 84  4p\)TT\+VRR7R	,\+VR
 85  R7R	,\+V
RR7R	,\+VRR7R
,T\VP4\-RV
 86  44\V
 87  Uu.uFpVP.^8�gKVNK	up4R7
 88  #uupi)z�
 89  Run multi-source correlation.
 90  
 91  Args:
 92      hours_back: How far back to look
 93      correlation_window: Seconds to consider events related (default 300)
 94      min_weight: Minimum signal weight to include
 95  
 96  Returns:
 97      CorrelationReport with findings
 98  )�hours�claude_sessionsrrc��VP#r()r1)rWs&r!r|�1MultiSourceCorrelator.correlate.<locals>.<lambda>s����r r~��?c��VP)#r(�r]��ms&r!r|r�5s
��1�;L�;L�:Lr :N�Nc��VP)#r(r�r�s&r!r|r�6s
���IZ�IZ�HZr c��VP)#r(r�r�s&r!r|r�7s
��q�O`�O`�N`r c��VP)#r()r^r�s&r!r|r�8s
 99  ��1�<�<�-r :N�2Nc3�>"�TFqP^8�x�K	R#5i)rxN)rP)�.0r�s& r!�	<genexpr>�2MultiSourceCorrelator.correlate.<locals>.<genexpr>;s���!F�g��.�.�1�"4�g�s�)
100  r�r�r�r�r�r�r�r�r�r�)�CORRELATION_WINDOWr�nowrr��_load_claude_sessions�extendrz�_load_monologue_transcripts�_load_comet_history�sort�_build_time_index�_find_correlated_moments�_classify_momentr`r�rarlr^�_build_topic_research_maprpr��sumrP)r+r�r�r��window�cutoffr�rLrMrN�momentsr�r�r��high_confidencer�r�r�s&&&&              r!�	correlate�MultiSourceCorrelator.correlate�s]��"$�>�>�t�'>�'>������)�*�"=�=������
��2�2�6�:�
������M�*�+.�}�+=�
�'�(� �;�;�F�C�������,�-�%(�)9�%:�
�k�"��1�1�&�9�������N�+�),�^�)<�
�o�&�	
�����3��4�	
��� ��/�/��C������ "�����F��!�!�&�)��#�#�#��"�"�6�*��+�+�+�"�)�)�&�1��.�.�.�%�,�,�V�4�� � �C�'��&�&�v�.��"�;�;�G�D��!�(�'��{�0L�M�c�R�%�&8�>Z�[�\_�`�"(�)>�D`�"a�be�"f�$*�?�@W�$X�Y\�$]�1��T�\�\�*�!�!F�g�!F�F�!$��%O��A�A�N�N�Q�<N�a�a��%O�!P�
101102  ��&Ps�8J"�J"c�6<�V^8�dQhRS[RS[S[,/#�r/r�rH�rrr#)r<r=s"�r!r>r�?s$���e�e�H�e��k�9J�er c
��.pVPP4'gV#VPPR4EF&p\P!VP4P4pWA8dK;VPp\P!RV4pV'gKh\P!VP^4R4pVP4pTp	VPR4p
103  Rp.pRp
V
104  EF�p\P!RV4pV'EdV'd�V'd�RPV4P4pV'd�\!V4^
105  8�d�VP#V
P$V
P&V
P(R7p\+V4p\-\.P0VVV	VVVP2VP4R7pVP7V4VP^4p\P!VR	4P94p
VP^4p.pEK:V'gEKE\P:!R
106  RV4pVP4'gEKvVP7V4EK�	V'd�V'd�RPV4P4pV'd�\!V4^
107  8�d�V
'd�VP#V
P$V
P&V
P(R7p\+V4p\-\.P0VVV	VVVP2VP4R7pVP7V4EKEKEK EK#EK&EK)	V# \<d
pRp?EK?Rp?ii;i)z>Load events from Claude session transcripts (markdown format).z	*-live.mdz(\d{4}-\d{2}-\d{2})z%Y-%m-%dr�Nz8^\s*-?\s*\*\*\[(\d{2}:\d{2}:\d{2})\]\s+(Rick|Claude)\*\*)�hour�minute�second)r0r1r2r3r7r8r9r)z%H:%M:%Sz^\s*-\s*ru)r��exists�globr�
fromtimestamp�stat�st_mtime�stem�re�match�strptime�group�	read_text�splitrV�striprz�replacer�r�r�rr#rr�weight_modifier�suggested_tagsr��time�sub�	Exception)r+r��events�session_file�mtime�filename�
108  date_match�	base_dater2r3r��current_speaker�current_content�current_time�line�
speaker_match�textr1r8r��time_str�
109  clean_linerWs&&                     r!r��+MultiSourceCorrelator._load_claude_sessions?s������ � �'�'�)�)��M�!�-�-�2�2�;�?�L�Z
� �.�.�|�/@�/@�/B�/K�/K�L���>��(�,�,���X�X�&<�h�G�
110  �!��$�-�-�j�.>�.>�q�.A�:�N�	�&�0�0�2��%�
111  � �
�
�d�+��"&��"$��#��!�D�$&�H�H�S��%�M�
112  %�}�*��#'�9�9�_�#=�#C�#C�#E�D�#��D�	�B��,5�,=�,=�)5�):�):�+7�+>�+>�+7�+>�+>�->�-"�	�+9��*>��(3�+6�+E�+E�.7�,0�/9�,;�,3�+2�+B�+B�)0�)?�)?�	)"��!'�
�
�e� 4�$1�#6�#6�q�#9��'/�'8�'8��:�'N�'S�'S�'U��*7�*=�*=�a�*@��*,��(��&(�V�V�K��T�%B�
113  �%�+�+�-�-�+�2�2�:�>�W"�\#���9�9�_�5�;�;�=�D���D�	�B��<�$-�$5�$5�!-�!2�!2�#/�#6�#6�#/�#6�#6�%6�%�	�
114  #1��"6�� +�#.�#=�#=�&/�$(�'1�$3�$+�#*�#:�#:�!(�!7�!7�	!���
�
�e�,�#4@��t�(7�?�K@�z�
���
���
�sW�4M-�;*M-�(A<M-�%M-�-&M-�C$M-�>+M-�/M-�
M-�&M-�<M-�BM-�-N�?Nc�6<�V^8�dQhRS[RS[S[,/#r�r�)r<r=s"�r!r>r��s$���B�B�(�B�t�K�?P�Br c
��.pVPP4'gV#\P!R4p\P!R4pVPP	R4EFppVP4p\P!RV4pRp\V4EF2wr�VPV
115  4pV'd)\P!VP^44pKGVeW�8dKSV
116  P4pV'd\V4^
117  8dK}Rp
VPV4pV'd@VP^4P4p
VPRV4P4pV'gK�\!V4p\#\$P&VVV
RVVP(VP*R7pVP-V4EK5	EKs	V# RpL�;i \.d
pRp?EK�Rp?ii;i)	z-Load events from Monologue voice transcripts.z+###\s+(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})z\[Context:\s*([^\]]+)\]z*.mdz+(###\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})Nru�Rick)r0r1r2r6r7r8r9r))r�r�r��compiler�r�r��	enumerater�r�
fromisoformatr�r�rz�searchr�rr#rrr�r�r�r�)r+r�r��timestamp_pattern�context_pattern�md_filer2�sections�current_timestamp�i�section�ts_matchr�r6�	ctx_matchr8r�rWs&&                r!r��1MultiSourceCorrelator._load_monologue_transcripts�s������!�!�(�(�*�*��M��J�J�'U�V���*�*�%?�@���)�)�.�.�v�6�G�4
�!�+�+�-���8�8�$R�T[�\��$(�!�"+�H�"5�J�A�0�6�6�w�?�H��5�08�0F�0F�x�~�~�VW�GX�0Y�-�!�(�0�4E�4N� �#�=�=�?�D��3�t�9�r�>� �'+�O� /� 6� 6�t� <�I� �*3�/�/�!�*<�*B�*B�*D��.�2�2�2�t�<�B�B�D��� �-�T�2�G�'�*�4�4�"3� $�(7� &� '�&�6�6�$�3�3�	�E��M�M�%�(�U#6�7�n�
��S5�04�-��J�
���
�s?�1AG,�%G#�*%G,�,G,�=AG,�AG,�#G)�'G,�,H�>Hc�6<�V^8�dQhRS[RS[S[,/#r�r�)r<r=s"�r!r>r��s$���C�C�(�C�t�K�7H�Cr c
118  �a
�.pVPP4'gV#\P!RVPR2RR7pVP	4p\R^^4p\
W,
119  P4R,4pVPRV34VP4F�pVwpo
p	V\VR7,p
120  S
PR	4'gS
PR
121  4'dKM\\PT
122  T	;'gS
S
T	RR7p\;QJdT
3R
lR4F'gKRM	RM!T
3R
lR44'd#RTnTP"P%R4TP'T4K�	VP)4V# EK;i \*dpRp?T#Rp?ii;i)z Load browser history from Comet.zfile:z?mode=roT)�uriiAi@Bz�
123                  SELECT
124                      last_visit_time,
125                      url,
126                      title
127                  FROM urls
128                  WHERE last_visit_time > ?
129                  ORDER BY last_visit_time
130              )�microsecondsz	chrome://zchrome-extension://r�)r0r1r2r4r5r9c3�,<"�TF	qS9x�K	R#5ir(r)r��domainr�s& �r!r��<MultiSourceCorrelator._load_comet_history.<locals>.<genexpr>s�����4���}�4�s�Fr$�researchN)z	arxiv.orgzscholar.googlez
wikipedia.orgz
131  github.comzstackoverflow.comz
132  medium.comz
133  nature.comzsciencedirect.com)r�r��sqlite3�connect�cursorrrI�
total_seconds�execute�fetchallr�
134  startswithr#rr�anyr9r)�addr��closer�)r+r�r��connr�chrome_epoch�
cutoff_chrome�row�chrome_time�titler1r�rWr�s&&           @r!r��)MultiSourceCorrelator._load_comet_history�s�������!�!�(�(�*�*��M�:	��?�?�U�4�+=�+=�*>�h�#G�T�R�D��[�[�]�F�$�D�!�Q�/�L���!6� E� E� G�'� Q�R�M�
�N�N�� �!�
#����(��*-�'��S�%�� ,�y�k�/R� R�I�
135  �>�>�+�.�.�#�.�.�AV�2W�2W��$�&�4�4�'�!�L�L�S� #�"'��
���3��4��3�3�3��4����
136  $'�E�L��J�J�N�N�:�.��
�
�e�$�A)�D
�J�J�L�
137  �
��C���:�	���
��	�sO�BF;�=F2�F;�'F;�>F;�F;�4F;�F;�)AF;�2F8�4F;�;G�Gc���/VnVPFapVPP^^R7pW P9d.VPV&VPV,P	V4Kc	R#)z*Index events by time for efficient lookup.�r��microsecondN)r�r�r1r�r�)r+r�rs&  r!r��'MultiSourceCorrelator._build_time_index/sf��!����\�\�E��/�/�)�)���)�B�C��.�.�.�,.��$�$�S�)�� � ��%�,�,�U�3�"r c�<<�V^8�dQhRS[RS[RS[S[,/#)r/r�r�rH)r;rrD)r<r=s"�r!r>r�9s/���>�>��>��>�
138  ��	�	>r c� �.p\4pVPEFkpVPV8dKVPP	^^R7pWd9dK<VPV4VP\
VR7,
139  pVP\
VR7,pVPU	u.uF#p	WyPu;8:d
140  V8:gKMK!V	NK%	p
141  p	V
142  'gK�\VPVR7pV
143  F�p	V	P\P8XdVPPV	4MuV	P\P8XdVPPV	4M:V	P\P8XdVP PV	4VP"P%V	P&4K�	VPVP,VP ,pV'dP\)RV44VnV;P*^RVP,^,
144  ,,,unVP/V4VnVPV4EKn	V#uup	i)z.Find moments where multiple sources correlate.r*)�seconds)r1rkc3�8"�TFqPx�K	R#5ir()r9�r�rWs& r!r��AMultiSourceCorrelator._find_correlated_moments.<locals>.<genexpr>ms���,J�z�!�X�X�z���g333333�?)r*r�r9r1r�r rrDr0rrrLr�rrMrrNr_�updater)�maxr]rP�_calculate_confidencer^)
r+r�r�r��processed_timesr��
145  window_key�window_start�
146  window_endrW�related_eventsr��
147  all_eventss
&&&          r!r��.MultiSourceCorrelator._find_correlated_moments9s
148  �����%���\�\�E��|�|�j�(�����0�0��q�0�I�J��,�����
149  �+�!�?�?�Y�v�-F�F�L����9�V�+D�D�J� �<�<��'�a��;�;�<�*�<��<��<�
��
150  "��&��/�/�%��F�
151  $���8�8�{�9�9�9��(�(�/�/��2��X�X��!6�!6�6��+�+�2�2�1�5��X�X��!:�!:�:��)�)�0�0��3��
�
�$�$�Q�V�V�,�$� �-�-��0G�0G�G�&�J_�J_�_�J��),�,J�z�,J�)J��&��&�&�1�s�f�6I�6I�A�6M�/N�+N�O�&�!%� :� :�6� B�F���N�N�6�"�e"�h���Ms�.J�
J�Jc�&<�V^8�dQhRS[RS[/#)r/r�rH)rDr;)r<r=s"�r!r>r�ys���-$�-$�,<�-$��-$r c���RpW!PR,,
p\4pVPF<pVP'gKVP	VPP
152  4K>	VPF<pVP'gKVP	VPP
153  4K>	RV9gRV9d
154  VR,
pRV9d
155  VR,
pRV9d
156  VR,
pR	V9d
157  VR,
pVP'd�VP'gVP'd�R
158  PRVP44P4pR
159  PVP4P4p\VP44p\VP44pWx,'d
160  VR,
p\VR4#)
z�
161  Calculate confidence score for a correlated moment.
162  
163  Factors:
164  - Number of sources (more = higher confidence)
165  - Signal word alignment across sources
166  - Research relevance
167  rEg�?�aha�insightg333333�?�	principleg�������?�decision�needs_validation� c3�8"�TFqPx�K	R#5ir()r2r1s& r!r��>MultiSourceCorrelator._calculate_confidence.<locals>.<genexpr>�s���#M�7L�!�I�I�7L�r3r$)
rPr*rLr8r4r�rMrNrV�lowerr_r��min)	r+r�r^�all_tagsrW�browser_text�
168  topic_text�topic_words�
browser_wordss	&&       r!r6�+MultiSourceCorrelator._calculate_confidenceys����
169  �	�)�)�D�0�0�
170  ��5���%�%�A��y�y�y�����	�	� 8� 8�9�&��(�(�A��y�y�y�����	�	� 8� 8�9�)�
171  �H��	�X� 5��$��J��(�"��#��J���!��#��J���)��#��J�� � � �f�&:�&:�&:�f�>U�>U�>U��8�8�#M�v�7L�7L�#M�M�S�S�U�L����&�-�-�0�6�6�8�J��j�.�.�0�1�K��� 2� 2� 4�5�M��*�*��d�"�
172  ��:�s�#�#r c� <�V^8�dQhRS[/#)r/r�)rD)r<r=s"�r!r>r��s���3�3�'7�3r c�.�VPVP,FipVP'gKRVPP9gRVPP9gKOVP^8�gKbRVnM	VPVP,F;pVP'gKRVPP9gK4RVnM	VP'dVPR8�d
173  RVn	R#R#R#)z"Classify a moment into categories.r@rATrDg333333�?N)
174  rLrMr8r�rPr`rarNr]rl)r+r�rWs&& r!r��&MultiSourceCorrelator._classify_moment�s����%�%��(?�(?�?�?�A��y�y�y�e�q�y�y�'?�'?�?�9�PQ�PY�PY�Ph�Ph�Ch��&�&��*�+/�F�(��	@��%�%��(?�(?�?�?�A��y�y�y�/�1�9�9�3K�3K�K�/3��,��@�� � � �V�%;�%;�c�%A�.2�F�+�&B� r c�\<�V^8�dQhRS[S[,RS[S[S[S[,3,/#)r/r�rH)rrDrr:)r<r=s"�r!r>r��s2������&�'��
175  �c�4��9�n�	�r c��/pVF�pVP'gKVPUu.uF"qDP'gKVPNK$	ppVPF$pWb9d.W&&W&,PV4K&	K�	VF0p\	\
176  P
W&,44R,W&&K2	V#uupi)z/Build a map of topics to related research URLs.rv)rNr4r_r�rgr��fromkeys)r+r��
177  topic_urlsr�rWr�r�s&&     r!r��/MultiSourceCorrelator._build_topic_research_map�s���
178  ,.�
179  ��F��(�(�(��+1�+@�+@�R�+@�a�M�M�M�A�M�M�+@�D�R������*�(*�J�%��!�(�(��.�'�
� �E� $�T�]�]�:�3D�%E� F�s� K�J�� ����Ss�C�C)r�r�r�r�r�r�)NNN)�Nr$)rrrrrr�homer�r�r�r�r�r�r�r�r�r�r�r6r�r�rrArBs@r!r�r��s������ �9�9�;�)P�P�� �I�I�K�+d�d�� �I�I�K�*]�]����E�E� Q
180  �Q
181  �fe�e�NB�B�HC�C�J4�>�>�@-$�-$�^3�3�(�r r�c�0�V^8�dQhR\R\/#)r/r�rHr�)r<s"r!r>r>�s��7�7�%�7�2C�7r c�:�\4pVPVR7#)z%Quick correlation across all sources.�r�)r�r�)r��
182  correlators& r!�correlate_sourcesr^�s��&�(�J����:��6�6r �__main__z === Multi-Source Correlator ===
183  r\)rX)$r�jsonr�r�dataclassesrrrr�pathlibr�typingrrr	r
184  rr�enumr
�signal_wordsrrrrr#rDrpr�r^r�printr]r��reportr�rr r!�<module>rhs����$�	��(�(��8�8��M�M�$�$�$������.�4
185  �4
186  ��4
187  �n�P �P ��P �fG�G�V7��z��	�
188  -�.�&�(�J�
�
!�
!�S�
!�
1�F�	�&�
189  �
190  �
191  ��
r