Files
semantica/cookbook/advanced/01_Advanced_Extraction.ipynb
KaifAhmad1 7a6f1d0417 docs: add citation section and fix stale org references
Add a Cite Us section to the README with BibTeX citation info, and
align it with docs/citation.md (author/organization: Semantica, 2026).
Update LICENSE and docs/project-license.md copyright holder to
Semantica, and replace the stale Hawksight-AI GitHub org slug with
semantica-agi across READMEs, plugin manifests, cookbook notebooks,
and GitHub templates.
2026-08-24 16:07:22 +05:30

6.6 KiB

Open In Colab

Advanced Extraction

Overview

This notebook demonstrates advanced semantic extraction using EventDetector, CoreferenceResolver, TripletExtractor, SemanticAnalyzer, SemanticNetworkExtractor, LLMEnhancer, and ExtractionValidator.

Documentation: API Reference

Learning Objectives

  • Use EventDetector to detect events
  • Use CoreferenceResolver to resolve coreferences
  • Use TripletExtractor to extract RDF triplets
  • Use SemanticAnalyzer for semantic analysis
  • Use SemanticNetworkExtractor to extract semantic networks
  • Use LLMEnhancer for LLM-based enhancement
  • Use ExtractionValidator to validate extractions

Installation

Install Semantica from PyPI:

pip install semantica
# Or with all optional dependencies:
pip install semantica[all]

Workflow: Event Detection → Coreference Resolution → Triplet Extraction → Semantic Analysis → Network Extraction → LLM Enhancement → Validation

In [ ]:
!pip install -q semantica
In [ ]:
from semantica.semantic_extract import (
    EventDetector, CoreferenceResolver, TripletExtractor,
    SemanticAnalyzer, SemanticNetworkExtractor, LLMEnhancer, ExtractionValidator
)

text = "Apple Inc. was founded by Steve Jobs in 1976. The company is now led by Tim Cook."

event_detector = EventDetector()
events = event_detector.detect_events(text)

print(f"Detected {len(events)} events")
for event in events[:3]:
    print(f"  Event: {event.event_type} - {event.text[:50]}")

Step 2: Coreference Resolution

Resolve coreferences in text.

In [ ]:
coreference_resolver = CoreferenceResolver()

coreferences = coreference_resolver.resolve(text)

print(f"Resolved {len(coreferences)} coreference chains")

Step 3: Triplet Extraction

Extract RDF triplets.

In [ ]:
triplet_extractor = TripletExtractor()

triplets = triplet_extractor.extract_triplets(text)

print(f"Extracted {len(triplets)} triplets")
for triplet in triplets[:3]:
    print(f"  ({triplet.get('subject', '')}, {triplet.get('predicate', '')}, {triplet.get('object', '')})")

Step 4: Semantic Analysis

Perform semantic analysis.

In [ ]:
semantic_analyzer = SemanticAnalyzer()

semantic_roles = semantic_analyzer.analyze_semantic_roles(text)

print(f"Analyzed semantic roles: {len(semantic_roles)}")

Step 5: Semantic Network Extraction

Extract semantic networks.

In [ ]:
semantic_network_extractor = SemanticNetworkExtractor()

semantic_network = semantic_network_extractor.extract_network(text)

print(f"Extracted semantic network with {len(semantic_network.get('nodes', []))} nodes")
print(f"Edges: {len(semantic_network.get('edges', []))}")

Step 6: LLM Enhancement

Enhance extractions using LLM.

In [ ]:
llm_enhancer = LLMEnhancer()

enhanced_extractions = llm_enhancer.enhance_extractions(events, text)

print(f"Enhanced {len(enhanced_extractions)} extractions")

Step 7: Extraction Validation

Validate extractions.

In [ ]:
extraction_validator = ExtractionValidator()

validation_result = extraction_validator.validate(events, text)

print(f"Extraction validation:")
print(f"  Valid: {validation_result.valid}")
print(f"  Confidence: {validation_result.confidence:.3f}")

Summary

You've learned advanced extraction capabilities:

  • EventDetector: Event detection and classification
  • CoreferenceResolver: Coreference resolution
  • TripletExtractor: RDF triplet extraction
  • SemanticAnalyzer: Semantic analysis and role labeling
  • SemanticNetworkExtractor: Semantic network extraction
  • LLMEnhancer: LLM-based extraction enhancement
  • ExtractionValidator: Extraction validation