File size: 1,246 Bytes
742b2a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class CitationManager:
    def add_citations(self, analysis, search_results):
        """
        Add citations to the analysis based on source URLs
        """
        if not search_results:
            return analysis
            
        # Create a simple citation mapping
        citations = {}
        for i, result in enumerate(search_results):
            citation_id = f"[{i+1}]"
            citations[citation_id] = {
                'url': result.get('url', ''),
                'title': result.get('title', 'Untitled'),
                'source': result.get('source', 'Unknown')
            }
        
        # Add citation references to analysis
        cited_analysis = analysis
        # In a more sophisticated implementation, we would match claims to sources
        # For now, we'll just append the citation list
        
        return cited_analysis, citations
    
    def format_bibliography(self, citations):
        """
        Format citations into a bibliography
        """
        bib_items = []
        for cite_id, info in citations.items():
            bib_item = f"{cite_id} {info['title']}. {info['source']}. Retrieved from: {info['url']}"
            bib_items.append(bib_item)
        return "\n".join(bib_items)