semantica.semantic_extract extracts structured information from unstructured text: the foundation of every knowledge graph in Semantica:
NERExtractor: named entity recognition with confidence scores and source attributionRelationExtractor: typed relationship extraction (founded_by,located_in, and custom types)TripletExtractor: direct(subject, predicate, object)triplet generation for RDF outputEventDetector: event detection with participants, temporal context, and confidence- Three extraction modes on every extractor:
"pattern"(no API key),"huggingface","llm"
Getting Started
Prerequisites & Setup
Step 1: Install DependenciesExported Classes
Method Selection Guide
- Pattern: No Setup
- HuggingFace: Custom Models
- LLM: Best Accuracy
- Fallback Chain
Zero dependencies, no API key required. Uses spaCy rules and regex to match standard entity types.
Method Availability by Extractor
Method Fallback Chains
For reliability, extractors support fallback chains that try methods in order until one succeeds:NER Merge Strategies
NERExtractor uses merge_strategy="fallback" by default, so a method list remains an ordered fallback chain. To run several methods together, choose one of the explicit strategies below:
eligible_methods=[...] to restrict the consensus denominator when the configured methods have different coverage, or use merge_strategy="union" for complementary rule extractors. method_weights only break an otherwise eligible exact-span cross-label tie; they never turn one method into multiple votes.
Each merged entity includes supporting_methods, vote_count, eligible_method_count, agreement, and per-method method_scores in its metadata. Consensus treats compatible label aliases such as PER/PERSON and ORGANIZATION/ORG as the same vote. It resolves a cross-label conflict only when the final spans are identical, using method weight, vote count, confidence, and a stable label order; nested entities at different spans remain available. ml and spacy are one backend for both voting and weights, so their weights are interchangeable (conflicting values are rejected). Boundary candidates are matched one-to-one only when their span IoU is at least 0.5 with every existing vote in that candidate; equal-confidence variants prefer the longer span. If a provider omits offsets, Semantica resolves its entity text against whole-word document matches before merging. This keeps repeated mentions with the same text distinct and prevents one broad span from acting as a vote for multiple mentions.
ensemble_voting=True is deprecated and maps to merge_strategy="union" during migration. Use merge_strategy="consensus" when method agreement is required.
Unlike fallback, union and consensus never inject a pattern-derived entity after the configured methods return no candidates. An empty result is therefore meaningful in those strategies.
Quick Start
Extractor Methods
NERExtractor
Custom Entity Types
v0.5.0 fix:
NERExtractor(method="llm") no longer silently falls back to pattern extraction on custom gateways. The response_format=json_object parameter is now conditionally omitted for incompatible gateways, with a plain generate() + JSON parsing fallback applied automatically.RelationExtractor
"pattern": rule-based pattern matching"dependency": spaCy dependency parsing"cooccurrence": proximity-based co-occurrence"huggingface": custom models"llm": highest accuracy, requires API key
TripletExtractor
Generate RDF-ready(subject, predicate, object) triplets directly from text:
EventDetector
Detect events with participants and temporal context:type: event category (e.g."founding","acquisition")participants: list of entities with rolestemporal: date or time referencelocation: location entity (when present)confidence: extraction confidence score
CoreferenceResolver
Resolve pronoun and alias references to canonical entities before extraction:Batch Processing
All extractors automatically detect batch input and process multiple texts efficiently:Using All Extractors Together
The standard extraction pipeline: entities → relationships → triplets:Extraction Method Comparison
- LLM Providers — Configure which LLM is used for extraction.
- Knowledge Graph — Build graphs from extracted entities and relationships.
- Parse Module — Parse documents before extraction.
- Deduplication — Resolve duplicate entities after extraction.
