Process description according to the requirements: 1. If description is empty, use title 2. If description is a list, select the longest one 3. If the longest in list is also empty, use title Args: description: The description field from
(self, description, title)
| 482 | self.get_inputs() |
| 483 | |
| 484 | def _process_description(self, description, title): |
| 485 | """ |
| 486 | Process description according to the requirements: |
| 487 | 1. If description is empty, use title |
| 488 | 2. If description is a list, select the longest one |
| 489 | 3. If the longest in list is also empty, use title |
| 490 | |
| 491 | Args: |
| 492 | description: The description field from item_feat |
| 493 | title: The title field from item_feat |
| 494 | |
| 495 | Returns: |
| 496 | str: Processed description |
| 497 | """ |
| 498 | # Check if description is empty or None |
| 499 | if not description or description == '': |
| 500 | return title |
| 501 | |
| 502 | # Check if description is a list (either actual list or string representation) |
| 503 | if isinstance(description, list): |
| 504 | # It's already a list |
| 505 | desc_list = description |
| 506 | elif isinstance(description, str) and description.startswith('[') and description.endswith(']'): |
| 507 | try: |
| 508 | # Try to parse string representation of list |
| 509 | desc_list = eval(description) |
| 510 | except: |
| 511 | # If parsing fails, treat as regular string |
| 512 | return description if description.strip() else title |
| 513 | else: |
| 514 | # Regular string description |
| 515 | return description if description.strip() else title |
| 516 | |
| 517 | # If we have a list, find the longest non-empty item |
| 518 | if desc_list: |
| 519 | # Filter out empty strings and find the longest |
| 520 | non_empty_descriptions = [desc for desc in desc_list if desc and desc.strip()] |
| 521 | if non_empty_descriptions: |
| 522 | # Return the longest description |
| 523 | longest_desc = max(non_empty_descriptions, key=len) |
| 524 | return longest_desc |
| 525 | else: |
| 526 | # All descriptions in list are empty, use title |
| 527 | return title |
| 528 | else: |
| 529 | # Empty list, use title |
| 530 | return title |
| 531 | |
| 532 | def __len__(self): |
| 533 | return len(self.data) |