Default to SVG name for display for non-base DC#1956
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new helper function isCustomHierarchy to identify SVGs from non-base Data Commons instances and integrates it into getSpecializedEntity alongside an empty check on childName. The reviewer suggests renaming isCustomHierarchy to isNonBaseDCHierarchy to prevent confusion with existing custom SVGs that start with "dc/", and adding an empty string check to the helper for robustness.
| // isCustomHierarchy checks if the SVG is part of a non-base DC. | ||
| func isCustomHierarchy(svg string) bool { | ||
| return !strings.HasPrefix(svg, "dc/") | ||
| } |
There was a problem hiding this comment.
The name isCustomHierarchy is potentially misleading because "Custom" is already used in the codebase (e.g., CustomSVGPrefix = "dc/g/Custom_") to refer to local custom SVGs, which do start with dc/. Since this function specifically checks for SVGs from a non-base Data Commons instance (which do not start with dc/), renaming it to isNonBaseDCHierarchy or isExternalHierarchy would be much clearer and prevent future confusion. Additionally, adding a check for an empty string makes the helper more robust.
| // isCustomHierarchy checks if the SVG is part of a non-base DC. | |
| func isCustomHierarchy(svg string) bool { | |
| return !strings.HasPrefix(svg, "dc/") | |
| } | |
| // isNonBaseDCHierarchy checks if the SVG is part of a non-base DC. | |
| func isNonBaseDCHierarchy(svg string) bool { | |
| return svg != "" && !strings.HasPrefix(svg, "dc/") | |
| } |
References
- Ensure that function docstrings accurately reflect the function's signature and return values.
| func getSpecializedEntity(parent, child, childName string) string { | ||
| if !strings.Contains(child, "_") || isCuratedHierarchy(child) { // Child is likely curated. | ||
| if childName != "" && (!strings.Contains(child, "_") || isCuratedHierarchy(child) || isCustomHierarchy(child)) { // Child is likely curated. | ||
| return childName | ||
| } |
There was a problem hiding this comment.
Update the call to use the renamed isNonBaseDCHierarchy function for clarity.
| func getSpecializedEntity(parent, child, childName string) string { | |
| if !strings.Contains(child, "_") || isCuratedHierarchy(child) { // Child is likely curated. | |
| if childName != "" && (!strings.Contains(child, "_") || isCuratedHierarchy(child) || isCustomHierarchy(child)) { // Child is likely curated. | |
| return childName | |
| } | |
| func getSpecializedEntity(parent, child, childName string) string { | |
| if childName != "" && (!strings.Contains(child, "_") || isCuratedHierarchy(child) || isNonBaseDCHierarchy(child)) { // Child is likely curated. | |
| return childName | |
| } |
No description provided.