A comprehensive systematic dynamic knowledge graph system built in Python to analyze legal expert reports, extract entities, relationships, and arguments, and provide interactive exploration capabilities.
The solution is built upon three core pillars: a knowledge graph-based analysis engine, a generative AI-powered strategy assistant, and a sophisticated debate simulation platform.
This system addresses the Simmons and Simmons Challenge for building an evidence mapping solution that connects key entities, concepts, and positions from across multiple expert reports in litigation. It enables legal teams to quickly understand what each expert says about specific topics and how their views relate, support, or contradict each other.
- People (PERSON): Expert names, legal professionals, witnesses
- Organizations (ORG): Companies, institutions, legal entities
- Legal Terms: Damages, liability, breach, contracts, settlements
- Financial Information (MONEY): Monetary values, compensation amounts
- Temporal Data (DATE): Important dates and timelines
- Legal Cases: Case citations and references
- Percentages: Statistical data and percentages
- Financial Flow: Payment, investment, transfer relationships
- Information Flow: Communication, reporting, disclosure relationships
- Physical Flow: Delivery, transportation, supply relationships
- Argument Stances: Support, opposition, neutral positions
- Timeline visualization of events
- Chronological tracking of entity mentions
- Temporal relationship mapping
- Primary Arguments: Main claims and positions
- Supporting Arguments: Evidence and corroborations
- Counter Arguments: Disputes and contradictions
- Argument Strength Assessment: Linguistic confidence analysis
- Natural Language Queries: "Who discusses damages?" "Which experts disagree on valuation?"
- Network Visualizations: Interactive graph representations
- Debate Mapping: Dynamic back-and-forth argument analysis
- Analytical Dashboards: Comprehensive statistics and insights
pip install -r requirements.txtpython -m spacy download en_core_web_smFor enhanced date parsing:
pip install python-dateutilHackathon documents/
├── dynamic_knowledge_graph.py # Main knowledge graph system
├── streamlit_app.py # Interactive web interface
├── requirements.txt # Python dependencies
├── README.md # This file
├── knowledge_graph_output/ # Generated output directory
│ ├── entities.json
│ ├── relationships.json
│ ├── arguments.json
│ ├── temporal_events.json
│ ├── knowledge_graph.graphml
│ └── analysis_report.md
└── PDF files to be analyzed...
python dynamic_knowledge_graph.pyThis will:
- Process all PDF files in the directory
- Extract entities, relationships, and arguments
- Build the dynamic knowledge graph
- Generate interactive visualization (
dynamic_knowledge_graph.html) - Save all data to
knowledge_graph_output/ - Display comprehensive analysis report
streamlit run streamlit_app.pyAccess the web interface at http://localhost:8501 for:
- 🔍 Query Explorer: Natural language search
- 🕸️ Network View: Interactive graph visualization
- 📈 Analytics: Statistical analysis and charts
- ⏰ Temporal Analysis: Timeline visualizations
- 💬 Arguments: Argument mapping and analysis
The system supports sophisticated queries like:
- "What does Jeffrey Cohen say about damages?"
- "Which experts discuss valuation methodology?"
- "Who mentions Uruguay arbitration?"
- "Which experts disagree on compensation?"
- "What are the opposing views on liability?"
- "Find contradictory positions on market conduct"
- "Show all financial relationships"
- "What are the monetary damages mentioned?"
- "Find payment flows between entities"
- "What happened in 2020?"
- "Show chronological order of events"
- "Find recent expert opinions"
Uses advanced NLP techniques including:
- Spacy Named Entity Recognition
- Legal domain-specific regex patterns
- Fuzzy matching for entity resolution
Identifies relationships through:
- Co-occurrence analysis in sentences
- Pattern matching for relationship types
- Context-based relationship classification
Extracts temporal information using:
- Multiple date format recognition
- Context-aware date parsing
- Timeline construction
Analyzes arguments through:
- Argument keyword detection
- Stance classification (support/oppose/neutral)
- Strength assessment based on linguistic cues
Builds comprehensive graph with:
- NetworkX multi-directed graph structure
- Node attributes for entities
- Edge attributes for relationships
- Interactive query capabilities
The system generates multiple output formats:
entities.json: All extracted entities by documentrelationships.json: All relationships with contextarguments.json: All arguments with classificationstemporal_events.json: Timeline events with dates
knowledge_graph.graphml: NetworkX graph format- Interactive HTML visualization
analysis_report.md: Comprehensive analysis summary- Statistical breakdowns and insights
Easily extend with domain-specific entities:
self.legal_patterns = {
'custom_pattern': r'your_regex_pattern',
# Add more patterns as needed
}The system categorizes relationships into three main flows:
- Financial Flow: Money, payments, investments
- Information Flow: Communications, reports, disclosures
- Physical Flow: Deliveries, transfers, supplies
Automatically classifies argument stances:
- Support: Agreements, confirmations, validations
- Oppose: Contradictions, disputes, challenges
- Neutral: Mentions, discussions, references
- Color-coded nodes by entity type
- Hover information with details
- Filterable views by entity selection
- Dynamic layout with force-directed positioning
- Timeline scatter plots showing events over time
- Document-based timelines for cross-referencing
- Chronological event sequences
- Entity type distribution pie charts
- Relationship flow bar charts
- Argument type distributions
- Document statistics tables
- PDFProcessor: Extracts text from PDF files using PyPDF2 and pdfplumber
- NLPPipeline: Processes text using spaCy and transformers
- GraphBuilder: Constructs NetworkX graph from extracted data
- Visualizer: Creates interactive visualizations using Plotly and Pyvis
- QueryEngine: Enables natural language querying
PDF Files → Text Extraction → NLP Processing → Entity/Relationship Extraction → Graph Construction → Visualization/Query Interface
- Caching: Processed data is cached to avoid reprocessing
- Batch Processing: Documents processed in batches for efficiency
- Memory Management: Large texts split into manageable chunks
- Progressive Loading: Streamlit interface loads data progressively
- Machine Learning: Enhanced entity linking with ML models
- Multi-language Support: Extend to other languages
- Real-time Updates: Live document processing
- Advanced Analytics: Predictive analysis and trend detection
- Export Capabilities: Multiple format exports (PDF, Excel, etc.)
This system is designed to be modular and extensible. Key areas for enhancement:
- Custom Entity Types: Add domain-specific entities
- Relationship Patterns: Extend relationship detection
- Visualization Themes: Create custom visualization styles
- Query Interfaces: Build more sophisticated query capabilities
This project is developed for the Simmons and Simmons Challenge as a demonstration of dynamic knowledge graph capabilities for legal document analysis.
- Place your PDF files in the designated folder
- Run the main script:
python dynamic_knowledge_graph.py - Launch the web interface:
streamlit run streamlit_app.py - Explore your data through interactive queries and visualizations
The system will systematically process all PDFs, extract comprehensive knowledge, and provide you with a powerful tool for legal document analysis and exploration.
Built with ❤️ for the Simmons and Simmons Challenge