🔍 Code Extractor

function has_wuxi_coding_v1

Maturity: 33

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

File:
/tf/active/vicechatdev/mailsearch/upload_non_wuxi_coded.py
Lines:
17 - 20
Complexity:
simple

Purpose

This function is designed to identify files that follow a specific hierarchical numbering convention known as 'Wuxi coding'. It checks if the filename begins with a pattern of one or more digits followed by additional dot-separated digit sequences. This is commonly used in document management systems, version control, or organizational file naming schemes where hierarchical numeric identifiers are used to categorize or order files.

Source Code

def has_wuxi_coding(filename):
    """Check if filename starts with wuxi coding pattern (e.g., '2.13.4.1.2')"""
    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 (or file path) to check. Can be a full path or just a filename. The function only examines the beginning of the string to determine if it matches the Wuxi coding pattern. Expected to be a string type, though no explicit type checking is performed.

Return Value

Returns a boolean value. True if the filename starts with the Wuxi coding pattern (one or more digits followed by at least one dot and more digits, e.g., '1.2', '2.13.4.1.2'). False if the pattern is not found at the start of the filename or if the input doesn't match the expected format.

Dependencies

  • re

Required Imports

import re

Usage Example

import re

def has_wuxi_coding(filename):
    """Check if filename starts with wuxi coding pattern (e.g., '2.13.4.1.2')"""
    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 (no dots)
print(has_wuxi_coding('1.2'))  # True
print(has_wuxi_coding('abc.123.456'))  # False (doesn't start with digit)

Best Practices

  • The function only checks if the filename STARTS with the Wuxi coding pattern; it does not validate the entire filename structure
  • The pattern requires at least one dot separator (e.g., '1.2' is valid, but '123' alone is not)
  • Consider sanitizing or validating the input to ensure it's a string before calling this function to avoid potential errors
  • The function works on the raw filename string, so if passing a full file path, the path components will be included in the check
  • For file path inputs, consider using os.path.basename() or Path().name to extract just the filename before checking
  • The regex pattern is case-insensitive to digits but will not match if there are leading spaces or other characters

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function has_wuxi_coding 97.7% similar

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

    From: /tf/active/vicechatdev/mailsearch/copy_signed_documents.py
  • function extract_document_code_v1 58.5% 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.6% 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 53.2% 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 52.5% 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