You are developing a data ingestion component for a large-scale analytics platform. The platform receives raw data in a simplified CSV format, where each line represents a record with specific attributes. Before storage or analysis, all incoming data must be strictly validated to maintain data quality and comply with business requirements.
The system provides three inputs:
data: A list of strings, with each string representing a row in a CSV table containingnrows and 6 columns per row. Each row follows the format"col1,col2,col3,col4,col5,col6", and the first row is always the header.forbiddenWords: A list of strings containing words that are prohibited in specific fields.ignoreWords: A list of strings consisting of common words (stop words) that should be ignored only during cross-column content comparison.
For each data row (excluding the header), determine whether it is "VALID" or "INVALID" by applying the following four rules in order:
-
RULE_1: Schema & Completeness.
Every column value must be non-empty after trimming any leading or trailing whitespace. -
RULE_2: Column 5 Length Check.
The 5th column (col5), once trimmed, must have a length between 5 and 31 characters (inclusive). -
RULE_3: Forbidden Words in Column 2.
The 2nd column (col2) must not contain any word fromforbiddenWords.- Matching is case-insensitive.
- Words are defined as tokens separated by whitespace.
-
RULE_4: Cross-Column Word Match.
A valid word is a lowercase word not found inignoreWords. The row meets this rule only if at least 50% of valid words incol2are also present as valid words in eithercol4orcol5.- If
col2has zero valid words, the row is invalid. - Repeated valid words in
col2are only counted once for percentage calculation.
- If
If a row satisfies all rules, label it as "VALID". If it fails any rule, label it as "INVALID: RULE_X", where X is the number of the first failed rule. Return a list of validation results of length n - 1 (excluding the header), with each result corresponding to a data row.
Constraints:
≤data.length≤data[i]consists of ASCII characters.forbiddenWordsandignoreWordscan contain up toelements.- Fields are separated strictly by a single comma (
','). - There is no support for quotes or escape characters.
- Commas will never appear as part of the content within a field.
Example 1:
Input: data = ["col1,col2,col3,col4,col5,col6", "id1,Land Water,c,d,land water llc,f", "id2,Good Company,c,d,land water,f", "id3,Apple banana,c,d,banana orange,f", "id4, ,c,d,hello world,f", "id5,LLC Inc,c,d,something real,f", "id6,blue sky ocean,c,d,green yellow pink,f", "id7,Best Group,c,d,hello group,f", "id8,land water,c,d,land,f"], forbiddenWords = ["company", "firm", "co.", "corporation", "group"], ignoreWords = ["llc", "inc"] Output: ["VALID", "INVALID:RULE_3", "VALID", "INVALID:RULE_1", "INVALID:RULE_4", "INVALID:RULE_4", "INVALID:RULE_3", "INVALID:RULE_2"] Explanation: All violations are listed below:
- Row 2:
col2violates "RULE_3" as it containsforbiddenWords"Company". It violates "RULE_3".- Row 4:
col2violates "RULE_1" as it contains only whitespace.- Row 5:
col2violates "RULE_4" as both words are inignoreWords.- Row 6:
col2violates "RULE_4" as words ("blue", "sky", "ocean") do not appear incol4orcol5.- Row 8:
col5violates "RULE_2"as its length is 4.
Example 2:
Input: data = ["col1,col2,col3,col4,col5,col6", "id1,hello world,c,d,hello there,f"], forbiddenWords = ["bad", "wrong"], ignoreWords = [] Output: ["VALID"]
Example 3:
Input: data = ["col1,col2,col3,col4,col5,col6", "id1,good name,c,d,test,f"], forbiddenWords = [], ignoreWords = [] Output: ["INVALID:RULE_2"]
