MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / parse_string_list

Function parse_string_list

experiments/baselines/knowledge_entity/runner.py:167–192  ·  view source on GitHub ↗
(raw_value: Any)

Source from the content-addressed store, hash-verified

165
166
167def parse_string_list(raw_value: Any) -> List[str]:
168 if raw_value in (None, "", []):
169 return []
170 if isinstance(raw_value, list):
171 values: List[str] = []
172 for item in raw_value:
173 if isinstance(item, dict):
174 values.extend(parse_string_list(item))
175 else:
176 values.append(str(item))
177 return [item.strip() for item in values if item.strip()]
178 if isinstance(raw_value, dict):
179 values: List[str] = []
180 for key, value in raw_value.items():
181 values.append(str(key))
182 values.extend(parse_string_list(value))
183 return [item.strip() for item in values if item.strip()]
184 if isinstance(raw_value, str):
185 try:
186 parsed = json.loads(raw_value)
187 except json.JSONDecodeError:
188 parsed = None
189 if isinstance(parsed, (list, dict)):
190 return parse_string_list(parsed)
191 return [item.strip() for item in re.split(r"[,;|\n]+", raw_value) if item.strip()]
192 return [str(raw_value).strip()] if str(raw_value).strip() else []
193
194
195def normalize_phrase_text(value: Any) -> str:

Callers 4

metadata_entitiesFunction · 0.70
_direction_termsFunction · 0.70
build_initial_profileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected