This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsd_keywords.h
68 lines (58 loc) · 2.72 KB
/
sd_keywords.h
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
// Copyright (C) 2022 Valentin-Ioan VINTILA (313CA / 2021-2022).
// All rights reserved.
#ifndef SD_KEYWORDS_H
#define SD_KEYWORDS_H
// This library creates the means to store keywords and apply operations on
// strings present in emails.
// This is the maximum number of strings in a keywords collection.
#define MAX_COLLECTION_SIZE 1024
// This is the maximum size of a keyword that can be found in such a collection.
#define MAX_WORD_SIZE 64
// This is the default buffer size for any character array input.
#define BUFFER_SIZE 1024
// A keywords collection
typedef struct {
char associated_filename[BUFFER_SIZE]; // used in error logs
int count; // the ammount of elements in the collection
char keywords[MAX_COLLECTION_SIZE][MAX_WORD_SIZE]; // keywords themselves
int lps[MAX_COLLECTION_SIZE][MAX_WORD_SIZE]; // lps for said keywords
int kw_size[MAX_COLLECTION_SIZE]; // the length of each keyword
double values[MAX_COLLECTION_SIZE]; // the multiplier for each keyword
} kw_collection_t;
// General header file
#include "spam_detector.h"
// This function reads the content of a file and stores the given information in
// a kw_collection_t element.
// - - - - -
// char[] filename = The name of the file that has to be parsed.
// double multiplier = If > 0, this will be the value used for every
// "values" component instead of reading a new one.
// kw_collection_t *kw = This is where the resulting collection will be
// returned.
// - - - - -
// Return: error_t = The function will report CRITICAL_INPUT_KW in case the
// input file could not be opened.
extern error_t kw_collection_read(char *filename,
double multiplier,
kw_collection_t *kw);
// This function computes the score associated between a collection of keywords
// and an email.
// - - - - -
// kw_collection_t *kw = The collection of keywords.
// email_t *email = The email that should be scored.
// double multiplier = In addition to the values present in kw, the
// result is multiplied by multiplier.
// bool header = True if the email's header should be examined.
// bool use_log = True if the score should use the log function.
// double *result = This is where the resulting score will be
// returned.
// - - - - -
// Return: error_t = The function will report a warning in case the collection
// was empty.
extern error_t kw_collection_apply(kw_collection_t *kw,
email_t *email,
double multiplier,
bool header,
bool use_log,
double *result);
#endif // SD_KEYWORDS_H