@@ -166,115 +166,240 @@ float fossil_io_soap_politeness_score(const char *text);
166
166
}
167
167
168
168
#include < string>
169
+ #include < memory>
169
170
170
171
/* *
171
172
* C++ wrapper for the SOAP API.
172
173
*/
173
174
namespace fossil {
174
-
175
- /* *
176
- * Namespace for I/O operations.
177
- */
178
175
namespace io {
176
+
179
177
/* *
180
- * SOAP API for sanitizing strings.
178
+ * @brief SOAP API for sanitizing and analyzing user text input.
179
+ *
180
+ * Provides C++ wrappers for detecting, transforming, or correcting slang, tone, sentiment,
181
+ * clickbait, and other language features with a focus on clarity and safety.
181
182
*/
182
183
class Soap {
183
184
public:
185
+
184
186
/* *
185
- * Sanitize input text by removing or replacing " rot-brain" and meme-based language .
186
- *
187
- * @param text The input text to sanitize .
188
- * @return A dynamically allocated sanitized string (must be freed by the caller) .
187
+ * @brief Sanitize input by replacing meme/ rot-brain terms with standard alternatives .
188
+ *
189
+ * @param text The input string .
190
+ * @return A cleaned-up version of the text .
189
191
*/
190
192
static std::string sanitize (const std::string &text) {
191
- return fossil_io_soap_sanitize (text.c_str ());
193
+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_sanitize (text.c_str ()), free);
194
+ return ptr ? std::string (ptr.get ()) : std::string{};
192
195
}
193
196
194
197
/* *
195
- * Suggest proper alternatives for rot-brain words or grammar fixes .
198
+ * @brief Sanitize input text (C-style) .
196
199
*
197
- * @param text The input text.
198
- * @param format_type Custom format for output (e.g., "*" or "#").
199
- * @return A dynamically allocated string with suggestions (must be freed by the caller).
200
+ * @param text The input string.
201
+ * @return A heap-allocated cleaned-up version (must be freed manually).
202
+ */
203
+ static char * sanitize (const char * text) {
204
+ return fossil_io_soap_sanitize (text);
205
+ }
206
+
207
+ /* *
208
+ * @brief Suggest alternative expressions for slang or incorrect grammar.
209
+ *
210
+ * @param text The input string.
211
+ * @return A string with suggested improvements.
200
212
*/
201
213
static std::string suggest (const std::string &text) {
202
- return fossil_io_soap_suggest (text.c_str ());
214
+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_suggest (text.c_str ()), free);
215
+ return ptr ? std::string (ptr.get ()) : std::string{};
203
216
}
204
217
205
218
/* *
206
- * Add a custom word or phrase to the filter.
207
- *
208
- * @param phrase The phrase to add.
219
+ * @brief Suggest improvements (C-style).
220
+ *
221
+ * @param text The input string.
222
+ * @return A heap-allocated suggestion (must be freed manually).
223
+ */
224
+ static char * suggest (const char * text) {
225
+ return fossil_io_soap_suggest (text);
226
+ }
227
+
228
+ /* *
229
+ * @brief Add a custom slang or flagged phrase to the filter.
230
+ *
231
+ * @param phrase The custom phrase.
209
232
* @return 0 on success, nonzero on failure.
210
233
*/
211
234
static int add_custom_filter (const std::string &phrase) {
212
235
return fossil_io_soap_add_custom_filter (phrase.c_str ());
213
236
}
214
237
215
238
/* *
216
- * Clear all custom filters.
239
+ * @brief Add a custom slang or flagged phrase to the filter (C-style).
240
+ *
241
+ * @param phrase The custom phrase.
242
+ * @return 0 on success, nonzero on failure.
243
+ */
244
+ static int add_custom_filter (const char * phrase) {
245
+ return fossil_io_soap_add_custom_filter (phrase);
246
+ }
247
+
248
+ /* *
249
+ * @brief Clear all user-added custom filters.
217
250
*/
218
251
static void clear_custom_filters () {
219
252
fossil_io_soap_clear_custom_filters ();
220
253
}
221
254
222
255
/* *
223
- * Detect the tone of a sentence .
224
- *
225
- * @param text The input text .
226
- * @return A string representing the detected tone ("formal", "casual", "sarcastic", etc.) .
256
+ * @brief Detect tone of the input (e.g., "sarcastic", "formal") .
257
+ *
258
+ * @param text The input string .
259
+ * @return A tone descriptor string .
227
260
*/
228
261
static std::string detect_tone (const std::string &text) {
229
- return fossil_io_soap_detect_tone (text.c_str ());
262
+ return std::string ( fossil_io_soap_detect_tone (text.c_str () ));
230
263
}
231
264
232
265
/* *
233
- * Sanitize input text by removing or replacing "rot-brain" and meme-based language .
234
- *
235
- * @param text The input text to sanitize .
236
- * @return A dynamically allocated sanitized string (must be freed by the caller) .
266
+ * @brief Detect tone of the input (C-style) .
267
+ *
268
+ * @param text The input string .
269
+ * @return A tone descriptor string.
237
270
*/
238
- static char * sanitize (const char * text) {
239
- return fossil_io_soap_sanitize (text);
271
+ static const char * detect_tone (const char * text) {
272
+ return fossil_io_soap_detect_tone (text);
240
273
}
241
274
242
275
/* *
243
- * Suggest proper alternatives for rot-brain words or grammar fixes.
244
- *
245
- * @param text The input text.
246
- * @param format_type Custom format for output (e.g., "*" or "#").
247
- * @return A dynamically allocated string with suggestions (must be freed by the caller).
276
+ * @brief Analyze sentiment in the input ("positive", "neutral", "negative").
277
+ *
278
+ * @param text The input string.
279
+ * @return Sentiment label.
248
280
*/
249
- static char * suggest (const char * text) {
250
- return fossil_io_soap_suggest ( text);
281
+ static std::string detect_sentiment (const std::string & text) {
282
+ return std::string ( fossil_io_soap_detect_sentiment ( text. c_str ()) );
251
283
}
252
284
253
285
/* *
254
- * Add a custom word or phrase to the filter .
255
- *
256
- * @param phrase The phrase to add .
257
- * @return 0 on success, nonzero on failure .
286
+ * @brief Analyze sentiment (C-style) .
287
+ *
288
+ * @param text The input string .
289
+ * @return Sentiment label string .
258
290
*/
259
- static int add_custom_filter (const char * phrase ) {
260
- return fossil_io_soap_add_custom_filter (phrase );
291
+ static const char * detect_sentiment (const char * text ) {
292
+ return fossil_io_soap_detect_sentiment (text );
261
293
}
262
294
263
295
/* *
264
- * Detect the tone of a sentence .
265
- *
266
- * @param text The input text .
267
- * @return A string representing the detected tone ("formal", "casual", "sarcastic", etc.) .
296
+ * @brief Check for harmful or inappropriate content .
297
+ *
298
+ * @param text The input string .
299
+ * @return true if flagged, false otherwise .
268
300
*/
269
- static const char * detect_tone (const char * text) {
270
- return fossil_io_soap_detect_tone (text) ;
301
+ static bool is_harmful (const std::string & text) {
302
+ return fossil_io_soap_detect_harmful_content (text. c_str ()) != 0 ;
271
303
}
272
304
273
- };
305
+ /* *
306
+ * @brief Check if the input contains exaggerated or hyperbolic language.
307
+ *
308
+ * @param text The input string.
309
+ * @return true if exaggerated, false otherwise.
310
+ */
311
+ static bool is_exaggerated (const std::string &text) {
312
+ return fossil_io_soap_detect_exaggeration (text.c_str ()) != 0 ;
313
+ }
274
314
275
- }
315
+ /* *
316
+ * @brief Check if the input uses clickbait language.
317
+ *
318
+ * @param text The input string.
319
+ * @return true if clickbait detected, false otherwise.
320
+ */
321
+ static bool is_clickbait (const std::string &text) {
322
+ return fossil_io_soap_detect_clickbait (text.c_str ()) != 0 ;
323
+ }
276
324
277
- }
325
+ /* *
326
+ * @brief Normalize slang and internet abbreviations.
327
+ *
328
+ * @param text The input string.
329
+ * @return A cleaned version of the input text.
330
+ */
331
+ static std::string normalize_slang (const std::string &text) {
332
+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_normalize_slang (text.c_str ()), free);
333
+ return ptr ? std::string (ptr.get ()) : std::string{};
334
+ }
335
+
336
+ /* *
337
+ * @brief Fix common grammar errors in input text.
338
+ *
339
+ * @param text The input string.
340
+ * @return A corrected version of the input.
341
+ */
342
+ static std::string correct_grammar (const std::string &text) {
343
+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_correct_grammar (text.c_str ()), free);
344
+ return ptr ? std::string (ptr.get ()) : std::string{};
345
+ }
346
+
347
+ /* *
348
+ * @brief Replace offensive language with neutral alternatives.
349
+ *
350
+ * @param text The input string.
351
+ * @return A sanitized version with offensive terms filtered out.
352
+ */
353
+ static std::string filter_offensive (const std::string &text) {
354
+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_filter_offensive (text.c_str ()), free);
355
+ return ptr ? std::string (ptr.get ()) : std::string{};
356
+ }
357
+
358
+ /* *
359
+ * @brief Attempt to identify logical fallacies in the input.
360
+ *
361
+ * @param text The input string.
362
+ * @return Description of detected fallacy or empty string.
363
+ */
364
+ static std::string detect_fallacy (const std::string &text) {
365
+ const char * result = fossil_io_soap_detect_fallacy (text.c_str ());
366
+ return result ? std::string (result) : std::string{};
367
+ }
368
+
369
+ /* *
370
+ * @brief Generate a brief summary of the key idea in the input.
371
+ *
372
+ * @param text The input string.
373
+ * @return Summary string.
374
+ */
375
+ static std::string summarize (const std::string &text) {
376
+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_summarize (text.c_str ()), free);
377
+ return ptr ? std::string (ptr.get ()) : std::string{};
378
+ }
379
+
380
+ /* *
381
+ * @brief Return a readability score (e.g., Flesch-Kincaid).
382
+ *
383
+ * @param text The input string.
384
+ * @return Readability score as a float.
385
+ */
386
+ static float readability_score (const std::string &text) {
387
+ return fossil_io_soap_evaluate_readability (text.c_str ());
388
+ }
389
+
390
+ /* *
391
+ * @brief Compute a politeness score (0.0 = rude, 1.0 = very polite).
392
+ *
393
+ * @param text The input string.
394
+ * @return Politeness score.
395
+ */
396
+ static float politeness_score (const std::string &text) {
397
+ return fossil_io_soap_politeness_score (text.c_str ());
398
+ }
399
+ };
400
+
401
+ } // namespace io
402
+ } // namespace fossil
278
403
279
404
#endif
280
405
0 commit comments