NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

class MNDocRecordParser(BaseSORRecordParser):
"""MN DOC data parser"""

def __init__(self):
self.name = "MN_DOC_DATA_PARSER"
self.source_added_date = datetime.now()

def generate_id_case_number(self, comm_name, dob):
"""Generate idcasenumber = stripped name + dob"""
try:
name_clean = name_obj.clean_name(comm_name)
name_clean = re.sub(r"[^A-Za-z]", "", name_clean)
return f"{name_clean}{dob}"
except Exception as e:
logger.error("Error generating idcasenumber: %s", e, exc_info=True)
return ""

def clean_name(self, name:str):
"""Remove punctuation from the name by keeping only apostrophes.
- leading/trailing spaces
- spaces within the string
- hyphens
- commas
"""
if not name:
return ""
return re.sub(r"[,s-]+", "", name.strip())

def clean(self, val):
val = "" if val is None else str(val).strip()
val = val.strip(string.digits).strip()
return "" if val in ("", "0", "NONE", "NULL") else val

def is_yyyymmdd(self, date_str: str) -> bool:
"""
Verifies whether a date is a valid YYYYMMDD date.
"""
if not date_str:
return False

# Normalize input first
date_str = str(date_str).strip().strip('"')

if len(date_str) != 8 or not date_str.isdigit():
return False

try:
datetime.strptime(date_str, "%Y%m%d")
return True
except ValueError:
return False

def format_sentence_duration(self, max_year: str, max_month: str, max_day: str) -> str:
"""
Formats sentence duration as YYYMMDDD (8 digits).

Args:
max_year: Year value (0-999)
max_month: Month value (0-99)
max_day: Day value (0-999)

Returns:
8-digit string in YYYMMDDD format, or empty string if invalid/all zeros
"""
def to_int(val):
val = str(val).strip() if val is not None else ""
return int(val) if val.isdigit() else 0

y = to_int(max_year)
m = to_int(max_month)
d = to_int(max_day)

# If everything is zero, return empty
if y == 0 and m == 0 and d == 0:
return ""

# Validate ranges for 8-digit format YYYMMDDD
if y > 999 or m > 99 or d > 999:
return ""

# Format as YYYMMDDD (3+2+3 = 8 digits)
return f"{y:03d}{m:02d}{d:03d}"

def add_comment(self, label, value):
"""
Build a formatted comment string only when a valid value is present.
This function prevents empty or invalid fields from being added
to the final comments column. If the value is None, empty,
or represents a NaN value, the comment is skipped.

Args:
label (str): The comment label (e.g., 'OID', 'CURR LOC').
Pass an empty string for free-text comments.
value (Any): The source value to be appended.

Returns:
str | None: Formatted 'label: value' string if valid,
otherwise None.
"""
if value is None:
return None
value = str(value).strip()
if value == "" or value.lower() == "nan":
return None
return f"{label}: {value}" if label else value

def parser(self, line):
"""
Entry point for parsing a single MN DOC record
"""
try:
line = [x.strip() if isinstance(x, str) else x for x in line]

if len(line) < 28:
logger.error("Invalid MN DOC line length")
return False

cleara_format_parts = [""] * 69
parsed_rows = []

raw_comm = line[1]
raw_leg = line[2]
raw_alias = line[26]

comm_name = self.clean(raw_comm)
leg_name = self.clean(raw_leg)

# Ignore names
if leg_name in ("MC", "(RESENTENCED BY JUDGE)", "148802", "M"):
leg_name = ""

# extract first name, middle name, last name, suffix, and raw fullname
name_sets = []

if comm_name:
parts = name_obj.extract_name_parts(comm_name, "LFM")
if parts:
name_sets.append((*parts, "main", raw_comm))

if leg_name:
parts = name_obj.extract_name_parts(leg_name, "LFM")
if parts:
name_sets.append((*parts, "main", raw_leg))

alias_name = self.clean(raw_alias)
if alias_name:
parts = name_obj.extract_name_parts(alias_name, "LFM")
if parts:
name_sets.append((*parts, "alias", raw_alias))

# Deduplicate
name_sets = list(set(name_sets))

for first_nm, middle_nm, last_nm, suffix, driver, raw_name in name_sets:
# Skip company names
if name_obj.check_for_company_name(first_nm, middle_nm, last_nm):
return False

clean_middlename = self.clean_name(middle_nm)

if "-" in first_nm or "-" in last_nm:
variations = name_obj.generate_name_variations(
first_nm,
clean_middlename,
last_nm,
)
else:
variations = [(first_nm, clean_middlename, last_nm)]

for fn, mn, ln in variations:
row = self.process_mn_doc_data(
cleara_format_parts.copy(),
line,
ln,
fn,
mn,
suffix,
driver,
raw_name,
)
if row:
parsed_rows.append(row)

return parsed_rows if parsed_rows else False

except Exception as e:
logger.error("Error in MN DOC parser: %s", e, exc_info=True)
return False
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.