This commit is contained in:
46
docs/snippets/c/utils/keyword_extraction_example.md
Normal file
46
docs/snippets/c/utils/keyword_extraction_example.md
Normal file
@@ -0,0 +1,46 @@
|
||||
```c title="C"
|
||||
#include "kreuzberg.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
const char *config_json =
|
||||
"{"
|
||||
"\"keywords\": {"
|
||||
"\"algorithm\": \"yake\","
|
||||
"\"max_keywords\": 10,"
|
||||
"\"min_score\": 0.3"
|
||||
"}"
|
||||
"}";
|
||||
|
||||
KREUZBERGExtractionConfig *config = kreuzberg_extraction_config_from_json(config_json);
|
||||
if (!config) {
|
||||
fprintf(stderr, "config parse failed (code %d): %s\n",
|
||||
kreuzberg_last_error_code(),
|
||||
kreuzberg_last_error_context());
|
||||
return 1;
|
||||
}
|
||||
|
||||
KREUZBERGExtractionResult *result =
|
||||
kreuzberg_extract_file_sync("research_paper.pdf", NULL, config);
|
||||
if (!result) {
|
||||
fprintf(stderr, "extraction failed (code %d): %s\n",
|
||||
kreuzberg_last_error_code(),
|
||||
kreuzberg_last_error_context());
|
||||
kreuzberg_extraction_config_free(config);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *keywords_json = kreuzberg_extraction_result_extracted_keywords(result);
|
||||
if (keywords_json) {
|
||||
printf("Keywords: %s\n", keywords_json);
|
||||
kreuzberg_free_string(keywords_json);
|
||||
} else {
|
||||
printf("Keywords: (none)\n");
|
||||
}
|
||||
|
||||
kreuzberg_extraction_result_free(result);
|
||||
kreuzberg_extraction_config_free(config);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user