Class ComponentQuery
java.lang.Object
neqsim.mcp.runners.ComponentQuery
Queries the NeqSim component database for MCP and API integration.
Provides fast, stateless lookup of component names for validation, search, and fuzzy matching. All methods return JSON strings for direct use by MCP tool wrappers.
Component names are loaded once from the resource file neqsim_component_names.txt and
cached in memory. For richer property queries, the H2 database (COMP table) is used.
- Version:
- 1.0
- Author:
- Even Solbraa
-
Field Summary
FieldsModifier and TypeFieldDescriptionCached list of all component names (trimmed, original case).Cached list of all component names in lower case for matching.private static final org.apache.logging.log4j.LoggerLogger object for class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringclosestMatch(String name) Finds the closest matching component name for a possibly misspelled input using edit distance.private static voidLoads component names from the resource file if not already cached.private static StringCreates a standard error JSON response.Returns all known component names.static StringReturns detailed information for a specific component as JSON.static booleanChecks whether a component name exists in the database.(package private) static intlevenshteinDistance(String a, String b) Computes the Levenshtein edit distance between two strings.private static voidloadFromDatabase(List<String> names, List<String> namesLower) Loads component names from the H2 database as a fallback.private static doublesafeDouble(String value) Safely parses a string to double, returning 0.0 on failure.static StringSearches for components whose name contains the query string (case-insensitive).
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger loggerLogger object for class. -
cachedNames
-
cachedNamesLower
-
-
Constructor Details
-
ComponentQuery
private ComponentQuery()Private constructor to prevent instantiation.
-
-
Method Details
-
getAllNames
-
isValid
Checks whether a component name exists in the database.- Parameters:
name- the component name to check (case-insensitive)- Returns:
- true if the component is known
-
search
-
closestMatch
-
getInfo
Returns detailed information for a specific component as JSON.Queries the H2 database COMP table for properties like molar mass, critical temperature, critical pressure, and acentric factor.
- Parameters:
name- the exact component name- Returns:
- JSON string with component properties, or error if not found
-
ensureLoaded
private static void ensureLoaded()Loads component names from the resource file if not already cached. -
loadFromDatabase
-
levenshteinDistance
-
safeDouble
Safely parses a string to double, returning 0.0 on failure.- Parameters:
value- the string value- Returns:
- the parsed double, or 0.0
-
errorJson
-