API reference¶
Search and resolve personal names in text corpora.
- search_names.augment_names(input_file, prefix_column='seat', name_column='FirstName', output_file='augmented_clean_names.csv', prefix_file=None, nickname_file=None)[source]¶
Write a copy of the input with deterministic prefix/nickname columns.
- search_names.clean_names(input_file, output_file='clean_names.csv', name_column='Name', keep_duplicates=False)[source]¶
Parse names, preserve source columns, and write normalized CSV records.
- search_names.merge_results(input_files, output_file='merged_search_results.csv')[source]¶
Concatenate compatible CSV files and return the number of data rows.
- search_names.preprocess(input_file, patterns=('FirstName LastName', 'NickName LastName', 'Prefix LastName'), output_file='deduped_augmented_clean_names.csv', edit_length_thresholds=(), drop_patterns=None)¶
Build long-form patterns and remove ambiguous near-duplicates.
- search_names.search_names(corpus_file, names, output_file='search_results.csv', *, text_column='text', input_columns=('uniqid', 'text'), max_results=20, fuzzy_rules=None, processes=4, chunk_size=1000)[source]¶
Search every corpus row and write a stable, wide result table.
- search_names.setup_logging(level='INFO', rich_tracebacks=True, show_time=True, show_path=False)[source]¶
Set up logging with rich formatting.
- Parameters:
- Returns:
Configured logger instance
- Return type:
- search_names.split_text_corpus(input_file, output_pattern='{basename}_{chunk_id:04d}.csv', chunk_size=1000)[source]¶
Split a CSV file and return the number of chunks written.
Correct, deterministic exact and fuzzy name matching.
- class search_names.engines.SearchEngine(names, fuzzy_rules=None)[source]¶
Compile name patterns once and search many documents.
Enhanced name parser with support for both HumanName and parsernaam.
- class search_names.enhanced_name_parser.ParsedName(original, first_name=None, middle_name=None, last_name=None, title=None, suffix=None, nickname=None, model_score=None, parser_used='humanname')[source]¶
Unified parsed name representation.
- Parameters:
- class search_names.enhanced_name_parser.NameParser(parser_type='auto', batch_size=100, ml_threshold=0.8)[source]¶
Enhanced name parser with multiple backend support.
- Parameters:
- parse_with_parsernaam(names)[source]¶
Parse names using parsernaam (batch processing).
- Parameters:
- Return type:
- parse(name: str) ParsedName[source]¶
- parse(name: list[str]) list[ParsedName]
Parse one or more names.
- parse_dataframe(df, name_column='name', add_components=True)[source]¶
Parse names in a DataFrame.
- Parameters:
- Returns:
DataFrame with parsed names
- Raises:
TypeError – If the name column contains non-string values.
ValueError – If the requested name column does not exist.
- Return type:
DataFrame
- search_names.enhanced_name_parser.parse_names(names, parser_type='auto', name_column='name')[source]¶
Convenience function to parse names.
- Parameters:
- Returns:
Parsed results in same format as input
- Return type:
ParsedName | list[ParsedName] | DataFrame
- search_names.enhanced_name_parser.compare_parsers(name)[source]¶
Compare results from different parsers.
- Parameters:
name (str) – Name to parse
- Returns:
Dictionary with results from each parser
- Return type:
Optional spaCy recognition and Sentence Transformer name linking.
- exception search_names.nlp_engine.NLPEngineError[source]¶
Exception raised for NLP engine related errors.
- class search_names.nlp_engine.SpacyNER(model_name='en_core_web_sm', disable_components=None)[source]¶
spaCy-based Named Entity Recognition for person detection.
- extract_entities(text, entity_types=None)[source]¶
Extract named entities from text.
- Parameters:
- Returns:
List of entity mentions
- Raises:
NLPEngineError – If the spaCy model is unavailable or processing fails.
- Return type:
- extract_person_entities(text, min_length=2)[source]¶
Extract person entities specifically.
- Parameters:
- Returns:
List of person entity mentions
- Raises:
ValueError – If
min_lengthis less than one.- Return type:
- class search_names.nlp_engine.SemanticSimilarity(model_name='sentence-transformers/all-MiniLM-L6-v2', revision=None, local_files_only=False)[source]¶
Semantic similarity matching using sentence transformers.
- compute_similarity(text1, text2)[source]¶
Compute semantic similarity between two texts.
- Parameters:
- Returns:
Cosine similarity score between -1 and 1.
- Raises:
NLPEngineError – If the model is unavailable or encoding fails.
- Return type:
- find_similar_names(target_name, candidate_names, threshold=0.8)[source]¶
Find names similar to target name.
- Parameters:
- Returns:
List of (name, similarity_score) tuples above threshold
- Raises:
NLPEngineError – If the sentence-transformer model is unavailable.
ValueError – If
thresholdis outside the valid cosine range.
- Return type:
- class search_names.nlp_engine.EntityLinker(knowledge_base, semantic_model=None)[source]¶
Simple entity linking using string matching and semantic similarity.
- link_entity(mention, similarity_threshold=0.8)[source]¶
Link entity mention to knowledge base.
- Parameters:
mention (EntityMention) – Entity mention to link
similarity_threshold (float) – Threshold for semantic similarity matching
- Returns:
Entity linking result
- Raises:
ValueError – If
similarity_thresholdis outside the cosine range.- Return type:
- class search_names.nlp_engine.NLPEngine(spacy_model='en_core_web_sm', similarity_model='sentence-transformers/all-MiniLM-L6-v2', similarity_revision=None, knowledge_base=None, enable_ner=True, enable_similarity=False, enable_linking=False)[source]¶
Main NLP engine combining all components.
- Parameters:
- process_text(text, extract_entities=True, link_entities=False, min_name_length=2, similarity_threshold=0.8)[source]¶
Process text with all available NLP components.
- Parameters:
- Returns:
Dictionary with processing results
- Raises:
NLPEngineError – If a requested component was not enabled.
ValueError – If linking is requested without entity extraction.
- Return type:
- enhance_name_search(search_names, text_corpus, context_window=100)[source]¶
Enhance name search with NLP context analysis.
- Parameters:
- Returns:
Enhanced search results with context analysis
- Raises:
ValueError – If a name is blank or
context_windowis negative.- Return type:
Validated result types used by the NLP components.
- class search_names.models.EntityMention(*, text, label, start, end)[source]¶
A named-entity span returned by spaCy.
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class search_names.models.EntityLinkingResult(*, mention, linked_entity_id=None, linked_entity_name=None, match_method=None, score=None, alternative_entities=<factory>)[source]¶
The canonical entity selected for one mention, if any.
- Parameters:
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Four-stage workflow for name processing.
This module provides a systematic 4-step pipeline for processing names:
Step 1: Clean - Parse and standardize raw names Step 2: Augment - Add supplementary data (nicknames, prefixes) Step 3: Preprocess - Create search patterns and deduplicate Step 4: Search - Execute deterministic exact or fuzzy search
Each step builds on the previous one, creating a complete name processing workflow.
- search_names.pipeline.augment_names(input_file, prefix_column='seat', name_column='FirstName', output_file='augmented_clean_names.csv', prefix_file=None, nickname_file=None)[source]¶
Write a copy of the input with deterministic prefix/nickname columns.
- search_names.pipeline.clean_names(input_file, output_file='clean_names.csv', name_column='Name', keep_duplicates=False)[source]¶
Parse names, preserve source columns, and write normalized CSV records.
- search_names.pipeline.preprocess_names(input_file, patterns=('FirstName LastName', 'NickName LastName', 'Prefix LastName'), output_file='deduped_augmented_clean_names.csv', edit_length_thresholds=(), drop_patterns=None)[source]¶
Build long-form patterns and remove ambiguous near-duplicates.