You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于特定条件配置Part attachment包含与排除过滤器的技术问询

Hey Kapil, let’s work through setting up those two Part Attachment filters for your car configuration data. I’ll use mock data and practical examples to make this concrete.

Part Attachment Filter Setup (Include & Exclude)

First, let’s start with a sample dataset that mirrors your use case—configurations with their associated parts:

# Mock Car Configuration Data
car_configs = [
    {"configuration_id": "CONF-001", "part_attachment": ["steering wheel", "steering column", "dashboard"]},
    {"configuration_id": "CONF-002", "part_attachment": ["front lights", "rear lights", "fog lights"]},
    {"configuration_id": "CONF-003", "part_attachment": ["steering rack", "tire assembly", "brake system"]},
    {"configuration_id": "CONF-004", "part_attachment": ["seat assembly", "door panels", "roof liner"]}
]

1. Part Attachment Include Filter (for 'steering')

This filter returns all configurations where any part in the Part Attachment list contains the keyword (in this case, 'steering'). Here’s how to implement it in Python:

def filter_include_part(configs, target_keyword):
    matched_configs = []
    for config in configs:
        # Check if any part includes the keyword (case-insensitive for flexibility)
        if any(target_keyword.lower() in part.lower() for part in config["part_attachment"]):
            matched_configs.append(config)
    return matched_configs

# Run the filter with 'steering'
steering_included = filter_include_part(car_configs, "steering")
print(steering_included)

Output:

[
{"configuration_id": "CONF-001", "part_attachment": ["steering wheel", "steering column", "dashboard"]},
{"configuration_id": "CONF-003", "part_attachment": ["steering rack", "tire assembly", "brake system"]}
]

2. Part Attachment Exclude Filter

This filter does the reverse: it keeps configurations where none of the parts in the Part Attachment list contain the keyword. Here’s the implementation:

def filter_exclude_part(configs, target_keyword):
    unmatched_configs = []
    for config in configs:
        # Check if no parts include the keyword
        if not any(target_keyword.lower() in part.lower() for part in config["part_attachment"]):
            unmatched_configs.append(config)
    return unmatched_configs

# Example: Exclude all configurations with 'steering'
steering_excluded = filter_exclude_part(car_configs, "steering")
print(steering_excluded)

Output:

[
{"configuration_id": "CONF-002", "part_attachment": ["front lights", "rear lights", "fog lights"]},
{"configuration_id": "CONF-004", "part_attachment": ["seat assembly", "door panels", "roof liner"]}
]

Bonus: SQL Implementation (If Using a Database)

If your data is stored in a SQL table (e.g., car_configurations), here’s how to write the filters:

Include 'steering' (for comma-separated part lists):

SELECT * 
FROM car_configurations 
WHERE part_attachment LIKE '%steering%';

Exclude 'steering' (for comma-separated part lists):

SELECT * 
FROM car_configurations 
WHERE part_attachment NOT LIKE '%steering%';

For JSON array columns (PostgreSQL example):

-- Include
SELECT * 
FROM car_configurations 
WHERE EXISTS (
    SELECT 1 FROM jsonb_array_elements_text(part_attachment) AS part 
    WHERE part LIKE '%steering%'
);

-- Exclude
SELECT * 
FROM car_configurations 
WHERE NOT EXISTS (
    SELECT 1 FROM jsonb_array_elements_text(part_attachment) AS part 
    WHERE part LIKE '%steering%'
);

Let me know if you need tweaks for your specific tech stack or data format!

内容的提问来源于stack exchange,提问作者Kapil Lehar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:12:15