選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

lang_detection_fasttext.h 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*-
  2. * Copyright 2023 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef RSPAMD_LANG_DETECTION_FASTTEXT_H
  17. #define RSPAMD_LANG_DETECTION_FASTTEXT_H
  18. #include "config.h"
  19. G_BEGIN_DECLS
  20. struct rspamd_config;
  21. struct rspamd_task; /* for logging */
  22. /**
  23. * Initialize fasttext language detector
  24. * @param cfg
  25. * @return opaque pointer
  26. */
  27. void *rspamd_lang_detection_fasttext_init(struct rspamd_config *cfg);
  28. /**
  29. * Check if fasttext language detector is enabled
  30. * @param ud
  31. * @return
  32. */
  33. bool rspamd_lang_detection_fasttext_is_enabled(void *ud);
  34. /**
  35. * Show info about fasttext language detector
  36. * @param ud
  37. * @return
  38. */
  39. char *rspamd_lang_detection_fasttext_show_info(void *ud);
  40. typedef void *rspamd_fasttext_predict_result_t;
  41. /**
  42. * Detect language using fasttext
  43. * @param ud opaque pointer
  44. * @param in input text
  45. * @param len length of input text
  46. * @param k number of results to return
  47. * @return TRUE if language is detected
  48. */
  49. rspamd_fasttext_predict_result_t rspamd_lang_detection_fasttext_detect(void *ud,
  50. struct rspamd_task *task, GArray *utf_words, int k);
  51. /**
  52. * Get number of languages detected
  53. * @param ud
  54. * @return
  55. */
  56. unsigned int rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t ud);
  57. /**
  58. * Get language from fasttext result
  59. * @param res
  60. * @return
  61. */
  62. const char *rspamd_lang_detection_fasttext_get_lang(rspamd_fasttext_predict_result_t res, unsigned int idx);
  63. /**
  64. * Get probability from fasttext result
  65. * @param res
  66. * @return
  67. */
  68. float rspamd_lang_detection_fasttext_get_prob(rspamd_fasttext_predict_result_t res, unsigned int idx);
  69. /**
  70. * Destroy fasttext result
  71. * @param res
  72. */
  73. void rspamd_fasttext_predict_result_destroy(rspamd_fasttext_predict_result_t res);
  74. /**
  75. * Destroy fasttext language detector
  76. */
  77. void rspamd_lang_detection_fasttext_destroy(void *ud);
  78. G_END_DECLS
  79. #endif /* RSPAMD_LANG_DETECTION_FASTTEXT_H */