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 attribution
  • RelationExtractor: typed relationship extraction (founded_by, located_in, and custom types)
  • TripletExtractor: direct (subject, predicate, object) triplet generation for RDF output
  • EventDetector: 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 Dependencies
Step 2: Set API Keys (for LLM methods only)
Step 3: First Extraction

Exported Classes

NamedEntityRecognizer is the high-level coordinator with confidence thresholding and overlap merging. NERExtractor is the lower-level implementation. For most use cases, start with NERExtractor for simplicity or NamedEntityRecognizer for fine-grained control.

Method Selection Guide

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:
Consensus counts support against the configured eligible methods, not only methods that emitted a candidate. An empty or failed eligible method is therefore a non-supporting vote. Use 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

Semantic extraction pipeline: raw text fans into NER, Relation, and Coreference extractors, then merges into a Triplet Generator

Extractor Methods

NERExtractor

Output format:

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

Output format:
Available methods:
  • "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:
Triplets are suitable for loading directly into a triplet store or knowledge graph.

EventDetector

Detect events with participants and temporal context:
Output fields per event:
  • type: event category (e.g. "founding", "acquisition")
  • participants: list of entities with roles
  • temporal: date or time reference
  • location: 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:
Batch Input Options:

Using All Extractors Together

The standard extraction pipeline: entities → relationships → triplets:

Extraction Method Comparison