Code/AutoRig/Analyze/NameHints.cs

Utility that scores a collection of part/tag names for mechanical or organic keywords. It defines keyword lists and provides MechanicalScore and OrganicScore returning the fraction of names containing any keyword.

namespace AutoRig.Analyze;

/// <summary>Keyword evidence from part/tag names.</summary>
public static class NameHints
{
    static readonly string[] Mechanical =
    [
        "turret", "wheel", "barrel", "hull", "track", "bolt", "slide", "mag",
        "trigger", "door", "hinge", "rotor", "gear", "piston", "chassis",
        "hatch", "suspension", "axle", "engine", "cannon", "muzzle", "stock",
        "grip", "sight", "scope", "blade", "prop", "thruster", "landing",
    ];

    static readonly string[] Organic =
    [
        "head", "arm", "leg", "hand", "foot", "spine", "tail", "wing", "ear",
        "neck", "jaw", "body", "torso", "hip", "shoulder", "finger", "thigh",
        "chest", "pelvis", "knee", "elbow", "toe", "eye", "mouth", "belly",
    ];

    /// <summary>Fraction (0..1) of names containing a mechanical keyword.</summary>
    public static float MechanicalScore( IEnumerable<string> names ) => Score( names, Mechanical );

    /// <summary>Fraction (0..1) of names containing an organic keyword.</summary>
    public static float OrganicScore( IEnumerable<string> names ) => Score( names, Organic );

    static float Score( IEnumerable<string> names, string[] keywords )
    {
        var total = 0;
        var matched = 0;
        foreach ( var name in names )
        {
            total++;
            foreach ( var keyword in keywords )
            {
                if ( name.Contains( keyword, StringComparison.OrdinalIgnoreCase ) )
                {
                    matched++;
                    break;
                }
            }
        }
        return total == 0 ? 0f : (float)matched / total;
    }
}