Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
frictionless_data_util.h
Go to the documentation of this file.
1 /*
2  * frictionless_data_util.h
3  *
4  * Created on: 22 Mar 2021
5  * Author: billy
6  */
7 
8 #ifndef SERVICES_FIELD_TRIALS_INCLUDE_FRICTIONLESS_DATA_UTIL_H_
9 #define SERVICES_FIELD_TRIALS_INCLUDE_FRICTIONLESS_DATA_UTIL_H_
10 
12 
13 #include "jansson.h"
14 #include "bson/bson.h"
15 
16 
17 #ifndef DOXYGEN_SHOULD_SKIP_THIS
18 
19 
20 #ifdef ALLOCATE_FD_UTIL_TAGS
21  #define FD_UTIL_PREFIX GRASSROOTS_FRICTIONLESS_DATA_API
22  #define FD_UTIL_VAL(x) = x
23 #else
24  #define FD_UTIL_PREFIX extern GRASSROOTS_FRICTIONLESS_DATA_API
25  #define FD_UTIL_VAL(x)
26 #endif
27 
28 #endif /* #ifndef DOXYGEN_SHOULD_SKIP_THIS */
29 
30 
31 
32 
33 FD_UTIL_PREFIX const char * const FD_PROFILE_S FD_UTIL_VAL ("profile");
34 FD_UTIL_PREFIX const char * const FD_PROFILE_DATA_PACKAGE_S FD_UTIL_VAL ("data-package");
35 FD_UTIL_PREFIX const char * const FD_PROFILE_TABULAR_PACKAGE_S FD_UTIL_VAL ("tabular-data-package");
36 FD_UTIL_PREFIX const char * const FD_PROFILE_TABULAR_RESOURCE_S FD_UTIL_VAL ("tabular-data-resource");
37 FD_UTIL_PREFIX const char * const FD_PROFILE_PROPERTY_ORDER_S FD_UTIL_VAL ("propertyOrder");
38 FD_UTIL_PREFIX const char * const FD_NAME_S FD_UTIL_VAL ("name");
39 FD_UTIL_PREFIX const char * const FD_TITLE_S FD_UTIL_VAL ("title");
40 FD_UTIL_PREFIX const char * const FD_ID_S FD_UTIL_VAL ("id");
41 FD_UTIL_PREFIX const char * const FD_LICENSES_S FD_UTIL_VAL ("licenses");
42 FD_UTIL_PREFIX const char * const FD_DESCRIPTION_S FD_UTIL_VAL ("description");
43 FD_UTIL_PREFIX const char * const FD_URL_S FD_UTIL_VAL ("homepage");
44 FD_UTIL_PREFIX const char * const FD_RESOURCES_S FD_UTIL_VAL ("resources");
45 
46 
47 FD_UTIL_PREFIX const char * const FD_SCHEMA_S FD_UTIL_VAL ("schema");
48 
49 FD_UTIL_PREFIX const char * const FD_TABLE_FIELDS_S FD_UTIL_VAL ("fields");
50 
51 FD_UTIL_PREFIX const char * const FD_DATA_S FD_UTIL_VAL ("data");
52 
53 
54 FD_UTIL_PREFIX const char * const FD_ITEMS_S FD_UTIL_VAL ("items");
55 FD_UTIL_PREFIX const char * const FD_REF_S FD_UTIL_VAL ("$ref");
56 
57 
58 /*
59  * Table fields
60  */
61 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_NAME FD_UTIL_VAL ("name");
62 
63 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_TITLE FD_UTIL_VAL ("title");
64 
65 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_TYPE FD_UTIL_VAL ("type");
66 
67 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_FORMAT FD_UTIL_VAL ("format");
68 
69 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_DESCRIPTION FD_UTIL_VAL ("description");
70 
71 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINTS FD_UTIL_VAL ("constraints");
72 
73 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_RDF_TYPE FD_UTIL_VAL ("rdfType");
74 
75 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_NULL_VALUE FD_UTIL_VAL ("missingValues");
76 
77 
78 /*
79  * Constraints
80  */
81 
82 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINT_REQUIRED FD_UTIL_VAL ("required");
83 
84 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINT_UNIQUE FD_UTIL_VAL ("unique");
85 
86 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINT_MIN_LENGTH FD_UTIL_VAL ("minLength");
87 
88 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINT_MAX_LENGTH FD_UTIL_VAL ("maxLength");
89 
90 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINT_MIN FD_UTIL_VAL ("minimum");
91 
92 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINT_MAX FD_UTIL_VAL ("maximum");
93 
94 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINT_PATTERN FD_UTIL_VAL ("pattern");
95 
96 FD_UTIL_PREFIX const char *FD_TABLE_FIELD_CONSTRAINT_ENUM FD_UTIL_VAL ("enum");
97 
98 /*
99  * CSV Dialect
100  */
101 
102 FD_UTIL_PREFIX const char *FD_CSV_DIALECT FD_UTIL_VAL ("dialect");
103 
104 /*
105  * specifies the character sequence which should separate fields (aka columns).
106  * Default = ,. Example \t.
107  */
108 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_DELIMITER FD_UTIL_VAL ("delimiter");
109 
110 /*
111  * specifies the character sequence which should terminate rows. Default = \r\n
112  */
113 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_LINE_TERMINATOR FD_UTIL_VAL ("lineTerminator");
114 
115 /*
116  * specifies a one-character string to use as the quoting character. Default = "
117  */
118 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_QUOTE_CHAR FD_UTIL_VAL ("quoteChar");
119 
120 /*
121  * controls the handling of quotes inside fields. If true, two consecutive
122  * quotes should be interpreted as one. Default = true
123  */
124 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_DOUBLE_QUOTE FD_UTIL_VAL ("doubleQuote");
125 
126 /*
127  * specifies a one-character string to use for escaping (for example, \),
128  * mutually exclusive with quoteChar. Not set by default
129  */
130 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_ESCAPE_CHAR FD_UTIL_VAL ("escapeChar");
131 
132 /*
133  * specifies the null sequence (for example \N). Not set by default
134  */
135 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_NULL_VALUE FD_UTIL_VAL ("nullSequence");
136 
137 /*
138  * specifies how to interpret whitespace which immediately follows a delimiter;
139  * if false, it means that whitespace immediately after a delimiter should be treated
140  * as part of the following field. Default = true
141  */
142 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_SKIP_INITIAL_SPACE FD_UTIL_VAL ("skipInitialSpace");
143 
144 /*
145  * indicates whether the file includes a header row. If true the first row in the
146  * file is a header row, not data. Default = true
147  */
148 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_HEADER_ROW FD_UTIL_VAL ("header");
149 
150 /*
151  * indicates a one-character string to ignore any line whose row begins with this character
152  */
153 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_COMMENT_CHAR FD_UTIL_VAL ("commentChar");
154 
155 /*
156  * indicates that case in the header is meaningful. For example, columns CAT and Cat
157  * should not be equated. Default = false
158  */
159 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_CASE_SENSITIVE_HEADER FD_UTIL_VAL ("caseSensitiveHeader");
160 
161 /*
162  * a number, in n.n format, e.g., 1.2. If not present, consumers should assume latest
163  * schema version.
164  */
165 FD_UTIL_PREFIX const char *FD_CSV_DIALECT_VERSION FD_UTIL_VAL ("csvddfVersion");
166 
167 
168 /*
169  * Types
170  */
171 
173 FD_UTIL_PREFIX const char *FD_TYPE_STRING FD_UTIL_VAL ("string");
174 
176 FD_UTIL_PREFIX const char *FD_TYPE_STRING_FORMAT_DEFAULT FD_UTIL_VAL ("default");
177 
179 FD_UTIL_PREFIX const char *FD_TYPE_STRING_FORMAT_EMAIL FD_UTIL_VAL ("email");
180 
182 FD_UTIL_PREFIX const char *FD_TYPE_STRING_FORMAT_URI FD_UTIL_VAL ("uri");
183 
185 FD_UTIL_PREFIX const char *FD_TYPE_STRING_FORMAT_BINARY FD_UTIL_VAL ("binary");
186 
188 FD_UTIL_PREFIX const char *FD_TYPE_STRING_FORMAT_UUID FD_UTIL_VAL ("uuid");
189 
190 
191 
193 FD_UTIL_PREFIX const char *FD_TYPE_NUMBER FD_UTIL_VAL ("number");
194 
195 
196 
202 FD_UTIL_PREFIX const char *FD_TYPE_INTEGER FD_UTIL_VAL ("integer");
203 
204 
206 FD_UTIL_PREFIX const char *FD_TYPE_BOOLEAN FD_UTIL_VAL ("boolean");
207 
208 
212 FD_UTIL_PREFIX const char *FD_TYPE_DATE FD_UTIL_VAL ("date");
213 
214 
218 FD_UTIL_PREFIX const char *FD_TYPE_TIME FD_UTIL_VAL ("time");
219 
220 
224 FD_UTIL_PREFIX const char *FD_TYPE_DATETIME FD_UTIL_VAL ("datetime");
225 
226 
230 FD_UTIL_PREFIX const char *FD_TYPE_GEOJSON FD_UTIL_VAL ("geojson");
231 
232 
233 
235 FD_UTIL_PREFIX const char *FD_TYPE_JSON_OBJECT FD_UTIL_VAL ("object");
236 
237 
239 FD_UTIL_PREFIX const char *FD_TYPE_JSON_ARRAY FD_UTIL_VAL ("array");
240 
241 
242 #ifdef __cplusplus
243 extern "C"
244 {
245 #endif
246 
247 
248 GRASSROOTS_FRICTIONLESS_DATA_API json_t *AddTableField (json_t *fields_p, const char *name_s, const char *title_s, const char *type_s, const char *format_s, const char *description_s, const char *rdf_type_s);
249 
250 
251 GRASSROOTS_FRICTIONLESS_DATA_API json_t *AddIntegerField (json_t *fields_p, const char *name_s, const char *title_s, const char *format_s, const char *description_s, const char *rdf_type_s, const int *min_value_p);
252 
253 
254 GRASSROOTS_FRICTIONLESS_DATA_API json_t *AddNumberField (json_t *fields_p, const char *name_s, const char *title_s, const char *format_s, const char *description_s, const char *rdf_type_s, const double *min_value_p);
255 
256 
257 GRASSROOTS_FRICTIONLESS_DATA_API bool SetFDTableReal (json_t *row_p, const char * const key_s, const double64 *value_p, const char * const null_sequence_s);
258 
259 
260 GRASSROOTS_FRICTIONLESS_DATA_API bool SetFDTableString (json_t *row_p, const char * const key_s, const char * const value_s, const char * const null_sequence_s);
261 
262 
263 GRASSROOTS_FRICTIONLESS_DATA_API json_t *GetCSVDialect (const char *delimter_s, const char *line_terminator_s, const char *comment_char_p, const char *escape_char_p,
264  const char *null_seqeunce_s, const bool has_header_row_flag, const bool case_sensitive_header_flag,
265  const bool double_quote_flag, const bool skip_initial_space_flag, const char *quote_p,
266  const uint32 major_version, const uint32 minor_version);
267 
268 
269 
271 
273 
274 GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldMinimumInteger (json_t *field_p, const json_int_t value);
275 
276 GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldMinimumNumber (json_t *field_p, const double value);
277 
278 GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldMaximumInteger (json_t *field_p, const json_int_t value);
279 
280 GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldMaximumNumber (json_t *field_p, const double value);
281 
282 GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldPattern (json_t *field_p, const char * const pattern_s);
283 
284 GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldEnum (json_t *field_p, json_t *enum_p);
285 
286 GRASSROOTS_FRICTIONLESS_DATA_API json_t *GetDataPackage (const char *name_s, const char *description_s, const char *id_s);
287 
288 
289 GRASSROOTS_FRICTIONLESS_DATA_API const char *GetRefSchemaURI (const json_t *field_p);
290 
291 
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 
297 
298 #endif /* SERVICES_FIELD_TRIALS_INCLUDE_FRICTIONLESS_DATA_UTIL_H_ */
SetTableFieldMaximumInteger
GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldMaximumInteger(json_t *field_p, const json_int_t value)
AddTableField
GRASSROOTS_FRICTIONLESS_DATA_API json_t * AddTableField(json_t *fields_p, const char *name_s, const char *title_s, const char *type_s, const char *format_s, const char *description_s, const char *rdf_type_s)
AddNumberField
GRASSROOTS_FRICTIONLESS_DATA_API json_t * AddNumberField(json_t *fields_p, const char *name_s, const char *title_s, const char *format_s, const char *description_s, const char *rdf_type_s, const double *min_value_p)
SetTableFieldUnique
GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldUnique(json_t *field_p)
GetRefSchemaURI
const GRASSROOTS_FRICTIONLESS_DATA_API char * GetRefSchemaURI(const json_t *field_p)
SetFDTableString
GRASSROOTS_FRICTIONLESS_DATA_API bool SetFDTableString(json_t *row_p, const char *const key_s, const char *const value_s, const char *const null_sequence_s)
SetTableFieldMinimumInteger
GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldMinimumInteger(json_t *field_p, const json_int_t value)
SetTableFieldEnum
GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldEnum(json_t *field_p, json_t *enum_p)
SetTableFieldRequired
GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldRequired(json_t *field_p)
SetTableFieldMinimumNumber
GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldMinimumNumber(json_t *field_p, const double value)
SetTableFieldMaximumNumber
GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldMaximumNumber(json_t *field_p, const double value)
SetTableFieldPattern
GRASSROOTS_FRICTIONLESS_DATA_API bool SetTableFieldPattern(json_t *field_p, const char *const pattern_s)
GetCSVDialect
GRASSROOTS_FRICTIONLESS_DATA_API json_t * GetCSVDialect(const char *delimter_s, const char *line_terminator_s, const char *comment_char_p, const char *escape_char_p, const char *null_seqeunce_s, const bool has_header_row_flag, const bool case_sensitive_header_flag, const bool double_quote_flag, const bool skip_initial_space_flag, const char *quote_p, const uint32 major_version, const uint32 minor_version)
grassroots_frictionless_data_library.h
GetDataPackage
GRASSROOTS_FRICTIONLESS_DATA_API json_t * GetDataPackage(const char *name_s, const char *description_s, const char *id_s)
AddIntegerField
GRASSROOTS_FRICTIONLESS_DATA_API json_t * AddIntegerField(json_t *fields_p, const char *name_s, const char *title_s, const char *format_s, const char *description_s, const char *rdf_type_s, const int *min_value_p)
GRASSROOTS_FRICTIONLESS_DATA_API
#define GRASSROOTS_FRICTIONLESS_DATA_API
Definition: grassroots_frictionless_data_library.h:47
FD_UTIL_VAL
const FD_UTIL_PREFIX char *const FD_PROFILE_S FD_UTIL_VAL("profile")
SetFDTableReal
GRASSROOTS_FRICTIONLESS_DATA_API bool SetFDTableReal(json_t *row_p, const char *const key_s, const double64 *value_p, const char *const null_sequence_s)