mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-09-10 04:00:35 +00:00
2.9 KiB
2.9 KiB
Refactor Semantic Extract Module to Class-Based Interfaces
📝 Summary
This PR refactors the Semantic Extract module to promote a cleaner, object-oriented API for Entity, Relation, and Triple extraction. It standardizes the usage around NERExtractor, RelationExtractor, and TripleExtractor classes, replacing the previous low-level get_entity_method factory functions in user-facing code.
🚀 Motivation
The previous API relied heavily on factory functions (get_entity_method("pattern")), which made discovery and configuration difficult for users. The new class-based approach:
- Improves code readability and IDE auto-completion.
- Provides a consistent interface (
extractor.extract()) across all extraction tasks. - Aligns the documentation and cookbooks with the actual best practices.
🔍 Key Changes
1. API Refactoring
- Standardized Classes: Promoted
NERExtractor,RelationExtractor, andTripleExtractoras the primary entry points. - Method Aliases: Added
extract()aliases toextract_entities()andextract_relations()for a uniform API surface. - Configuration: Unified configuration passing via class constructors.
2. Documentation Updates (docs/reference/semantic_extract.md)
- Added missing documentation for Semantic Networks, Coreference Resolution, and LLM Enhancement.
- Updated all code examples to use the new class-based API.
- Added a "Semantic Networks" card to the overview for better discoverability.
3. Cookbook Updates
05_Entity_Extraction.ipynb: Refactored to useNERExtractorfor Pattern, Regex, ML, and LLM examples.06_Relation_Extraction.ipynb: Refactored to useRelationExtractorfor dependency and pattern-based examples.11_Chunking_and_Splitting.ipynb: Updated to use consistent method names (ner_method="ml").
4. Split Module Improvements
- Method Aliasing: Added aliases in
methods.pyto support "spacy" (mapping to "ml") and "ml" (mapping to "dependency" for relations), improving robustness and user experience. - Robustness: Verified
EntityAwareChunkerandRelationAwareChunkerfallback mechanisms.
5. Testing
- Added
tests/test_ner_configurations.pyto verify all NER method configurations. - Added
tests/test_notebooks_verification.pyto ensure notebook examples run correctly. - Added
tests/test_semantic_extract_deepdive.pycovering relation and triple extraction scenarios.
🧪 Verification
- Unit Tests: All new tests pass, verifying correct instantiation and execution of extractors.
- Notebooks: Verified that the updated cookbooks run without errors.
- Documentation: previewed
semantic_extract.mdto ensure correct rendering of new sections.
✅ Checklist
- Code follows the project's coding standards.
- Documentation has been updated to reflect the changes.
- Tests have been added to cover the new functionality.
- Cookbooks have been updated and verified.