FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
abacus-develop/source/source_io/input_help.h at develop · deepmodeling/abacus-develop · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
deepmodeling
/
abacus-develop
Public
forked from
abacusmodeling/abacus-develop
Notifications
You must be signed in to change notification settings
Fork
244
Star
286
Code
Issues
258
Pull requests
20
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
abacus-develop
/
source
/
source_io
/
input_help.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
163 lines (146 loc) · 5.68 KB
Breadcrumbs
abacus-develop
/
source
/
source_io
/
input_help.h
Copy path
File metadata and controls
163 lines (146 loc) · 5.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#
ifndef
INPUT_HELP_H
#
define
INPUT_HELP_H
#
include
<
iostream
>
#
include
<
map
>
#
include
<
mutex
>
#
include
<
string
>
#
include
<
vector
>
namespace
ModuleIO
{
/*
*
* @brief Metadata for a single INPUT parameter
*/
struct
ParameterMetadata
{
std::string name;
std::string type;
std::string description;
std::string default_value;
std::string category;
std::string unit;
//
Empty string if no unit
std::string availability;
//
Empty string if always available
std::string name_lowercase;
//
Pre-computed lowercase for fast fuzzy matching
};
/*
*
* @brief Help system for ABACUS INPUT parameters
*
* This class provides functionality to search for and display help information
* about INPUT parameters. The parameter data is loaded from auto-generated
* code that parses the documentation at build time.
*/
class
ParameterHelp
{
public:
/*
*
* @brief Initialize the help registry from generated data
*
* This function is called automatically on first use. It builds the
* parameter registry from the generated PARAMETER_DATA array.
*/
static
void
initialize
();
/*
*
* @brief Display detailed help for a specific parameter
*
* @param key The parameter name to look up (case-insensitive)
* @param os Output stream to write to (default: std::cout)
* @return true if parameter was found and help was displayed, false otherwise
*/
static
bool
show_parameter_help
(
const
std::string& key, std::ostream& os = std::cout);
/*
*
* @brief Search for parameters matching a query string
*
* Performs case-insensitive substring matching on parameter names.
*
* @param query The search query string
* @return Vector of matching parameter names (sorted alphabetically)
*/
static
std::vector<std::string>
search_parameters
(
const
std::string& query);
/*
*
* @brief Display general help message
*
* Shows usage information and lists commonly used parameters.
*
* @param os Output stream to write to (default: std::cout)
*/
static
void
show_general_help
(std::ostream& os = std::cout);
/*
*
* @brief Generate YAML dump of all parameter metadata
*
* Outputs a YAML document suitable for documentation generation.
* Each parameter includes name, category, type, description,
* default_value, unit, and availability fields.
*
* @param os Output stream to write YAML to (default: std::cout)
*/
static
void
generate_yaml
(std::ostream& os = std::cout);
/*
*
* @brief Get metadata for a specific parameter
*
* Returns a copy of the parameter metadata. Check if the returned
* metadata has a non-empty name to verify the parameter was found.
*
* @param key The parameter name to look up (case-insensitive)
* @return ParameterMetadata with empty name if not found, otherwise the parameter metadata
*
* Example:
* auto meta = ParameterHelp::get_metadata("ecutwfc");
* if (!meta.name.empty()) {
* // Parameter found, use meta.description, etc.
* }
*/
static
ParameterMetadata
get_metadata
(
const
std::string& key);
/*
*
* @brief Find similar parameter names for fuzzy matching
*
* Uses a multi-tier matching strategy to find relevant parameters:
* 1. Prefix matches (e.g., "relax" matches "relax_method") - highest priority
* 2. Substring matches (e.g., "cut" matches "ecutwfc") - medium priority
* 3. Levenshtein distance for typos - lowest priority
*
* This ensures semantic relevance: typing "relax" suggests "relax_method"
* instead of random 5-letter parameters like "nelec".
*
* @param query The parameter name to find similar matches for
* @param max_suggestions Maximum number of suggestions to return (default: 5)
* @param max_distance Maximum edit distance for fuzzy matches (default: 3)
* @return Vector of similar parameter names sorted by relevance
*/
static
std::vector<std::string>
find_similar_parameters
(
const
std::string& query,
int
max_suggestions =
5
,
int
max_distance =
3
);
private:
static
std::map<std::string, ParameterMetadata> registry_;
static
std::map<std::string, std::string> lowercase_to_actual_;
static
std::once_flag init_flag_;
/*
*
* @brief Build the registry from generated PARAMETER_DATA
*
* This is called once during initialization to populate the registry
* from the static constexpr data array. Thread-safe via std::call_once.
*/
static
void
build_registry
();
/*
*
* @brief Find parameter with case-insensitive matching
*
* Uses pre-computed lowercase mappings for O(log n) performance.
*
* @param key The parameter name to look up (any case)
* @return Iterator to the parameter in registry_, or registry_.end() if not found
*/
static
std::map<std::string, ParameterMetadata>::const_iterator
find_case_insensitive
(
const
std::string& key);
/*
*
* @brief Convert string to lowercase for case-insensitive comparison
*/
static
std::string
to_lowercase
(
const
std::string& str);
/*
*
* @brief Calculate Levenshtein distance between two strings
*
* Returns the minimum number of single-character edits (insertions,
* deletions, or substitutions) required to change one string into another.
*
* @param s1 First string
* @param s2 Second string
* @return Edit distance between the strings
*/
static
int
levenshtein_distance
(
const
std::string& s1,
const
std::string& s2);
};
}
//
namespace ModuleIO
#
endif
//
INPUT_HELP_H
Back
|
FazBrowse Home
|
New Git URL