legal_summariser 0.2.0 โ†’ 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99da5ab12240efdb658eafc5b3e76ef46834f7a7d76bf86edfe1958ea75c4f58
4
- data.tar.gz: aa0ee6b2406771e99c22af8d5ab00145eeee8666a8ccbda9b96c48ed87e0e408
3
+ metadata.gz: 17172c652ce52a7b5707e22bcec192c56e3538255cc579cdf4d331de5caf2d6e
4
+ data.tar.gz: 16383b701c48ce0e674edfccd9eece8fa31b6659ca29ff4f073939bf735b7564
5
5
  SHA512:
6
- metadata.gz: 20d58233629912675fd4fa7a44c0813d1267e25bc0004df18d37c60ed069906f31d8a68cc165c337809ff040e874d41053b347eb4b3df46f98bf85451a1f654d
7
- data.tar.gz: f7bc3b2feab8929485a5387e93ecc0762b32d18903460ba5e33ea1a7c3dd010102c8cbe10feff018694c0ea2a9641c6919904da574a041a226d1de0f1134122b
6
+ metadata.gz: aa1b6fd284af5525e90b8cf15333eb2cfddecc1179142b7f8ea0df306e7a04f92a637e208e985de6517414ec60aa565ba8baba37f993952969a565641ad45d6e
7
+ data.tar.gz: 638343a4a36085b27561abe93e0374e1e034ad3dd701646d1d3d9d38537c41bb3bef243a32b191526b5237e16a8f933ee9055e51b5dc62b21411752bf40958ca
data/CHANGELOG.md CHANGED
@@ -5,6 +5,37 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.3.1] - 2025-01-09
9
+
10
+ ### Updated
11
+ - **Gem Metadata**: Updated author information and contact details
12
+ - **RubyGems Page**: Enhanced description and metadata for better discoverability
13
+ - **Links**: Updated all GitHub repository links to correct owner
14
+ - **Documentation**: Added additional metadata links (bug tracker, wiki, documentation)
15
+
16
+ ## [0.3.0] - 2025-01-09
17
+
18
+ ### Added
19
+ - **Plain Language Generator**: AI-powered legal text simplification with fine-tuned models
20
+ - **Model Training System**: Complete training pipeline for custom legal language models
21
+ - **Advanced Multilingual Support**: Enhanced processing for 8 languages with cultural adaptations
22
+ - **PDF Annotation System**: Rich PDF output with highlighting, comments, and risk indicators
23
+ - **AI/ML Integration**: Support for external AI APIs and local model training
24
+ - **Advanced NLP Features**: Readability scoring, complexity reduction metrics, and text analysis
25
+
26
+ ### Enhanced
27
+ - **Legal Text Processing**: 30+ legal jargon mappings and sentence pattern simplification
28
+ - **Cross-Language Translation**: Legal term mapping across multiple languages
29
+ - **Document Analysis**: Enhanced with plain language generation and multilingual processing
30
+ - **Performance Monitoring**: Extended metrics for new AI/ML operations
31
+ - **Error Handling**: Comprehensive error management for AI operations and model training
32
+
33
+ ### Technical Improvements
34
+ - **Model Architecture**: Pattern-based, statistical, and neural model support
35
+ - **Caching System**: Extended for translation and model results
36
+ - **API Integration**: Support for external translation and AI services
37
+ - **Cultural Adaptations**: Legal system-specific processing for different countries
38
+
8
39
  ## [0.2.0] - 2025-01-09
9
40
 
10
41
  ### Added
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,231 @@
1
+ # Contributing to Legal Summariser
2
+
3
+ Thank you for your interest in contributing to Legal Summariser! This document provides guidelines for contributing to the project.
4
+
5
+ ## ๐Ÿš€ Getting Started
6
+
7
+ ### Prerequisites
8
+
9
+ - Ruby 2.6 or higher
10
+ - Bundler gem
11
+ - Git
12
+
13
+ ### Development Setup
14
+
15
+ 1. Fork the repository
16
+ 2. Clone your fork:
17
+ ```bash
18
+ git clone https://github.com/your-username/legal_summariser.git
19
+ cd legal_summariser
20
+ ```
21
+
22
+ 3. Install dependencies:
23
+ ```bash
24
+ bundle install
25
+ ```
26
+
27
+ 4. Run tests to ensure everything works:
28
+ ```bash
29
+ bundle exec rspec
30
+ ```
31
+
32
+ ## ๐Ÿงช Testing
33
+
34
+ We maintain comprehensive test coverage. Please ensure all tests pass before submitting a PR:
35
+
36
+ ```bash
37
+ # Run all tests
38
+ bundle exec rspec
39
+
40
+ # Run tests with coverage
41
+ bundle exec rspec --format documentation
42
+
43
+ # Run specific test file
44
+ bundle exec rspec spec/text_extractor_spec.rb
45
+
46
+ # Run linter
47
+ bundle exec rubocop
48
+ ```
49
+
50
+ ### Writing Tests
51
+
52
+ - Write tests for all new functionality
53
+ - Follow existing test patterns and naming conventions
54
+ - Use descriptive test names that explain the expected behavior
55
+ - Include both positive and negative test cases
56
+ - Test edge cases and error conditions
57
+
58
+ ## ๐Ÿ“ Code Style
59
+
60
+ We follow Ruby community standards:
61
+
62
+ - Use 2 spaces for indentation
63
+ - Keep lines under 120 characters
64
+ - Use descriptive variable and method names
65
+ - Add comments for complex logic
66
+ - Follow RuboCop guidelines
67
+
68
+ Run the linter before submitting:
69
+ ```bash
70
+ bundle exec rubocop
71
+ ```
72
+
73
+ ## ๐Ÿ”ง Development Guidelines
74
+
75
+ ### Architecture
76
+
77
+ The gem follows a modular architecture:
78
+
79
+ - `TextExtractor`: Document parsing and text extraction
80
+ - `Summariser`: Text summarization and key point extraction
81
+ - `ClauseDetector`: Legal clause identification
82
+ - `RiskAnalyzer`: Risk assessment and compliance checking
83
+ - `Formatter`: Output formatting (JSON, Markdown, Text)
84
+ - `Cache`: Result caching system
85
+ - `PerformanceMonitor`: Performance tracking
86
+ - `Configuration`: Gem configuration management
87
+
88
+ ### Adding New Features
89
+
90
+ 1. **Create an issue** describing the feature
91
+ 2. **Write tests** for the new functionality
92
+ 3. **Implement the feature** following existing patterns
93
+ 4. **Update documentation** including README and code comments
94
+ 5. **Add examples** if applicable
95
+ 6. **Ensure all tests pass**
96
+
97
+ ### Adding New Document Types
98
+
99
+ To add support for a new document type:
100
+
101
+ 1. Add detection patterns in `detect_document_type` method
102
+ 2. Update supported formats documentation
103
+ 3. Add test cases for the new format
104
+ 4. Update CLI help text if needed
105
+
106
+ ### Adding New Risk Patterns
107
+
108
+ To add new risk detection patterns:
109
+
110
+ 1. Add patterns to `RiskAnalyzer` class
111
+ 2. Include severity levels and recommendations
112
+ 3. Add corresponding test cases
113
+ 4. Update documentation
114
+
115
+ ## ๐Ÿ“š Documentation
116
+
117
+ - Update README.md for user-facing changes
118
+ - Add inline documentation for new methods
119
+ - Include examples for new features
120
+ - Update CHANGELOG.md following semantic versioning
121
+
122
+ ## ๐Ÿ› Bug Reports
123
+
124
+ When reporting bugs, please include:
125
+
126
+ - Ruby version
127
+ - Gem version
128
+ - Operating system
129
+ - Steps to reproduce
130
+ - Expected vs actual behavior
131
+ - Sample files (if applicable and not confidential)
132
+
133
+ ## ๐Ÿ’ก Feature Requests
134
+
135
+ Feature requests should include:
136
+
137
+ - Clear description of the feature
138
+ - Use case and motivation
139
+ - Proposed implementation approach
140
+ - Potential impact on existing functionality
141
+
142
+ ## ๐Ÿ”„ Pull Request Process
143
+
144
+ 1. **Create a feature branch** from `main`:
145
+ ```bash
146
+ git checkout -b feature/your-feature-name
147
+ ```
148
+
149
+ 2. **Make your changes** following the guidelines above
150
+
151
+ 3. **Commit with descriptive messages**:
152
+ ```bash
153
+ git commit -m "Add support for new document format"
154
+ ```
155
+
156
+ 4. **Push to your fork**:
157
+ ```bash
158
+ git push origin feature/your-feature-name
159
+ ```
160
+
161
+ 5. **Create a Pull Request** with:
162
+ - Clear title and description
163
+ - Reference to related issues
164
+ - List of changes made
165
+ - Test results
166
+
167
+ ### PR Requirements
168
+
169
+ - [ ] All tests pass
170
+ - [ ] Code follows style guidelines
171
+ - [ ] Documentation is updated
172
+ - [ ] CHANGELOG.md is updated
173
+ - [ ] No breaking changes (or clearly documented)
174
+
175
+ ## ๐Ÿท๏ธ Release Process
176
+
177
+ Releases follow semantic versioning:
178
+
179
+ - **MAJOR**: Breaking changes
180
+ - **MINOR**: New features (backward compatible)
181
+ - **PATCH**: Bug fixes (backward compatible)
182
+
183
+ ## ๐Ÿค Code of Conduct
184
+
185
+ - Be respectful and inclusive
186
+ - Focus on constructive feedback
187
+ - Help others learn and grow
188
+ - Maintain professionalism
189
+
190
+ ## ๐Ÿ“ž Getting Help
191
+
192
+ - Create an issue for bugs or feature requests
193
+ - Join discussions in existing issues
194
+ - Contact maintainers for questions
195
+
196
+ ## ๐ŸŽฏ Areas for Contribution
197
+
198
+ We welcome contributions in these areas:
199
+
200
+ ### High Priority
201
+ - Additional document format support (ODT, RTF, HTML)
202
+ - Enhanced clause detection patterns
203
+ - Multi-language support improvements
204
+ - Performance optimizations
205
+
206
+ ### Medium Priority
207
+ - Additional risk assessment rules
208
+ - Better error handling and recovery
209
+ - Enhanced caching strategies
210
+ - CLI improvements
211
+
212
+ ### Documentation
213
+ - More usage examples
214
+ - Video tutorials
215
+ - API documentation improvements
216
+ - Translation to other languages
217
+
218
+ ## ๐Ÿ™ Recognition
219
+
220
+ Contributors will be:
221
+ - Listed in the README.md
222
+ - Mentioned in release notes
223
+ - Given credit in commit messages
224
+
225
+ ## ๐Ÿ“„ License
226
+
227
+ By contributing, you agree that your contributions will be licensed under the MIT License.
228
+
229
+ ---
230
+
231
+ Thank you for contributing to Legal Summariser! Your efforts help make legal document analysis more accessible to everyone. ๐Ÿš€
data/README.md CHANGED
@@ -6,7 +6,8 @@
6
6
 
7
7
  [![Ruby](https://img.shields.io/badge/Ruby-2.6+-red.svg)](https://ruby-lang.org)
8
8
  [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
9
- [![Tests](https://img.shields.io/badge/Tests-26%20passing-green.svg)](#testing)
9
+ [![Tests](https://img.shields.io/badge/Tests-100+%20passing-green.svg)](#testing)
10
+ [![Version](https://img.shields.io/badge/Version-0.3.0-blue.svg)](https://rubygems.org/gems/legal_summariser)
10
11
 
11
12
  ---
12
13
 
@@ -27,7 +28,8 @@
27
28
 
28
29
  ## Features
29
30
 
30
- - **Document Processing**: Supports PDF, DOCX, and plain text files
31
+ ### ๐Ÿš€ Core Analysis
32
+ - **Document Processing**: Supports PDF, DOCX, RTF, and plain text files
31
33
  - **Smart Summarisation**: Converts legal documents into concise plain English
32
34
  - **Clause Detection**: Automatically identifies key legal clauses including:
33
35
  - Data Processing & Privacy (GDPR/KVKK compliance)
@@ -40,8 +42,29 @@
40
42
  - Governing Law
41
43
  - **Risk Analysis**: Flags potential legal risks and unfair terms
42
44
  - **Compliance Checking**: Identifies gaps in GDPR, KVKK, and other regulations
43
- - **Multiple Output Formats**: JSON, Markdown, and plain text
44
- - **CLI Interface**: Command-line tool for batch processing
45
+
46
+ ### ๐Ÿค– AI/ML Features (v0.3.0)
47
+ - **Plain Language Generator**: AI-powered legal text simplification with 30+ jargon mappings
48
+ - **Model Training System**: Train custom legal language models (pattern-based, statistical, neural)
49
+ - **Readability Scoring**: Calculate complexity reduction and readability metrics
50
+ - **Fine-tuning Support**: Customize models for specific legal domains
51
+
52
+ ### ๐ŸŒ Multilingual Support
53
+ - **8 Languages Supported**: English, Spanish, French, German, Italian, Portuguese, Turkish, Dutch
54
+ - **Legal Term Translation**: Cross-language legal terminology mapping
55
+ - **Cultural Adaptations**: Legal system-specific processing for different countries
56
+ - **AI Translation Integration**: Support for external translation APIs
57
+
58
+ ### ๐Ÿ“„ Advanced Output
59
+ - **PDF Annotations**: Rich PDF output with highlighting, comments, and risk indicators
60
+ - **Multiple Formats**: JSON, Markdown, plain text, and annotated PDF
61
+ - **Batch Processing**: Process multiple documents simultaneously
62
+ - **Performance Monitoring**: Built-in metrics and caching system
63
+
64
+ ### ๐Ÿ› ๏ธ Developer Tools
65
+ - **CLI Interface**: Comprehensive command-line tool
66
+ - **Configuration System**: Flexible configuration with validation
67
+ - **Caching System**: Result caching with TTL and size management
45
68
  - **Offline Processing**: Works without internet for sensitive documents
46
69
 
47
70
  ## Installation
@@ -73,41 +96,76 @@ require "legal_summariser"
73
96
 
74
97
  # Basic usage
75
98
  summary = LegalSummariser.summarise("contracts/nda.pdf")
76
- puts summary[:plain_text]
77
- # => "This Non-Disclosure Agreement establishes confidentiality, valid for 2 years. The company may terminate at any time..."
99
+ puts summary[:plain_text] # AI-generated plain language version
100
+ puts summary[:summary] # Original summary
101
+ puts summary[:multilingual] # Multi-language processing results
78
102
 
79
- # With options
103
+ # Advanced AI features
80
104
  result = LegalSummariser.summarise("contract.pdf", {
81
105
  format: 'markdown',
82
- max_sentences: 3
106
+ max_sentences: 3,
107
+ language: 'es', # Process in Spanish
108
+ plain_language: true, # Enable AI plain language generation
109
+ generate_annotations: true # Create PDF annotations
83
110
  })
84
111
 
85
- # Access different parts of the analysis
112
+ # Access AI-enhanced analysis
86
113
  puts result[:key_points] # Key contract points
87
114
  puts result[:clauses] # Detected legal clauses
88
115
  puts result[:risks] # Risk analysis
89
- puts result[:metadata] # Document metadata
116
+ puts result[:plain_text] # AI-simplified version
117
+ puts result[:multilingual] # Multi-language results
118
+ puts result[:metadata] # Enhanced metadata with AI metrics
119
+
120
+ # Plain Language Generator
121
+ generator = LegalSummariser::PlainLanguageGenerator.new
122
+ plain_result = generator.generate("The party of the first part shall indemnify...")
123
+ puts plain_result[:text] # "The first party will compensate..."
124
+ puts plain_result[:readability_score] # Readability improvement metrics
125
+
126
+ # Model Training
127
+ trainer = LegalSummariser::ModelTrainer.new
128
+ trainer.train_model('contract_model', training_data, type: 'statistical')
129
+ trainer.fine_tune_model('contract_model', fine_tuning_data)
130
+
131
+ # Multilingual Processing
132
+ processor = LegalSummariser::MultilingualProcessor.new
133
+ result = processor.process_multilingual("contract.pdf", source: 'en', target: 'es')
134
+
135
+ # PDF Annotations
136
+ annotator = LegalSummariser::PDFAnnotator.new
137
+ annotator.create_annotated_pdf("contract.pdf", analysis_results, "annotated_contract.pdf")
90
138
  ```
91
139
 
92
140
  ### Command Line Interface
93
141
 
94
142
  ```bash
95
- # Analyze a document
143
+ # Basic analysis
96
144
  legal_summariser analyze contract.pdf
97
145
 
98
- # Specify output format
99
- legal_summariser analyze contract.pdf --format markdown
146
+ # AI-enhanced analysis with plain language
147
+ legal_summariser analyze contract.pdf --plain-language --format markdown
100
148
 
101
- # Save to file
102
- legal_summariser analyze contract.pdf --output summary.md --format markdown
149
+ # Multilingual processing
150
+ legal_summariser analyze contract.pdf --language es --translate-to en
103
151
 
104
- # Run demo
105
- legal_summariser demo
152
+ # Generate annotated PDF
153
+ legal_summariser analyze contract.pdf --annotate --output annotated_contract.pdf
106
154
 
107
- # Show supported formats
108
- legal_summariser supported_formats
155
+ # Batch processing with AI features
156
+ legal_summariser batch contracts/ --plain-language --multilingual
157
+
158
+ # Configuration and stats
159
+ legal_summariser config --set language=es
160
+ legal_summariser stats
109
161
 
110
- # Show version
162
+ # Model management
163
+ legal_summariser train-model --type statistical --data training_data.json
164
+ legal_summariser list-models
165
+
166
+ # Utility commands
167
+ legal_summariser demo
168
+ legal_summariser supported_formats
111
169
  legal_summariser version
112
170
  ```
113
171
 
@@ -176,11 +234,16 @@ The system automatically detects and optimizes analysis for:
176
234
  - **Pattern matching**: For compliance gap identification
177
235
 
178
236
  ### Key Components
179
- - **TextExtractor**: Multi-format document parsing
180
- - **Summariser**: Plain English conversion engine
181
- - **ClauseDetector**: Legal clause identification
182
- - **RiskAnalyzer**: Risk assessment and flagging
183
- - **Formatter**: Multi-format output generation
237
+ - **TextExtractor**: Multi-format document parsing (PDF, DOCX, RTF, TXT)
238
+ - **Summariser**: Enhanced plain English conversion engine
239
+ - **ClauseDetector**: Advanced legal clause identification
240
+ - **RiskAnalyzer**: Comprehensive risk assessment and flagging
241
+ - **PlainLanguageGenerator**: AI-powered legal text simplification
242
+ - **ModelTrainer**: Custom model training and fine-tuning system
243
+ - **MultilingualProcessor**: Cross-language processing and translation
244
+ - **PDFAnnotator**: Rich PDF annotation and highlighting
245
+ - **Formatter**: Multi-format output generation (JSON, Markdown, PDF)
246
+ - **Cache & Performance**: Advanced caching and performance monitoring
184
247
 
185
248
  ## Development
186
249
 
@@ -206,9 +269,9 @@ gem install ./legal_summariser-*.gem
206
269
  ## Roadmap
207
270
 
208
271
  - **v0.1** โœ… Text extraction + basic summarisation
209
- - **v0.2** โœ… Clause detection + risk flagging
210
- - **v0.3** ๐Ÿ”„ Plain language generator (fine-tuned models)
211
- - **v1.0** ๐Ÿ“‹ Multi-language support + PDF annotation output
272
+ - **v0.2** โœ… Clause detection + risk flagging + performance enhancements
273
+ - **v0.3** โœ… AI/ML features + multilingual support + PDF annotations
274
+ - **v1.0** ๐Ÿ“‹ Advanced neural models + enterprise features + API service
212
275
 
213
276
  ## Contributing
214
277
 
@@ -234,7 +297,7 @@ This tool is designed to assist with legal document analysis but should not repl
234
297
  This project leverages my expertise in:
235
298
 
236
299
  - **Ruby Development**: Gem architecture, modular design patterns
237
- - **AI & NLP**: Rule-based text analysis, pattern recognition
300
+ - **AI & NLP**: Advanced machine learning, neural networks, multilingual processing
238
301
  - **Cybersecurity**: Compliance frameworks (GDPR, KVKK), risk assessment
239
302
  - **Digital Forensics**: Legal document analysis, evidence extraction
240
303
  - **Software Engineering**: Test-driven development, CLI tools
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Example: Advanced configuration and customization
5
+ require 'legal_summariser'
6
+ require 'logger'
7
+
8
+ puts "=== Advanced Legal Summariser Configuration ==="
9
+
10
+ # Example 1: Custom logging configuration
11
+ puts "\n1. Custom Logging Setup"
12
+ custom_logger = Logger.new('legal_analysis.log')
13
+ custom_logger.level = Logger::DEBUG
14
+ custom_logger.formatter = proc do |severity, datetime, progname, msg|
15
+ "[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}] #{severity}: #{msg}\n"
16
+ end
17
+
18
+ LegalSummariser.configure do |config|
19
+ config.logger = custom_logger
20
+ config.language = 'en'
21
+ config.max_file_size = 20 * 1024 * 1024 # 20MB
22
+ config.timeout = 60 # 60 seconds
23
+ config.enable_caching = true
24
+ config.cache_dir = './custom_cache'
25
+ end
26
+
27
+ puts "Configuration applied successfully!"
28
+
29
+ # Example 2: Multi-language support
30
+ puts "\n2. Multi-language Configuration"
31
+ LegalSummariser.configure do |config|
32
+ config.language = 'tr' # Turkish
33
+ end
34
+
35
+ puts "Language set to Turkish (TR)"
36
+ puts "Supported languages: #{LegalSummariser.configuration.supported_languages.join(', ')}"
37
+
38
+ # Example 3: Performance monitoring
39
+ puts "\n3. Performance Monitoring"
40
+ monitor = LegalSummariser.performance_monitor
41
+
42
+ # Simulate some operations for demonstration
43
+ monitor.start_timer(:demo_operation)
44
+ sleep(0.1) # Simulate work
45
+ monitor.end_timer(:demo_operation)
46
+
47
+ monitor.record(:demo_metric, 42.5)
48
+ monitor.record(:demo_metric, 38.2)
49
+
50
+ puts "Performance Report:"
51
+ puts monitor.report
52
+
53
+ # Example 4: Cache management
54
+ puts "\n4. Cache Management"
55
+ cache = LegalSummariser::Cache.new
56
+
57
+ # Show cache statistics
58
+ cache_stats = cache.stats
59
+ puts "Cache Status: #{cache_stats[:enabled] ? 'Enabled' : 'Disabled'}"
60
+
61
+ if cache_stats[:enabled]
62
+ puts "Cache Directory: #{cache_stats[:cache_dir]}"
63
+ puts "Cached Files: #{cache_stats[:file_count]}"
64
+ puts "Cache Size: #{cache_stats[:total_size_mb]} MB"
65
+ end
66
+
67
+ # Example 5: Error handling and validation
68
+ puts "\n5. Configuration Validation"
69
+ begin
70
+ LegalSummariser.configure do |config|
71
+ config.language = 'invalid_language'
72
+ end
73
+ rescue LegalSummariser::Error => e
74
+ puts "Configuration error caught: #{e.message}"
75
+ end
76
+
77
+ # Reset to valid configuration
78
+ LegalSummariser.configure do |config|
79
+ config.language = 'en'
80
+ end
81
+
82
+ # Example 6: Custom analysis workflow
83
+ puts "\n6. Custom Analysis Workflow"
84
+ def analyze_with_custom_workflow(file_path)
85
+ puts "Starting custom analysis workflow for: #{file_path}"
86
+
87
+ # Start performance monitoring
88
+ monitor = LegalSummariser.performance_monitor
89
+ monitor.start_timer(:custom_workflow)
90
+
91
+ begin
92
+ # Step 1: Basic analysis
93
+ puts "Step 1: Performing basic analysis..."
94
+ result = LegalSummariser.summarise(file_path)
95
+
96
+ # Step 2: Custom risk assessment
97
+ puts "Step 2: Custom risk assessment..."
98
+ risk_score = result[:risks][:risk_score][:score]
99
+
100
+ custom_risk_level = case risk_score
101
+ when 0..5 then 'Very Low'
102
+ when 6..15 then 'Low'
103
+ when 16..30 then 'Medium'
104
+ when 31..50 then 'High'
105
+ else 'Critical'
106
+ end
107
+
108
+ # Step 3: Generate custom report
109
+ puts "Step 3: Generating custom report..."
110
+ custom_report = {
111
+ file_path: file_path,
112
+ analysis_timestamp: Time.now.iso8601,
113
+ document_info: {
114
+ type: result[:metadata][:document_type],
115
+ word_count: result[:metadata][:word_count],
116
+ processing_time: result[:metadata][:extraction_time_seconds]
117
+ },
118
+ summary: result[:plain_text],
119
+ risk_assessment: {
120
+ standard_score: risk_score,
121
+ custom_level: custom_risk_level,
122
+ high_priority_issues: result[:risks][:high_risks].length,
123
+ compliance_gaps: result[:risks][:compliance_gaps].length
124
+ },
125
+ recommendations: generate_custom_recommendations(result)
126
+ }
127
+
128
+ workflow_time = monitor.end_timer(:custom_workflow)
129
+ custom_report[:workflow_time_seconds] = workflow_time.round(3)
130
+
131
+ puts "Custom workflow completed in #{workflow_time.round(3)}s"
132
+ return custom_report
133
+
134
+ rescue => e
135
+ monitor.end_timer(:custom_workflow)
136
+ puts "Workflow failed: #{e.message}"
137
+ return nil
138
+ end
139
+ end
140
+
141
+ def generate_custom_recommendations(analysis_result)
142
+ recommendations = []
143
+
144
+ # Risk-based recommendations
145
+ high_risks = analysis_result[:risks][:high_risks]
146
+ if high_risks.any?
147
+ recommendations << "URGENT: Address #{high_risks.length} high-risk issues before signing"
148
+ high_risks.each { |risk| recommendations << "- #{risk[:recommendation]}" }
149
+ end
150
+
151
+ # Compliance recommendations
152
+ compliance_gaps = analysis_result[:risks][:compliance_gaps]
153
+ if compliance_gaps.any?
154
+ recommendations << "COMPLIANCE: Review #{compliance_gaps.length} regulatory gaps"
155
+ compliance_gaps.each { |gap| recommendations << "- #{gap[:recommendation]}" }
156
+ end
157
+
158
+ # Document type specific recommendations
159
+ doc_type = analysis_result[:metadata][:document_type]
160
+ case doc_type
161
+ when 'nda'
162
+ recommendations << "NDA: Verify confidentiality scope and duration"
163
+ when 'employment_contract'
164
+ recommendations << "EMPLOYMENT: Check termination clauses and benefits"
165
+ when 'service_agreement'
166
+ recommendations << "SERVICE: Review deliverables and payment terms"
167
+ end
168
+
169
+ recommendations
170
+ end
171
+
172
+ # Example usage of custom workflow
173
+ puts "\n7. Custom Workflow Example"
174
+ # Replace with actual file path
175
+ sample_file = '/tmp/sample_contract.txt'
176
+ File.write(sample_file, "Sample contract content for demonstration purposes.")
177
+
178
+ custom_result = analyze_with_custom_workflow(sample_file)
179
+ if custom_result
180
+ puts "\nCustom Analysis Result:"
181
+ puts JSON.pretty_generate(custom_result)
182
+ end
183
+
184
+ # Cleanup
185
+ File.delete(sample_file) if File.exist?(sample_file)
186
+
187
+ # Example 8: System statistics and monitoring
188
+ puts "\n8. System Statistics"
189
+ system_stats = LegalSummariser.stats
190
+ puts "System Performance Overview:"
191
+ puts "- Performance Metrics: #{system_stats[:performance].keys.join(', ')}"
192
+ puts "- Cache Status: #{system_stats[:cache][:enabled] ? 'Active' : 'Inactive'}"
193
+ puts "- Memory Usage: #{system_stats[:memory][:memory_mb]} MB" if system_stats[:memory][:available]
194
+
195
+ puts "\nAdvanced configuration examples completed!"