🔍 Code Extractor

function has_wuxi_coding

Maturity: 38

Validates whether a filename starts with a Wuxi coding pattern consisting of dot-separated numeric segments (e.g., '2.13.4.1.2').

File:
/tf/active/vicechatdev/mailsearch/copy_signed_documents.py
Lines:
24 - 29
Complexity:
simple

Purpose

This function checks if a given filename begins with a specific hierarchical numbering pattern known as 'Wuxi coding', which consists of one or more numeric segments separated by dots. This pattern is commonly used in document management systems, file organization schemes, or classification systems where hierarchical numeric identifiers are prefixed to filenames. The function returns True if the pattern is found at the start of the filename, False otherwise.

Source Code

def has_wuxi_coding(filename):
    """Check if filename starts with wuxi coding pattern (e.g., '2.13.4.1.2')"""
    # Look for pattern at start of filename: digits.digits.digits etc
    import re
    pattern = r'^\d+(?:\.\d+)+'
    return bool(re.match(pattern, filename))

Parameters

Name Type Default Kind
filename - - positional_or_keyword

Parameter Details

filename: A string representing the filename to check. Expected to be a filename (with or without extension) that may or may not start with the Wuxi coding pattern. Can be a full path or just a filename. The function only checks the beginning of the string for the pattern.

Return Value

Returns a boolean value: True if the filename starts with the Wuxi coding pattern (one or more digits followed by one or more occurrences of a dot and more digits), False otherwise. The pattern must be at the very start of the filename string.

Dependencies

  • re

Required Imports

import re

Conditional/Optional Imports

These imports are only needed under specific conditions:

import re

Condition: imported lazily inside the function, always needed when function is called

Required (conditional)

Usage Example

import re

def has_wuxi_coding(filename):
    """Check if filename starts with wuxi coding pattern (e.g., '2.13.4.1.2')"""
    import re
    pattern = r'^\d+(?:\.\d+)+'
    return bool(re.match(pattern, filename))

# Example usage
print(has_wuxi_coding('2.13.4.1.2_document.pdf'))  # True
print(has_wuxi_coding('1.2.3_report.docx'))  # True
print(has_wuxi_coding('document_2.13.4.pdf'))  # False
print(has_wuxi_coding('123_file.txt'))  # False (needs at least one dot)
print(has_wuxi_coding('1.2'))  # True
print(has_wuxi_coding('no_coding_here.txt'))  # False

Best Practices

  • The function expects at least two numeric segments separated by a dot (e.g., '1.2'). A single number without a dot will return False.
  • The pattern only matches at the start of the filename string. If the Wuxi coding appears elsewhere in the filename, it will not be detected.
  • The function does not validate the semantic correctness of the Wuxi coding scheme, only its syntactic pattern.
  • Consider using os.path.basename() on full file paths before passing to this function if you only want to check the filename portion and not the directory path.
  • The regex pattern allows any number of numeric segments (minimum 2), so '1.2', '1.2.3', and '1.2.3.4.5.6.7.8.9' are all valid.
  • The function uses lazy import of 're' module inside the function, which is slightly less efficient if called repeatedly. Consider importing 're' at module level for better performance in production code.

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function has_wuxi_coding_v1 97.7% similar

    Validates whether a filename starts with a Wuxi coding pattern, which consists of numbers separated by dots (e.g., '2.13.4.1.2').

    From: /tf/active/vicechatdev/mailsearch/upload_non_wuxi_coded.py
  • function extract_document_code_v1 56.8% similar

    Extracts a structured document code (e.g., 2.13.4.3.3.2) from a filename using regex pattern matching.

    From: /tf/active/vicechatdev/mailsearch/enhanced_document_comparison.py
  • function find_best_folder 56.7% similar

    Finds the best matching folder in a directory tree by comparing hierarchical document codes with folder names containing numeric codes.

    From: /tf/active/vicechatdev/mailsearch/copy_signed_documents.py
  • function scan_wuxi2_folder_v1 51.8% similar

    Recursively scans a directory for PDF files, extracts document codes from filenames, and returns a dictionary mapping each unique document code to a list of file metadata dictionaries.

    From: /tf/active/vicechatdev/mailsearch/enhanced_document_comparison.py
  • function scan_wuxi2_folder 51.8% similar

    Recursively scans a wuxi2 folder for PDF documents, extracts document codes from filenames, and organizes them into a dictionary mapping codes to file information.

    From: /tf/active/vicechatdev/mailsearch/compare_documents.py
← Back to Browse