"""
Example script demonstrating how to use the literature search module.
"""

from literature_search import LiteratureSearcher
from pathlib import Path
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def main():
    # Initialize the literature searcher
    # Note: Replace with your email and API key
    searcher = LiteratureSearcher(
        email="your.email@example.com",
        api_key="your_api_key_here",  # Optional but recommended
        max_papers_per_feature=20,
        cache_dir="cache"  # Optional: for caching results
    )
    
    # Example features to analyze
    features = [
        "SOD1",  # Gene symbol
        "TARDBP",  # Gene symbol
        "C9ORF72"  # Gene symbol
    ]
    
    # Create output directory
    output_dir = Path("literature_results")
    output_dir.mkdir(exist_ok=True)
    
    # Analyze each feature
    results = {}
    for feature in features:
        logger.info(f"Analyzing literature for {feature}...")
        
        # Perform literature analysis
        feature_results = searcher.analyze_feature_literature(feature)
        
        # Store results
        results[feature] = feature_results
        
        # Log summary
        logger.info(f"Found {feature_results['total_papers']} papers")
        logger.info("Mechanistic terms with hits:")
        for term, papers in feature_results['mechanistic_papers'].items():
            if papers:
                logger.info(f"  {term}: {len(papers)} papers")
    
    # Export results
    searcher.export_results(results, output_dir)
    logger.info(f"Results exported to {output_dir}")

if __name__ == "__main__":
    main() 