From b68ef3071d663656ff845efee3c0da4a30f3fc6a Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 2 Jan 2025 12:15:13 +1100 Subject: [PATCH 1/7] mitielib : narrow scope of 'using namespace std' directives to avoid name clashes when using later versions of C++ standard --- mitielib/include/mitie/approximate_substring_set.h | 4 ++-- mitielib/include/mitie/gigaword_reader.h | 9 ++++----- mitielib/src/binary_relation_detector_trainer.cpp | 2 +- mitielib/src/conll_parser.cpp | 2 +- mitielib/src/ner_trainer.cpp | 2 +- mitielib/src/text_categorizer_trainer.cpp | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/mitielib/include/mitie/approximate_substring_set.h b/mitielib/include/mitie/approximate_substring_set.h index d1202b5a5..52375265f 100644 --- a/mitielib/include/mitie/approximate_substring_set.h +++ b/mitielib/include/mitie/approximate_substring_set.h @@ -9,12 +9,12 @@ #include #include -using namespace std; - // ---------------------------------------------------------------------------------------- namespace mitie { + using namespace std; + class approximate_substring_set { /*! diff --git a/mitielib/include/mitie/gigaword_reader.h b/mitielib/include/mitie/gigaword_reader.h index 7cde27794..fdc9932d8 100644 --- a/mitielib/include/mitie/gigaword_reader.h +++ b/mitielib/include/mitie/gigaword_reader.h @@ -82,11 +82,10 @@ namespace mitie if (!eh.no_errors) { - using namespace std; - cout << "doc.id: " << doc.id << endl; - cout << "doc.type: " << doc.type << endl; - cout << "doc.headline: " << doc.headline << endl; - cout << "Are there & references in the text? Per the XML standard, these should be lowercase.\n" << endl; + std::cout << "doc.id: " << doc.id << std::endl; + std::cout << "doc.type: " << doc.type << std::endl; + std::cout << "doc.headline: " << doc.headline << std::endl; + std::cout << "Are there & references in the text? Per the XML standard, these should be lowercase.\n" << std::endl; } return eh.no_errors && in->good(); } diff --git a/mitielib/src/binary_relation_detector_trainer.cpp b/mitielib/src/binary_relation_detector_trainer.cpp index f46813b6b..df1b83715 100644 --- a/mitielib/src/binary_relation_detector_trainer.cpp +++ b/mitielib/src/binary_relation_detector_trainer.cpp @@ -7,10 +7,10 @@ #include using namespace dlib; -using namespace std; namespace mitie { + using namespace std; // ---------------------------------------------------------------------------------------- diff --git a/mitielib/src/conll_parser.cpp b/mitielib/src/conll_parser.cpp index 66327d638..8966a6933 100644 --- a/mitielib/src/conll_parser.cpp +++ b/mitielib/src/conll_parser.cpp @@ -6,11 +6,11 @@ #include #include -using namespace std; using namespace dlib; namespace mitie { + using namespace std; // ---------------------------------------------------------------------------------------- diff --git a/mitielib/src/ner_trainer.cpp b/mitielib/src/ner_trainer.cpp index ec2f74e0b..9176676b1 100644 --- a/mitielib/src/ner_trainer.cpp +++ b/mitielib/src/ner_trainer.cpp @@ -7,11 +7,11 @@ #include #include -using namespace std; using namespace dlib; namespace mitie { + using namespace std; // ---------------------------------------------------------------------------------------- diff --git a/mitielib/src/text_categorizer_trainer.cpp b/mitielib/src/text_categorizer_trainer.cpp index bc4deca39..88e628b2a 100644 --- a/mitielib/src/text_categorizer_trainer.cpp +++ b/mitielib/src/text_categorizer_trainer.cpp @@ -5,11 +5,11 @@ #include #include -using namespace std; using namespace dlib; namespace mitie { + using namespace std; // ---------------------------------------------------------------------------------------- text_categorizer_trainer:: From 1194f35b377889817c5160864b60a7e0fc4a5368 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 3 Jan 2025 17:03:26 +1100 Subject: [PATCH 2/7] mitielib : fix shared library compilation for C++ API * Add MITIE_API prefixes to C++ functions and classes to ensure symbols are exported to shared libraries * Rename MITIE_EXPORT->MITIE_API in mitie.h header * Convert const variables in conll_parser and ner_feature_extraction headers to constexpr --- mitielib/include/mitie.h | 150 +++++++++--------- .../include/mitie/approximate_substring_set.h | 3 +- .../include/mitie/binary_relation_detector.h | 7 +- .../mitie/binary_relation_detector_trainer.h | 3 +- mitielib/include/mitie/conll_parser.h | 67 ++++---- mitielib/include/mitie/conll_tokenizer.h | 3 +- mitielib/include/mitie/count_min_sketch.h | 13 +- mitielib/include/mitie/gigaword_reader.h | 13 +- mitielib/include/mitie/group_tokenizer.h | 1 - mitielib/include/mitie/mitie_api_prefix.h | 18 +++ .../include/mitie/named_entity_extractor.h | 3 +- .../include/mitie/ner_feature_extraction.h | 9 +- mitielib/include/mitie/ner_trainer.h | 11 +- mitielib/include/mitie/stemmer.h | 3 +- mitielib/include/mitie/text_categorizer.h | 3 +- .../include/mitie/text_categorizer_trainer.h | 3 +- .../include/mitie/text_feature_extraction.h | 7 +- .../mitie/total_word_feature_extractor.h | 5 +- mitielib/include/mitie/unigram_tokenizer.h | 3 +- .../mitie/word_morphology_feature_extractor.h | 5 +- 20 files changed, 180 insertions(+), 150 deletions(-) create mode 100644 mitielib/include/mitie/mitie_api_prefix.h diff --git a/mitielib/include/mitie.h b/mitielib/include/mitie.h index b5136e7cf..a137f3aa4 100644 --- a/mitielib/include/mitie.h +++ b/mitielib/include/mitie.h @@ -4,11 +4,7 @@ #ifndef MITLL_MITIe_H_ #define MITLL_MITIe_H_ -#if defined(_WIN32) -#define MITIE_EXPORT __declspec(dllexport) -#else -#define MITIE_EXPORT -#endif +#include #ifdef __cplusplus extern "C" @@ -35,7 +31,7 @@ extern "C" typedef struct mitie_named_entity_extractor mitie_named_entity_extractor; typedef struct mitie_named_entity_detections mitie_named_entity_detections; - MITIE_EXPORT void mitie_free ( + MITIE_API void mitie_free ( void* object ); /*! @@ -47,7 +43,7 @@ extern "C" // ---------------------------------------------------------------------------------------- - MITIE_EXPORT char* mitie_load_entire_file ( + MITIE_API char* mitie_load_entire_file ( const char* filename ); /*! @@ -63,7 +59,7 @@ extern "C" // ---------------------------------------------------------------------------------------- - MITIE_EXPORT char** mitie_tokenize ( + MITIE_API char** mitie_tokenize ( const char* text ); /*! @@ -83,7 +79,7 @@ extern "C" - If something prevents this function from succeeding then a NULL is returned. !*/ - MITIE_EXPORT char** mitie_tokenize_file ( + MITIE_API char** mitie_tokenize_file ( const char* filename ); /*! @@ -96,7 +92,7 @@ extern "C" // ---------------------------------------------------------------------------------------- - MITIE_EXPORT char** mitie_tokenize_with_offsets ( + MITIE_API char** mitie_tokenize_with_offsets ( const char* text, unsigned long** token_offsets ); @@ -119,7 +115,7 @@ extern "C" // ---------------------------------------------------------------------------------------- - MITIE_EXPORT mitie_named_entity_extractor* mitie_load_named_entity_extractor ( + MITIE_API mitie_named_entity_extractor* mitie_load_named_entity_extractor ( const char* filename ); /*! @@ -132,7 +128,7 @@ extern "C" - If the object can't be created then this function returns NULL. !*/ - MITIE_EXPORT mitie_named_entity_extractor* mitie_load_named_entity_extractor_pure_model ( + MITIE_API mitie_named_entity_extractor* mitie_load_named_entity_extractor_pure_model ( const char* filename, const char* fe_filename ); @@ -154,7 +150,7 @@ extern "C" typedef struct mitie_total_word_feature_extractor mitie_total_word_feature_extractor; - MITIE_EXPORT int mitie_check_ner_pure_model( + MITIE_API int mitie_check_ner_pure_model( const char* filename ); /*! @@ -169,7 +165,7 @@ extern "C" - returns 0 if its a pure model and a non-zero value otherwise !*/ - MITIE_EXPORT mitie_named_entity_extractor* mitie_load_named_entity_extractor_pure_model_without_feature_extractor ( + MITIE_API mitie_named_entity_extractor* mitie_load_named_entity_extractor_pure_model_without_feature_extractor ( const char* filename ); /*! @@ -187,7 +183,7 @@ extern "C" - If the object can't be created then this function returns NULL. !*/ - MITIE_EXPORT unsigned long mitie_get_num_possible_ner_tags ( + MITIE_API unsigned long mitie_get_num_possible_ner_tags ( const mitie_named_entity_extractor* ner ); /*! @@ -201,7 +197,7 @@ extern "C" the numeric IDs are just 0, 1, 2, and 3. !*/ - MITIE_EXPORT const char* mitie_get_named_entity_tagstr ( + MITIE_API const char* mitie_get_named_entity_tagstr ( const mitie_named_entity_extractor* ner, unsigned long idx ); @@ -219,7 +215,7 @@ extern "C" // ---------------------------------------------------------------------------------------- - MITIE_EXPORT mitie_named_entity_detections* mitie_extract_entities ( + MITIE_API mitie_named_entity_detections* mitie_extract_entities ( const mitie_named_entity_extractor* ner, char** tokens ); @@ -236,7 +232,7 @@ extern "C" - If the object can't be created then this function returns NULL !*/ - MITIE_EXPORT mitie_named_entity_detections* mitie_extract_entities_with_extractor( + MITIE_API mitie_named_entity_detections* mitie_extract_entities_with_extractor( const mitie_named_entity_extractor* ner, char** tokens, const mitie_total_word_feature_extractor* fe @@ -256,7 +252,7 @@ extern "C" - If the object can't be created then this function returns NULL !*/ - MITIE_EXPORT unsigned long mitie_ner_get_num_detections ( + MITIE_API unsigned long mitie_ner_get_num_detections ( const mitie_named_entity_detections* dets ); /*! @@ -266,7 +262,7 @@ extern "C" - returns the number of named entity detections inside the dets object. !*/ - MITIE_EXPORT unsigned long mitie_ner_get_detection_position ( + MITIE_API unsigned long mitie_ner_get_detection_position ( const mitie_named_entity_detections* dets, unsigned long idx ); @@ -287,7 +283,7 @@ extern "C" entities never contain the same tokens as each other. !*/ - MITIE_EXPORT unsigned long mitie_ner_get_detection_length ( + MITIE_API unsigned long mitie_ner_get_detection_length ( const mitie_named_entity_detections* dets, unsigned long idx ); @@ -301,7 +297,7 @@ extern "C" named entity detection. !*/ - MITIE_EXPORT unsigned long mitie_ner_get_detection_tag ( + MITIE_API unsigned long mitie_ner_get_detection_tag ( const mitie_named_entity_detections* dets, unsigned long idx ); @@ -313,7 +309,7 @@ extern "C" - returns a numeric value that identifies the type of the idx-th named entity. !*/ - MITIE_EXPORT const char* mitie_ner_get_detection_tagstr ( + MITIE_API const char* mitie_ner_get_detection_tagstr ( const mitie_named_entity_detections* dets, unsigned long idx ); @@ -327,7 +323,7 @@ extern "C" - The returned pointer is valid until mitie_free(dets) is called. !*/ - MITIE_EXPORT double mitie_ner_get_detection_score ( + MITIE_API double mitie_ner_get_detection_score ( const mitie_named_entity_detections* dets, unsigned long idx ); @@ -349,7 +345,7 @@ extern "C" typedef struct mitie_binary_relation_detector mitie_binary_relation_detector; typedef struct mitie_binary_relation mitie_binary_relation; - MITIE_EXPORT mitie_binary_relation_detector* mitie_load_binary_relation_detector ( + MITIE_API mitie_binary_relation_detector* mitie_load_binary_relation_detector ( const char* filename ); /*! @@ -362,7 +358,7 @@ extern "C" - If the object can't be created then this function returns NULL. !*/ - MITIE_EXPORT const char* mitie_binary_relation_detector_name_string ( + MITIE_API const char* mitie_binary_relation_detector_name_string ( const mitie_binary_relation_detector* detector ); /*! @@ -374,7 +370,7 @@ extern "C" - The returned pointer is valid until mitie_free(detector) is called. !*/ - MITIE_EXPORT int mitie_entities_overlap ( + MITIE_API int mitie_entities_overlap ( unsigned long arg1_start, unsigned long arg1_length, unsigned long arg2_start, @@ -389,7 +385,7 @@ extern "C" overlap and returns 1 if they do. !*/ - MITIE_EXPORT mitie_binary_relation* mitie_extract_binary_relation ( + MITIE_API mitie_binary_relation* mitie_extract_binary_relation ( const mitie_named_entity_extractor* ner, char** tokens, unsigned long arg1_start, @@ -430,7 +426,7 @@ extern "C" - returns NULL if the object could not be created. !*/ - MITIE_EXPORT int mitie_classify_binary_relation ( + MITIE_API int mitie_classify_binary_relation ( const mitie_binary_relation_detector* detector, const mitie_binary_relation* relation, double* score @@ -459,7 +455,7 @@ extern "C" typedef struct mitie_text_categorizer mitie_text_categorizer; typedef struct mitie_text_categorizer_trainer mitie_text_categorizer_trainer; - MITIE_EXPORT mitie_text_categorizer* mitie_load_text_categorizer ( + MITIE_API mitie_text_categorizer* mitie_load_text_categorizer ( const char* filename ); /*! @@ -472,7 +468,7 @@ extern "C" - If the object can't be created then this function returns NULL. !*/ - MITIE_EXPORT mitie_text_categorizer* mitie_load_text_categorizer_pure_model ( + MITIE_API mitie_text_categorizer* mitie_load_text_categorizer_pure_model ( const char* filename, const char* fe_filename ); @@ -492,7 +488,7 @@ extern "C" - If the object can't be created then this function returns NULL. !*/ - MITIE_EXPORT int mitie_check_text_categorizer_pure_model( + MITIE_API int mitie_check_text_categorizer_pure_model( const char* filename ); /*! @@ -506,7 +502,7 @@ extern "C" - returns 0 if its a pure model and a non-zero value otherwise !*/ - MITIE_EXPORT mitie_text_categorizer* mitie_load_text_categorizer_pure_model_without_feature_extractor( + MITIE_API mitie_text_categorizer* mitie_load_text_categorizer_pure_model_without_feature_extractor( const char* filename ); /*! @@ -521,7 +517,7 @@ extern "C" - If the object can't be created then this function returns NULL. !*/ - MITIE_EXPORT int mitie_categorize_text ( + MITIE_API int mitie_categorize_text ( const mitie_text_categorizer* tcat, const char** tokens, char** text_tag, @@ -548,7 +544,7 @@ extern "C" - *score == the confidence the categorizer has about its prediction. !*/ - MITIE_EXPORT int mitie_categorize_text_with_extractor ( + MITIE_API int mitie_categorize_text_with_extractor ( const mitie_text_categorizer* tcat, const char** tokens, char** text_tag, @@ -584,7 +580,7 @@ extern "C" // ---------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------- - MITIE_EXPORT int mitie_save_named_entity_extractor ( + MITIE_API int mitie_save_named_entity_extractor ( const char* filename, const mitie_named_entity_extractor* ner ); @@ -600,7 +596,7 @@ extern "C" there is some error that prevents us from writing to the given file. !*/ - MITIE_EXPORT int mitie_save_named_entity_extractor_pure_model ( + MITIE_API int mitie_save_named_entity_extractor_pure_model ( const char* filename, const mitie_named_entity_extractor* ner ); @@ -620,7 +616,7 @@ extern "C" there is some error that prevents us from writing to the given file. !*/ - MITIE_EXPORT int mitie_save_binary_relation_detector ( + MITIE_API int mitie_save_binary_relation_detector ( const char* filename, const mitie_binary_relation_detector* detector ); @@ -636,7 +632,7 @@ extern "C" there is some error that prevents us from writing to the given file. !*/ - MITIE_EXPORT int mitie_save_text_categorizer ( + MITIE_API int mitie_save_text_categorizer ( const char* filename, const mitie_text_categorizer* tcat ); @@ -652,7 +648,7 @@ extern "C" there is some error that prevents us from writing to the given file. !*/ - MITIE_EXPORT int mitie_save_text_categorizer_pure_model ( + MITIE_API int mitie_save_text_categorizer_pure_model ( const char* filename, const mitie_text_categorizer* tcat ); @@ -677,7 +673,7 @@ extern "C" typedef struct mitie_ner_trainer mitie_ner_trainer; typedef struct mitie_ner_training_instance mitie_ner_training_instance; - MITIE_EXPORT mitie_ner_training_instance* mitie_create_ner_training_instance ( + MITIE_API mitie_ner_training_instance* mitie_create_ner_training_instance ( char** tokens ); /*! @@ -694,7 +690,7 @@ extern "C" - returns NULL if the object could not be created. !*/ - MITIE_EXPORT unsigned long mitie_ner_training_instance_num_tokens ( + MITIE_API unsigned long mitie_ner_training_instance_num_tokens ( const mitie_ner_training_instance* instance ); /*! @@ -706,7 +702,7 @@ extern "C" mitie_create_ner_training_instance(). !*/ - MITIE_EXPORT unsigned long mitie_ner_training_instance_num_entities ( + MITIE_API unsigned long mitie_ner_training_instance_num_entities ( const mitie_ner_training_instance* instance ); /*! @@ -718,7 +714,7 @@ extern "C" mitie_add_ner_training_entity() increases this count by 1. !*/ - MITIE_EXPORT int mitie_overlaps_any_entity ( + MITIE_API int mitie_overlaps_any_entity ( mitie_ner_training_instance* instance, unsigned long start, unsigned long length @@ -735,7 +731,7 @@ extern "C" - returns 1 if any entities overlap and 0 otherwise. !*/ - MITIE_EXPORT int mitie_add_ner_training_entity ( + MITIE_API int mitie_add_ner_training_entity ( mitie_ner_training_instance* instance, unsigned long start, unsigned long length, @@ -756,7 +752,7 @@ extern "C" caused by running out of memory. !*/ - MITIE_EXPORT mitie_ner_trainer* mitie_create_ner_trainer ( + MITIE_API mitie_ner_trainer* mitie_create_ner_trainer ( const char* filename ); /*! @@ -776,7 +772,7 @@ extern "C" That is, initially there are no training instances in the trainer. !*/ - MITIE_EXPORT unsigned long mitie_ner_trainer_size ( + MITIE_API unsigned long mitie_ner_trainer_size ( const mitie_ner_trainer* trainer ); /*! @@ -786,7 +782,7 @@ extern "C" - returns the number of training instances in the given trainer object. !*/ - MITIE_EXPORT int mitie_add_ner_training_instance( + MITIE_API int mitie_add_ner_training_instance( mitie_ner_trainer* trainer, const mitie_ner_training_instance* instance ); @@ -801,7 +797,7 @@ extern "C" caused by running out of memory. !*/ - MITIE_EXPORT void mitie_ner_trainer_set_beta ( + MITIE_API void mitie_ner_trainer_set_beta ( mitie_ner_trainer* trainer, double beta ); @@ -813,7 +809,7 @@ extern "C" - mitie_ner_trainer_get_beta(trainer) == beta !*/ - MITIE_EXPORT double mitie_ner_trainer_get_beta ( + MITIE_API double mitie_ner_trainer_get_beta ( const mitie_ner_trainer* trainer ); /*! @@ -833,7 +829,7 @@ extern "C" avoiding false alarms. !*/ - MITIE_EXPORT void mitie_ner_trainer_set_num_threads ( + MITIE_API void mitie_ner_trainer_set_num_threads ( mitie_ner_trainer* trainer, unsigned long num_threads ); @@ -844,7 +840,7 @@ extern "C" - mitie_ner_trainer_get_num_threads(trainer) == num_threads !*/ - MITIE_EXPORT unsigned long mitie_ner_trainer_get_num_threads ( + MITIE_API unsigned long mitie_ner_trainer_get_num_threads ( const mitie_ner_trainer* trainer ); /*! @@ -856,7 +852,7 @@ extern "C" the number of available CPU cores for maximum training speed. !*/ - MITIE_EXPORT mitie_named_entity_extractor* mitie_train_named_entity_extractor ( + MITIE_API mitie_named_entity_extractor* mitie_train_named_entity_extractor ( const mitie_ner_trainer* trainer ); /*! @@ -875,7 +871,7 @@ extern "C" typedef struct mitie_binary_relation_trainer mitie_binary_relation_trainer; - MITIE_EXPORT mitie_binary_relation_trainer* mitie_create_binary_relation_trainer ( + MITIE_API mitie_binary_relation_trainer* mitie_create_binary_relation_trainer ( const char* relation_name, const mitie_named_entity_extractor* ner ); @@ -899,7 +895,7 @@ extern "C" instances in it. !*/ - MITIE_EXPORT unsigned long mitie_binary_relation_trainer_num_positive_examples ( + MITIE_API unsigned long mitie_binary_relation_trainer_num_positive_examples ( const mitie_binary_relation_trainer* trainer ); /*! @@ -909,7 +905,7 @@ extern "C" - returns the number of positive training instances in the given trainer object. !*/ - MITIE_EXPORT unsigned long mitie_binary_relation_trainer_num_negative_examples ( + MITIE_API unsigned long mitie_binary_relation_trainer_num_negative_examples ( const mitie_binary_relation_trainer* trainer ); /*! @@ -919,7 +915,7 @@ extern "C" - returns the number of negative training instances in the given trainer object. !*/ - MITIE_EXPORT int mitie_add_positive_binary_relation ( + MITIE_API int mitie_add_positive_binary_relation ( mitie_binary_relation_trainer* trainer, char** tokens, unsigned long arg1_start, @@ -954,7 +950,7 @@ extern "C" happen if we run out of memory. !*/ - MITIE_EXPORT int mitie_add_negative_binary_relation ( + MITIE_API int mitie_add_negative_binary_relation ( mitie_binary_relation_trainer* trainer, char** tokens, unsigned long arg1_start, @@ -988,7 +984,7 @@ extern "C" happen if we run out of memory. !*/ - MITIE_EXPORT void mitie_binary_relation_trainer_set_beta ( + MITIE_API void mitie_binary_relation_trainer_set_beta ( mitie_binary_relation_trainer* trainer, double beta ); @@ -1000,7 +996,7 @@ extern "C" - mitie_binary_relation_trainer_get_beta(trainer) == beta !*/ - MITIE_EXPORT double mitie_binary_relation_trainer_get_beta ( + MITIE_API double mitie_binary_relation_trainer_get_beta ( const mitie_binary_relation_trainer* trainer ); /*! @@ -1020,7 +1016,7 @@ extern "C" avoiding false alarms. !*/ - MITIE_EXPORT void mitie_binary_relation_trainer_set_num_threads ( + MITIE_API void mitie_binary_relation_trainer_set_num_threads ( mitie_binary_relation_trainer* trainer, unsigned long num_threads ); @@ -1031,7 +1027,7 @@ extern "C" - mitie_binary_relation_trainer_get_num_threads(trainer) == num_threads !*/ - MITIE_EXPORT unsigned long mitie_binary_relation_trainer_get_num_threads ( + MITIE_API unsigned long mitie_binary_relation_trainer_get_num_threads ( const mitie_binary_relation_trainer* trainer ); /*! @@ -1043,7 +1039,7 @@ extern "C" to the number of available CPU cores for maximum training speed. !*/ - MITIE_EXPORT mitie_binary_relation_detector* mitie_train_binary_relation_detector ( + MITIE_API mitie_binary_relation_detector* mitie_train_binary_relation_detector ( const mitie_binary_relation_trainer* trainer ); /*! @@ -1060,7 +1056,7 @@ extern "C" !*/ // ---------------------------------------------------------------------------------------- - MITIE_EXPORT mitie_text_categorizer_trainer* mitie_create_text_categorizer_trainer ( + MITIE_API mitie_text_categorizer_trainer* mitie_create_text_categorizer_trainer ( const char* filename ); /*! @@ -1080,7 +1076,7 @@ extern "C" That is, initially there are no training instances in the trainer. !*/ - MITIE_EXPORT unsigned long mitie_text_categorizer_trainer_size ( + MITIE_API unsigned long mitie_text_categorizer_trainer_size ( const mitie_text_categorizer_trainer* trainer ); /*! @@ -1091,7 +1087,7 @@ extern "C" !*/ - MITIE_EXPORT void mitie_text_categorizer_trainer_set_beta ( + MITIE_API void mitie_text_categorizer_trainer_set_beta ( mitie_text_categorizer_trainer* trainer, double beta ); @@ -1103,7 +1099,7 @@ extern "C" - mitie_text_categorizer_trainer_get_beta(trainer) == beta !*/ - MITIE_EXPORT double mitie_text_categorizer_trainer_get_beta ( + MITIE_API double mitie_text_categorizer_trainer_get_beta ( const mitie_text_categorizer_trainer* trainer ); /*! @@ -1116,7 +1112,7 @@ extern "C" recall as precision. Set to 1 if these are equally important. !*/ - MITIE_EXPORT void mitie_text_categorizer_trainer_set_num_threads ( + MITIE_API void mitie_text_categorizer_trainer_set_num_threads ( mitie_text_categorizer_trainer* trainer, unsigned long num_threads ); @@ -1127,7 +1123,7 @@ extern "C" - mitie_text_categorizer_trainer_get_num_threads(trainer) == num_threads !*/ - MITIE_EXPORT unsigned long mitie_text_categorizer_trainer_get_num_threads ( + MITIE_API unsigned long mitie_text_categorizer_trainer_get_num_threads ( const mitie_text_categorizer_trainer* trainer ); /*! @@ -1139,7 +1135,7 @@ extern "C" the number of available CPU cores for maximum training speed. !*/ - MITIE_EXPORT int mitie_add_text_categorizer_labeled_text ( + MITIE_API int mitie_add_text_categorizer_labeled_text ( mitie_text_categorizer_trainer* trainer, const char** tokens, const char* label @@ -1159,7 +1155,7 @@ extern "C" caused by running out of memory. !*/ - MITIE_EXPORT mitie_text_categorizer* mitie_train_text_categorizer ( + MITIE_API mitie_text_categorizer* mitie_train_text_categorizer ( const mitie_text_categorizer_trainer* trainer ); /*! @@ -1176,7 +1172,7 @@ extern "C" // ---------------------------------------------------------------------------------------- - MITIE_EXPORT mitie_total_word_feature_extractor* mitie_load_total_word_feature_extractor ( + MITIE_API mitie_total_word_feature_extractor* mitie_load_total_word_feature_extractor ( const char* filename ); /*! @@ -1190,7 +1186,7 @@ extern "C" !*/ - MITIE_EXPORT unsigned long mitie_total_word_feature_extractor_fingerprint ( + MITIE_API unsigned long mitie_total_word_feature_extractor_fingerprint ( const mitie_total_word_feature_extractor* twfe ); /*! @@ -1200,7 +1196,7 @@ extern "C" - returns a 64bit ID number that uniquely identifies this object instance !*/ - MITIE_EXPORT unsigned long mitie_total_word_feature_extractor_num_dimensions ( + MITIE_API unsigned long mitie_total_word_feature_extractor_num_dimensions ( const mitie_total_word_feature_extractor* twfe ); /*! @@ -1210,7 +1206,7 @@ extern "C" - returns the dimensionality of the feature vectors produced by this object. !*/ - MITIE_EXPORT unsigned long mitie_total_word_feature_extractor_num_words_in_dictionary ( + MITIE_API unsigned long mitie_total_word_feature_extractor_num_words_in_dictionary ( const mitie_total_word_feature_extractor* twfe ); /*! @@ -1224,7 +1220,7 @@ extern "C" - Therefore, this function returns the number of words in the dictionary. !*/ - MITIE_EXPORT int mitie_total_word_feature_extractor_get_feature_vector ( + MITIE_API int mitie_total_word_feature_extractor_get_feature_vector ( const mitie_total_word_feature_extractor* twfe, const char* word, float* result @@ -1239,7 +1235,7 @@ extern "C" - returns 0 if successful, 1 if there is an error. !*/ - MITIE_EXPORT char** mitie_total_word_feature_extractor_get_words_in_dictionary ( + MITIE_API char** mitie_total_word_feature_extractor_get_words_in_dictionary ( const mitie_total_word_feature_extractor* twfe ); /*! diff --git a/mitielib/include/mitie/approximate_substring_set.h b/mitielib/include/mitie/approximate_substring_set.h index 52375265f..332444bed 100644 --- a/mitielib/include/mitie/approximate_substring_set.h +++ b/mitielib/include/mitie/approximate_substring_set.h @@ -4,6 +4,7 @@ #ifndef MIT_LL_APPROXIMATE_SUBSTRiNG_SET_H_ #define MIT_LL_APPROXIMATE_SUBSTRiNG_SET_H_ +#include #include #include #include @@ -15,7 +16,7 @@ namespace mitie { using namespace std; - class approximate_substring_set + class MITIE_API approximate_substring_set { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/binary_relation_detector.h b/mitielib/include/mitie/binary_relation_detector.h index b0312c4a1..a5a50a0ae 100644 --- a/mitielib/include/mitie/binary_relation_detector.h +++ b/mitielib/include/mitie/binary_relation_detector.h @@ -4,6 +4,7 @@ #ifndef MIT_LL_BINARY_rELATION_DETECTION_H_ #define MIT_LL_BINARY_rELATION_DETECTION_H_ +#include #include #include #include @@ -19,7 +20,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - struct binary_relation + struct MITIE_API binary_relation { /*! WHAT THIS OBJECT REPRESENTS @@ -32,7 +33,7 @@ namespace mitie dlib::uint64 total_word_feature_extractor_fingerprint; }; - binary_relation extract_binary_relation ( + MITIE_API binary_relation extract_binary_relation ( const std::vector& tokens, const std::pair& rel_arg1, const std::pair& rel_arg2, @@ -52,7 +53,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - struct binary_relation_detector + struct MITIE_API binary_relation_detector { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/binary_relation_detector_trainer.h b/mitielib/include/mitie/binary_relation_detector_trainer.h index 9af4cba4a..eadb1d746 100644 --- a/mitielib/include/mitie/binary_relation_detector_trainer.h +++ b/mitielib/include/mitie/binary_relation_detector_trainer.h @@ -4,13 +4,14 @@ #ifndef MIT_LL_BINARY_rELATION_DETECTION_TRAINER_H_ #define MIT_LL_BINARY_rELATION_DETECTION_TRAINER_H_ +#include #include #include #include namespace mitie { - class binary_relation_detector_trainer + class MITIE_API binary_relation_detector_trainer { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/conll_parser.h b/mitielib/include/mitie/conll_parser.h index 6d0b56e1a..6d3d36752 100644 --- a/mitielib/include/mitie/conll_parser.h +++ b/mitielib/include/mitie/conll_parser.h @@ -4,6 +4,7 @@ #ifndef MIT_LL_CONLL_PaRSER_H_ #define MIT_LL_CONLL_PaRSER_H_ +#include #include #include @@ -14,32 +15,32 @@ namespace mitie typedef unsigned long BIO_label; - const unsigned long I_PER = 0; - const unsigned long B_PER = 1; - const unsigned long O = 2; - const unsigned long B_LOC = 3; - const unsigned long B_ORG = 4; - const unsigned long B_MISC = 5; - const unsigned long I_ORG = 6; - const unsigned long I_LOC = 7; - const unsigned long I_MISC = 8; + constexpr unsigned long I_PER = 0; + constexpr unsigned long B_PER = 1; + constexpr unsigned long O = 2; + constexpr unsigned long B_LOC = 3; + constexpr unsigned long B_ORG = 4; + constexpr unsigned long B_MISC = 5; + constexpr unsigned long I_ORG = 6; + constexpr unsigned long I_LOC = 7; + constexpr unsigned long I_MISC = 8; // BILOU extension - const unsigned long L_PER = 9; - const unsigned long L_ORG = 10; - const unsigned long L_LOC = 11; - const unsigned long L_MISC = 12; - const unsigned long U_PER = 13; - const unsigned long U_ORG = 14; - const unsigned long U_LOC = 15; - const unsigned long U_MISC = 16; + constexpr unsigned long L_PER = 9; + constexpr unsigned long L_ORG = 10; + constexpr unsigned long L_LOC = 11; + constexpr unsigned long L_MISC = 12; + constexpr unsigned long U_PER = 13; + constexpr unsigned long U_ORG = 14; + constexpr unsigned long U_LOC = 15; + constexpr unsigned long U_MISC = 16; // chunk labels - const unsigned long PER = 0; - const unsigned long LOC = 1; - const unsigned long ORG = 2; - const unsigned long MISC = 3; - const unsigned long NOT_ENTITY = 4; + constexpr unsigned long PER = 0; + constexpr unsigned long LOC = 1; + constexpr unsigned long ORG = 2; + constexpr unsigned long MISC = 3; + constexpr unsigned long NOT_ENTITY = 4; // ---------------------------------------------------------------------------------------- @@ -47,7 +48,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - void parse_conll_data ( + MITIE_API void parse_conll_data ( const std::string& filename, std::vector >& sentences, std::vector > >& chunks, @@ -70,7 +71,7 @@ namespace mitie - #chunk_labels[i][j] is equal to either PER, ORG, LOC, or MISC. !*/ - void parse_conll_data ( + MITIE_API void parse_conll_data ( const std::string& filename, std::vector >& sentences, std::vector > >& chunks, @@ -85,7 +86,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - std::vector parse_conll_data ( + MITIE_API std::vector parse_conll_data ( const std::string& filename ); /*! @@ -96,7 +97,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - void print_conll_data ( + MITIE_API void print_conll_data ( const std::vector& data ); /*! @@ -107,7 +108,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - void print_conll_data ( + MITIE_API void print_conll_data ( const std::vector& data, const std::vector >& extra_labels ); @@ -125,7 +126,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - void separate_labels_from_tokens ( + MITIE_API void separate_labels_from_tokens ( const std::vector& data, std::vector >& tokens, std::vector >& labels @@ -143,23 +144,23 @@ namespace mitie // ---------------------------------------------------------------------------------------- - std::string lookup_conll_label ( + MITIE_API std::string lookup_conll_label ( const BIO_label& label ); - void convert_from_BIO_to_BILOU ( + MITIE_API void convert_from_BIO_to_BILOU ( std::vector& labels ); - void convert_from_BILOU_to_BIO ( + MITIE_API void convert_from_BILOU_to_BIO ( std::vector& labels ); - void convert_from_BIO_to_BILOU ( + MITIE_API void convert_from_BIO_to_BILOU ( std::vector >& labels ); - void convert_from_BILOU_to_BIO ( + MITIE_API void convert_from_BILOU_to_BIO ( std::vector >& labels ); diff --git a/mitielib/include/mitie/conll_tokenizer.h b/mitielib/include/mitie/conll_tokenizer.h index 854f20d49..c17ff2b55 100644 --- a/mitielib/include/mitie/conll_tokenizer.h +++ b/mitielib/include/mitie/conll_tokenizer.h @@ -4,6 +4,7 @@ #ifndef MIT_LL_XTECH_CONLL_ToKENIZER_H_ #define MIT_LL_XTECH_CONLL_ToKENIZER_H_ +#include #include #include #include @@ -14,7 +15,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - class conll_tokenizer + class MITIE_API conll_tokenizer { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/count_min_sketch.h b/mitielib/include/mitie/count_min_sketch.h index c9e071397..12f336905 100644 --- a/mitielib/include/mitie/count_min_sketch.h +++ b/mitielib/include/mitie/count_min_sketch.h @@ -4,16 +4,17 @@ #ifndef MIT_LL_CoUNT_MIN_SKETCH_H_ #define MIT_LL_CoUNT_MIN_SKETCH_H_ -#include "dlib/array2d.h" -#include "dlib/uintn.h" -#include "dlib/hash.h" -#include "dlib/byte_orderer.h" +#include +#include +#include +#include +#include #include -#include "dlib/image_transforms.h" +#include namespace mitie { - class count_min_sketch + class MITIE_API count_min_sketch { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/gigaword_reader.h b/mitielib/include/mitie/gigaword_reader.h index fdc9932d8..c8dbcedf9 100644 --- a/mitielib/include/mitie/gigaword_reader.h +++ b/mitielib/include/mitie/gigaword_reader.h @@ -4,9 +4,10 @@ #ifndef MIT_LL_GIGAWoRD_READER_H_ #define MIT_LL_GIGAWoRD_READER_H_ -#include "dlib/xml_parser.h" -#include "dlib/string.h" -#include "dlib/dir_nav.h" +#include +#include +#include +#include #include #include @@ -15,7 +16,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - struct gigaword_document + struct MITIE_API gigaword_document { /*! WHAT THIS OBJECT REPRESENTS @@ -32,7 +33,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - class gigaword_file_reader + class MITIE_API gigaword_file_reader { /*! WHAT THIS OBJECT REPRESENTS @@ -242,7 +243,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - class gigaword_reader + class MITIE_API gigaword_reader { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/group_tokenizer.h b/mitielib/include/mitie/group_tokenizer.h index eb8569c10..8e775e9ca 100644 --- a/mitielib/include/mitie/group_tokenizer.h +++ b/mitielib/include/mitie/group_tokenizer.h @@ -9,7 +9,6 @@ #include #include - namespace mitie { template < diff --git a/mitielib/include/mitie/mitie_api_prefix.h b/mitielib/include/mitie/mitie_api_prefix.h new file mode 100644 index 000000000..dc224617f --- /dev/null +++ b/mitielib/include/mitie/mitie_api_prefix.h @@ -0,0 +1,18 @@ +#ifndef MITIE_API_PREFIX_H_ +#define MITIE_API_PREFIX_H_ + +#ifdef MITIE_SHARED +# if defined(_WIN32) +# ifdef MITIE_BUILD +# define MITIE_API __declspec(dllexport) +# else +# define MITIE_API __declspec(dllimport) +# endif +# else +# define MITIE_API __attribute__ ((visibility ("default"))) +# endif +#else +# define MITIE_API +#endif + +#endif // MITIE_API_PREFIX_H_ diff --git a/mitielib/include/mitie/named_entity_extractor.h b/mitielib/include/mitie/named_entity_extractor.h index 4ef672163..c14605234 100644 --- a/mitielib/include/mitie/named_entity_extractor.h +++ b/mitielib/include/mitie/named_entity_extractor.h @@ -4,6 +4,7 @@ #ifndef MIT_LL_MITIE_NaMED_ENTITY_EXTRACTOR_H_ #define MIT_LL_MITIE_NaMED_ENTITY_EXTRACTOR_H_ +#include #include #include #include @@ -12,7 +13,7 @@ namespace mitie { - class named_entity_extractor + class MITIE_API named_entity_extractor { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/ner_feature_extraction.h b/mitielib/include/mitie/ner_feature_extraction.h index bcbab7078..eb6da209f 100644 --- a/mitielib/include/mitie/ner_feature_extraction.h +++ b/mitielib/include/mitie/ner_feature_extraction.h @@ -4,6 +4,7 @@ #ifndef MIT_LL_MITIE_NeR_FEATURE_EXTRACTION_H_ #define MIT_LL_MITIE_NeR_FEATURE_EXTRACTION_H_ +#include #include #include #include @@ -16,7 +17,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - class ner_feature_extractor + class MITIE_API ner_feature_extractor { public: @@ -64,7 +65,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - std::vector > sentence_to_feats ( + MITIE_API std::vector > sentence_to_feats ( const total_word_feature_extractor& fe, const std::vector& sentence ); @@ -78,7 +79,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - const unsigned long MAX_FEAT = 500000; + constexpr unsigned long MAX_FEAT = 500000; inline std::pair make_feat ( const std::pair& hash @@ -103,7 +104,7 @@ namespace mitie typedef std::vector > ner_sample_type; - ner_sample_type extract_ner_chunk_features ( + MITIE_API ner_sample_type extract_ner_chunk_features ( const std::vector& words, const std::vector >& feats, const std::pair& chunk_range diff --git a/mitielib/include/mitie/ner_trainer.h b/mitielib/include/mitie/ner_trainer.h index e06c3b6a1..081448f36 100644 --- a/mitielib/include/mitie/ner_trainer.h +++ b/mitielib/include/mitie/ner_trainer.h @@ -4,6 +4,7 @@ #ifndef MIT_LL_MITIE_NER_TRAINER_H_ #define MIT_LL_MITIE_NER_TRAINER_H_ +#include #include #include #include @@ -17,7 +18,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - class ner_training_instance + class MITIE_API ner_training_instance { /*! WHAT THIS OBJECT REPRESENTS @@ -108,7 +109,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - class ner_trainer + class MITIE_API ner_trainer { /*! WHAT THIS OBJECT REPRESENTS @@ -274,7 +275,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------- - struct ner_eval_metrics + struct MITIE_API ner_eval_metrics { /*! WHAT THIS OBJECT REPRESENTS @@ -293,13 +294,13 @@ namespace mitie double overall_recall; }; - std::ostream& operator<< (std::ostream& out_, const ner_eval_metrics& item); + MITIE_API std::ostream& operator<< (std::ostream& out_, const ner_eval_metrics& item); /*! ensures - print the contents of item to the output stream in a nice format. !*/ - ner_eval_metrics evaluate_named_entity_recognizer ( + MITIE_API ner_eval_metrics evaluate_named_entity_recognizer ( const named_entity_extractor& ner, const std::vector >& sentences, const std::vector > >& chunks, diff --git a/mitielib/include/mitie/stemmer.h b/mitielib/include/mitie/stemmer.h index 0ca42e255..687c64cdd 100644 --- a/mitielib/include/mitie/stemmer.h +++ b/mitielib/include/mitie/stemmer.h @@ -4,11 +4,12 @@ #ifndef MIT_LL_STEM_WoRD_H_ #define MIT_LL_STEM_WoRD_H_ +#include #include namespace mitie { - std::string stem_word (const std::string& word); + MITIE_API std::string stem_word (const std::string& word); /*! ensures - lowercases word and then applies the Porter stemmer. The diff --git a/mitielib/include/mitie/text_categorizer.h b/mitielib/include/mitie/text_categorizer.h index 424363bcd..9fc7df287 100644 --- a/mitielib/include/mitie/text_categorizer.h +++ b/mitielib/include/mitie/text_categorizer.h @@ -2,6 +2,7 @@ #ifndef MITIE_TexT_CATEGORIZER_H #define MITIE_TexT_CATEGORIZER_H +#include #include #include #include @@ -11,7 +12,7 @@ namespace mitie { - class text_categorizer + class MITIE_API text_categorizer { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/text_categorizer_trainer.h b/mitielib/include/mitie/text_categorizer_trainer.h index 9c92c466d..f180ffa38 100644 --- a/mitielib/include/mitie/text_categorizer_trainer.h +++ b/mitielib/include/mitie/text_categorizer_trainer.h @@ -1,6 +1,7 @@ #ifndef MITIE_TEXT_CATEGORIZER_TRAINER_H #define MITIE_TEXT_CATEGORIZER_TRAINER_H +#include #include #include #include @@ -12,7 +13,7 @@ namespace mitie { - class text_categorizer_trainer + class MITIE_API text_categorizer_trainer { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/text_feature_extraction.h b/mitielib/include/mitie/text_feature_extraction.h index 013cafe56..5ccb6ff6c 100644 --- a/mitielib/include/mitie/text_feature_extraction.h +++ b/mitielib/include/mitie/text_feature_extraction.h @@ -1,6 +1,7 @@ #ifndef MIT_LL_MITIE_TexT_FEATURE_EXTRACTION_H_ #define MIT_LL_MITIE_TexT_FEATURE_EXTRACTION_H_ +#include #include #include #include @@ -16,7 +17,7 @@ namespace mitie typedef std::vector > text_sample_type; - text_sample_type extract_text_features ( + MITIE_API text_sample_type extract_text_features ( const std::vector& words, const std::vector >& feats ); @@ -30,7 +31,7 @@ namespace mitie !*/ // ---------------------------------------------------------------------------------------- - text_sample_type extract_BoW_features ( + MITIE_API text_sample_type extract_BoW_features ( const std::vector& words ); /*! @@ -42,7 +43,7 @@ namespace mitie !*/ // ---------------------------------------------------------------------------------------- - text_sample_type extract_combined_features ( + MITIE_API text_sample_type extract_combined_features ( const std::vector& words, const std::vector >& feats ); diff --git a/mitielib/include/mitie/total_word_feature_extractor.h b/mitielib/include/mitie/total_word_feature_extractor.h index fb81d1338..1d600b6f2 100644 --- a/mitielib/include/mitie/total_word_feature_extractor.h +++ b/mitielib/include/mitie/total_word_feature_extractor.h @@ -4,8 +4,9 @@ #ifndef MIT_LL_TOTAL_WoRD_FEATURE_EXTRACTOR_H_ #define MIT_LL_TOTAL_WoRD_FEATURE_EXTRACTOR_H_ +#include #include -#include "word_morphology_feature_extractor.h" +#include #include #include #include @@ -13,7 +14,7 @@ namespace mitie { - class total_word_feature_extractor + class MITIE_API total_word_feature_extractor { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/unigram_tokenizer.h b/mitielib/include/mitie/unigram_tokenizer.h index 60a6b525e..9fedb68dc 100644 --- a/mitielib/include/mitie/unigram_tokenizer.h +++ b/mitielib/include/mitie/unigram_tokenizer.h @@ -4,6 +4,7 @@ #ifndef MIT_LL_XTECH_UNIGRAM_ToKENIZER_H_ #define MIT_LL_XTECH_UNIGRAM_ToKENIZER_H_ +#include #include #include #include @@ -14,7 +15,7 @@ namespace mitie // ---------------------------------------------------------------------------------------- - class unigram_tokenizer + class MITIE_API unigram_tokenizer { /*! WHAT THIS OBJECT REPRESENTS diff --git a/mitielib/include/mitie/word_morphology_feature_extractor.h b/mitielib/include/mitie/word_morphology_feature_extractor.h index bae0a58e0..26fb23976 100644 --- a/mitielib/include/mitie/word_morphology_feature_extractor.h +++ b/mitielib/include/mitie/word_morphology_feature_extractor.h @@ -4,12 +4,13 @@ #ifndef MIT_LL_WORD_MORPHOLOGY_FEATURE_ExTRACTOR_H_ #define MIT_LL_WORD_MORPHOLOGY_FEATURE_ExTRACTOR_H_ -#include "approximate_substring_set.h" +#include +#include #include namespace mitie { - class word_morphology_feature_extractor + class MITIE_API word_morphology_feature_extractor { /*! WHAT THIS OBJECT REPRESENTS From 328fc5bdfe49d08905921db76474e2bcf4116390 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 4 Jan 2025 22:45:35 +1100 Subject: [PATCH 3/7] Initial CMake build process uplift * Create CMakeLists for overarching project root folder and modularise build options (aiming to set defaults which align to original behaviour) * Update mitielib CMakeLists to assume it is called from parent project CMakeLists and implement new build options * Add ability to prepend mitie- prefix to tools and examples executable output files --- CMakeLists.txt | 60 +++++++++++++++++++ examples/C/ner/CMakeLists.txt | 2 +- examples/C/relation_extraction/CMakeLists.txt | 2 +- examples/cpp/ner/CMakeLists.txt | 2 +- .../cpp/relation_extraction/CMakeLists.txt | 2 +- examples/cpp/text_categorizer/CMakeLists.txt | 2 +- examples/cpp/train_ner/CMakeLists.txt | 2 +- .../train_relation_extraction/CMakeLists.txt | 2 +- .../cpp/train_text_categorizer/CMakeLists.txt | 2 +- .../train_text_categorizer_BoW/CMakeLists.txt | 2 +- mitielib/CMakeLists.txt | 39 ++++++------ tools/ner_conll/CMakeLists.txt | 2 +- tools/ner_stream/CMakeLists.txt | 2 +- .../CMakeLists.txt | 2 +- tools/wordrep/CMakeLists.txt | 6 +- 15 files changed, 93 insertions(+), 36 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..c79234e33 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.10) +project(mitie_project) + + +option(MITIE_INTEGRATED_DLIB "mitie: build and statically link integrated dlib as shipped with MITIE codebase (otherwise look for system dlib)" ON) +option(MITIE_INTEGRATED_DLIB_DISABLE_OPT_COMPONENTS "mitie: disable optional components not required for MITIE when building integrated dlib (image libraries, FFmpeg, SQLite3)" ON) +option(MITIE_BUILD_TOOLS "mitie: build tools" ON) +option(MITIE_BUILD_EXAMPLES "mitie: build examples" ON) +option(MITIE_APPLY_EXECUTABLES_PREFIX "mitie: add 'mitie-' prefix to executables" OFF) + + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + +if(MITIE_APPLY_EXECUTABLES_PREFIX) + set(MITIE_EXECUTABLES_PREFIX "mitie-") +else() + set(MITIE_EXECUTABLES_PREFIX "") +endif() + + +# Build integrated dlib if requested +if(MITIE_INTEGRATED_DLIB) + if(MITIE_INTEGRATED_DLIB_DISABLE_OPT_COMPONENTS) + set(DLIB_PNG_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE) + set(DLIB_JPEG_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE) + set(DLIB_JXL_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE) + set(DLIB_GIF_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE) + set(DLIB_WEBP_SUPPORT OFF CACHE STRING "not needed by MITIE" FORCE) + set(DLIB_USE_FFMPEG OFF CACHE STRING "not needed by MITIE" FORCE) + set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING "not needed by MITIE" FORCE) + endif() + + add_subdirectory(dlib) +endif() + + +# MITIE core library +add_subdirectory(mitielib) + +# MITIE tools +if(MITIE_BUILD_TOOLS) + add_subdirectory(tools/ner_conll) + add_subdirectory(tools/ner_stream) + add_subdirectory(tools/train_freebase_relation_detector) + add_subdirectory(tools/wordrep) +endif() + +# MITIE examples (C and C++) +if(MITIE_BUILD_EXAMPLES) + add_subdirectory(examples/C/ner) + add_subdirectory(examples/C/relation_extraction) + add_subdirectory(examples/cpp/ner) + add_subdirectory(examples/cpp/relation_extraction) + add_subdirectory(examples/cpp/text_categorizer) + add_subdirectory(examples/cpp/train_ner) + add_subdirectory(examples/cpp/train_relation_extraction) + add_subdirectory(examples/cpp/train_text_categorizer) + add_subdirectory(examples/cpp/train_text_categorizer_BoW) +endif() diff --git a/examples/C/ner/CMakeLists.txt b/examples/C/ner/CMakeLists.txt index 627f9f9a2..976ad3224 100644 --- a/examples/C/ner/CMakeLists.txt +++ b/examples/C/ner/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name ner_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}ner_c_example") set(source ner_example.c ) diff --git a/examples/C/relation_extraction/CMakeLists.txt b/examples/C/relation_extraction/CMakeLists.txt index cec6cf591..d1764fee9 100644 --- a/examples/C/relation_extraction/CMakeLists.txt +++ b/examples/C/relation_extraction/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name relation_extraction_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}relation_extraction_c_example") set(source relation_extraction_example.c ) diff --git a/examples/cpp/ner/CMakeLists.txt b/examples/cpp/ner/CMakeLists.txt index aa3e34e48..63154c8db 100644 --- a/examples/cpp/ner/CMakeLists.txt +++ b/examples/cpp/ner/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name ner_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}ner_example") set(source ner_example.cpp ) diff --git a/examples/cpp/relation_extraction/CMakeLists.txt b/examples/cpp/relation_extraction/CMakeLists.txt index d0abdb953..d0bebad60 100644 --- a/examples/cpp/relation_extraction/CMakeLists.txt +++ b/examples/cpp/relation_extraction/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name relation_extraction_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}relation_extraction_example") set(source relation_extraction_example.cpp ) diff --git a/examples/cpp/text_categorizer/CMakeLists.txt b/examples/cpp/text_categorizer/CMakeLists.txt index 85b2f38e3..360c04c7a 100644 --- a/examples/cpp/text_categorizer/CMakeLists.txt +++ b/examples/cpp/text_categorizer/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name text_categorizer_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}text_categorizer_example") set(source text_categorizer_example.cpp ) diff --git a/examples/cpp/train_ner/CMakeLists.txt b/examples/cpp/train_ner/CMakeLists.txt index 8f7373a58..f234d7a75 100644 --- a/examples/cpp/train_ner/CMakeLists.txt +++ b/examples/cpp/train_ner/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name train_ner_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_ner_example") set(source train_ner_example.cpp ) diff --git a/examples/cpp/train_relation_extraction/CMakeLists.txt b/examples/cpp/train_relation_extraction/CMakeLists.txt index 08c995d3d..3d4dea140 100644 --- a/examples/cpp/train_relation_extraction/CMakeLists.txt +++ b/examples/cpp/train_relation_extraction/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name train_relation_extraction_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_relation_extraction_example") set(source train_relation_extraction_example.cpp ) diff --git a/examples/cpp/train_text_categorizer/CMakeLists.txt b/examples/cpp/train_text_categorizer/CMakeLists.txt index 2ccd1a132..e3e3c32f5 100644 --- a/examples/cpp/train_text_categorizer/CMakeLists.txt +++ b/examples/cpp/train_text_categorizer/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name train_text_categorizer_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_text_categorizer_example") set(source train_text_categorizer_example.cpp ) diff --git a/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt b/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt index f52891a17..e687de938 100644 --- a/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt +++ b/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name train_text_categorizer_BoW_example) +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_text_categorizer_BoW_example") set(source train_text_categorizer_BoW_example.cpp ) diff --git a/mitielib/CMakeLists.txt b/mitielib/CMakeLists.txt index d0b05cba3..9f0a8a575 100644 --- a/mitielib/CMakeLists.txt +++ b/mitielib/CMakeLists.txt @@ -2,33 +2,18 @@ # This is a CMake makefile. You can find the cmake utility and # information about it at http://www.cmake.org # +cmake_minimum_required(VERSION 3.10) +project(mitie C CXX) -# setting this makes CMake allow normal looking if else statements -SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) -cmake_minimum_required(VERSION 2.4) - -# Suppress cmake warnings about changes in new versions. -if(COMMAND cmake_policy) - cmake_policy(SET CMP0003 NEW) -endif() - -set(CMAKE_POSITION_INDEPENDENT_CODE True) include(tell_visual_studio_to_use_static_runtime.cmake) + if (NOT TARGET mitie) if (NOT DEFINED BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS 1) + set(BUILD_SHARED_LIBS ON) endif() - set(DLIB_LINK_WITH_LIBPNG OFF CACHE STRING "not needed by MITIE" FORCE) - set(DLIB_LINK_WITH_LIBJPEG OFF CACHE STRING "not needed by MITIE" FORCE) - set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING "not needed by MITIE" FORCE) - - - include(../dlib/dlib/cmake) - include_directories(include) - set(source_files src/stemmer.cpp src/ner_feature_extraction.cpp @@ -45,7 +30,21 @@ if (NOT TARGET mitie) ) add_library(mitie ${source_files}) - target_link_libraries(mitie dlib) + set_target_properties(mitie PROPERTIES POSITION_INDEPENDENT_CODE ON) + target_compile_definitions(mitie PRIVATE MITIE_BUILD) + + if(BUILD_SHARED_LIBS) + target_compile_definitions(mitie PUBLIC MITIE_SHARED) + endif() + + target_include_directories(mitie PUBLIC include) + + if(MITIE_INTEGRATED_DLIB) + target_link_libraries(mitie dlib) + else() + find_package(dlib REQUIRED) + target_link_libraries(mitie dlib::dlib) + endif() # Determine the path to our CMakeLists.txt file. string(REGEX REPLACE "CMakeLists.txt$" "" base_path ${CMAKE_CURRENT_LIST_FILE}) diff --git a/tools/ner_conll/CMakeLists.txt b/tools/ner_conll/CMakeLists.txt index 96fd3139e..fb05aa622 100644 --- a/tools/ner_conll/CMakeLists.txt +++ b/tools/ner_conll/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name ner) +set(project_name "${MITIE_EXECUTABLES_PREFIX}ner") set(source src/main.cpp ) diff --git a/tools/ner_stream/CMakeLists.txt b/tools/ner_stream/CMakeLists.txt index 93b61130f..0e0ec2f2c 100644 --- a/tools/ner_stream/CMakeLists.txt +++ b/tools/ner_stream/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name ner_stream) +set(project_name "${MITIE_EXECUTABLES_PREFIX}ner_stream") set(source src/main.cpp ) diff --git a/tools/train_freebase_relation_detector/CMakeLists.txt b/tools/train_freebase_relation_detector/CMakeLists.txt index a08112fb2..9bb800e96 100644 --- a/tools/train_freebase_relation_detector/CMakeLists.txt +++ b/tools/train_freebase_relation_detector/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 2.6) -set(project_name train_relation_detector) +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_relation_detector") set(source src/main.cpp ) diff --git a/tools/wordrep/CMakeLists.txt b/tools/wordrep/CMakeLists.txt index 7a1a1cf49..a549d5989 100644 --- a/tools/wordrep/CMakeLists.txt +++ b/tools/wordrep/CMakeLists.txt @@ -3,12 +3,11 @@ # information about it at http://www.cmake.org # - cmake_minimum_required(VERSION 2.6) -set(project_name wordrep) +set(project_name "${MITIE_EXECUTABLES_PREFIX}wordrep") set(source src/main.cpp src/basic_morph.cpp @@ -24,7 +23,6 @@ include(../../mitielib/cmake) ADD_EXECUTABLE(${project_name} ${source}) -TARGET_LINK_LIBRARIES(${project_name} mitie ) - +TARGET_LINK_LIBRARIES(${project_name} mitie) From eaccf6e8c4e28258f0ece5306a48d2059dbecb69 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 5 Jan 2025 22:08:34 +1100 Subject: [PATCH 4/7] Configure CMake install directives for all targets: MITIE library and headers, C/C++ based tools and examples --- examples/C/ner/CMakeLists.txt | 4 +++- examples/C/relation_extraction/CMakeLists.txt | 4 +++- examples/cpp/ner/CMakeLists.txt | 4 +++- examples/cpp/relation_extraction/CMakeLists.txt | 4 +++- examples/cpp/text_categorizer/CMakeLists.txt | 4 +++- examples/cpp/train_ner/CMakeLists.txt | 4 +++- .../cpp/train_relation_extraction/CMakeLists.txt | 4 +++- examples/cpp/train_text_categorizer/CMakeLists.txt | 4 +++- .../cpp/train_text_categorizer_BoW/CMakeLists.txt | 4 +++- mitielib/CMakeLists.txt | 12 +++++++----- tools/ner_conll/CMakeLists.txt | 12 +++++++++++- tools/ner_stream/CMakeLists.txt | 4 +++- .../train_freebase_relation_detector/CMakeLists.txt | 5 +++-- tools/wordrep/CMakeLists.txt | 4 +++- 14 files changed, 54 insertions(+), 19 deletions(-) diff --git a/examples/C/ner/CMakeLists.txt b/examples/C/ner/CMakeLists.txt index 976ad3224..7e39bed77 100644 --- a/examples/C/ner/CMakeLists.txt +++ b/examples/C/ner/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/examples/C/relation_extraction/CMakeLists.txt b/examples/C/relation_extraction/CMakeLists.txt index d1764fee9..80c3dee55 100644 --- a/examples/C/relation_extraction/CMakeLists.txt +++ b/examples/C/relation_extraction/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/examples/cpp/ner/CMakeLists.txt b/examples/cpp/ner/CMakeLists.txt index 63154c8db..b6392bcb4 100644 --- a/examples/cpp/ner/CMakeLists.txt +++ b/examples/cpp/ner/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/examples/cpp/relation_extraction/CMakeLists.txt b/examples/cpp/relation_extraction/CMakeLists.txt index d0bebad60..c8b6332ee 100644 --- a/examples/cpp/relation_extraction/CMakeLists.txt +++ b/examples/cpp/relation_extraction/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/examples/cpp/text_categorizer/CMakeLists.txt b/examples/cpp/text_categorizer/CMakeLists.txt index 360c04c7a..b2e2c47f7 100644 --- a/examples/cpp/text_categorizer/CMakeLists.txt +++ b/examples/cpp/text_categorizer/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/examples/cpp/train_ner/CMakeLists.txt b/examples/cpp/train_ner/CMakeLists.txt index f234d7a75..7a9ea7843 100644 --- a/examples/cpp/train_ner/CMakeLists.txt +++ b/examples/cpp/train_ner/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/examples/cpp/train_relation_extraction/CMakeLists.txt b/examples/cpp/train_relation_extraction/CMakeLists.txt index 3d4dea140..ea8429488 100644 --- a/examples/cpp/train_relation_extraction/CMakeLists.txt +++ b/examples/cpp/train_relation_extraction/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/examples/cpp/train_text_categorizer/CMakeLists.txt b/examples/cpp/train_text_categorizer/CMakeLists.txt index e3e3c32f5..a2baafbba 100644 --- a/examples/cpp/train_text_categorizer/CMakeLists.txt +++ b/examples/cpp/train_text_categorizer/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt b/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt index e687de938..c59579136 100644 --- a/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt +++ b/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/mitielib/CMakeLists.txt b/mitielib/CMakeLists.txt index 9f0a8a575..7859c4a95 100644 --- a/mitielib/CMakeLists.txt +++ b/mitielib/CMakeLists.txt @@ -46,10 +46,12 @@ if (NOT TARGET mitie) target_link_libraries(mitie dlib::dlib) endif() - # Determine the path to our CMakeLists.txt file. - string(REGEX REPLACE "CMakeLists.txt$" "" base_path ${CMAKE_CURRENT_LIST_FILE}) - install(TARGETS mitie - DESTINATION ${base_path} - ) + + include(GNUInstallDirs) + install(TARGETS mitie) + install(DIRECTORY include/ + TYPE INCLUDE + FILES_MATCHING REGEX ".*\.h(pp)?$" + ) endif() diff --git a/tools/ner_conll/CMakeLists.txt b/tools/ner_conll/CMakeLists.txt index fb05aa622..3eebe9615 100644 --- a/tools/ner_conll/CMakeLists.txt +++ b/tools/ner_conll/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,13 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) +install(PROGRAMS "conlleval" + TYPE BIN + RENAME "${MITIE_EXECUTABLES_PREFIX}conlleval" + ) +install(PROGRAMS "train-ner" + TYPE BIN + RENAME "${MITIE_EXECUTABLES_PREFIX}train-ner" + ) diff --git a/tools/ner_stream/CMakeLists.txt b/tools/ner_stream/CMakeLists.txt index 0e0ec2f2c..cefc08887 100644 --- a/tools/ner_stream/CMakeLists.txt +++ b/tools/ner_stream/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,3 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/tools/train_freebase_relation_detector/CMakeLists.txt b/tools/train_freebase_relation_detector/CMakeLists.txt index 9bb800e96..b2ef9c129 100644 --- a/tools/train_freebase_relation_detector/CMakeLists.txt +++ b/tools/train_freebase_relation_detector/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -23,4 +23,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) - +include(GNUInstallDirs) +install(TARGETS ${project_name}) diff --git a/tools/wordrep/CMakeLists.txt b/tools/wordrep/CMakeLists.txt index a549d5989..946b66005 100644 --- a/tools/wordrep/CMakeLists.txt +++ b/tools/wordrep/CMakeLists.txt @@ -3,7 +3,7 @@ # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) @@ -26,3 +26,5 @@ ADD_EXECUTABLE(${project_name} ${source}) TARGET_LINK_LIBRARIES(${project_name} mitie) +include(GNUInstallDirs) +install(TARGETS ${project_name}) From 76e41d3ae909c1f733142d4cb39d8ef549fb5b9c Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 28 Mar 2025 18:28:48 +1100 Subject: [PATCH 5/7] Build process tweaks: separate build options for C and C++ examples, option to switch _example suffix on/off, error if system-installed dlib not found when MITIE_INTEGRATED_DLIB=OFF, omit lib prefix on Windows MinGW --- CMakeLists.txt | 18 +++++++++++++++--- examples/C/ner/CMakeLists.txt | 2 +- examples/C/relation_extraction/CMakeLists.txt | 2 +- examples/cpp/ner/CMakeLists.txt | 2 +- .../cpp/relation_extraction/CMakeLists.txt | 2 +- examples/cpp/text_categorizer/CMakeLists.txt | 2 +- examples/cpp/train_ner/CMakeLists.txt | 2 +- .../train_relation_extraction/CMakeLists.txt | 2 +- .../cpp/train_text_categorizer/CMakeLists.txt | 2 +- .../train_text_categorizer_BoW/CMakeLists.txt | 2 +- mitielib/CMakeLists.txt | 10 ++++++++++ tools/ner_conll/CMakeLists.txt | 10 +++++----- tools/ner_conll/train-ner | 8 ++++---- 13 files changed, 43 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c79234e33..f4c43c7fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,14 @@ cmake_minimum_required(VERSION 3.10) project(mitie_project) +option(BUILD_SHARED_LIBS "mitie: build shared libraries" ON) option(MITIE_INTEGRATED_DLIB "mitie: build and statically link integrated dlib as shipped with MITIE codebase (otherwise look for system dlib)" ON) option(MITIE_INTEGRATED_DLIB_DISABLE_OPT_COMPONENTS "mitie: disable optional components not required for MITIE when building integrated dlib (image libraries, FFmpeg, SQLite3)" ON) option(MITIE_BUILD_TOOLS "mitie: build tools" ON) -option(MITIE_BUILD_EXAMPLES "mitie: build examples" ON) +option(MITIE_BUILD_C_EXAMPLES "mitie: build C examples" ON) +option(MITIE_BUILD_CPP_EXAMPLES "mitie: build C++ examples" ON) option(MITIE_APPLY_EXECUTABLES_PREFIX "mitie: add 'mitie-' prefix to executables" OFF) +option(MITIE_APPLY_EXAMPLES_SUFFIX "mitie: add '_example' suffix to executables for C and C++ examples" ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -18,6 +21,12 @@ else() set(MITIE_EXECUTABLES_PREFIX "") endif() +if(MITIE_APPLY_EXAMPLES_SUFFIX) + set(MITIE_EXAMPLES_SUFFIX "_example") +else() + set(MITIE_EXAMPLES_SUFFIX "") +endif() + # Build integrated dlib if requested if(MITIE_INTEGRATED_DLIB) @@ -46,10 +55,13 @@ if(MITIE_BUILD_TOOLS) add_subdirectory(tools/wordrep) endif() -# MITIE examples (C and C++) -if(MITIE_BUILD_EXAMPLES) +# MITIE examples +if(MITIE_BUILD_C_EXAMPLES) add_subdirectory(examples/C/ner) add_subdirectory(examples/C/relation_extraction) +endif() + +if(MITIE_BUILD_CPP_EXAMPLES) add_subdirectory(examples/cpp/ner) add_subdirectory(examples/cpp/relation_extraction) add_subdirectory(examples/cpp/text_categorizer) diff --git a/examples/C/ner/CMakeLists.txt b/examples/C/ner/CMakeLists.txt index 7e39bed77..b10da20b7 100644 --- a/examples/C/ner/CMakeLists.txt +++ b/examples/C/ner/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}ner_c_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}ner_c${MITIE_EXAMPLES_SUFFIX}") set(source ner_example.c ) diff --git a/examples/C/relation_extraction/CMakeLists.txt b/examples/C/relation_extraction/CMakeLists.txt index 80c3dee55..f47c663eb 100644 --- a/examples/C/relation_extraction/CMakeLists.txt +++ b/examples/C/relation_extraction/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}relation_extraction_c_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}relation_extraction_c${MITIE_EXAMPLES_SUFFIX}") set(source relation_extraction_example.c ) diff --git a/examples/cpp/ner/CMakeLists.txt b/examples/cpp/ner/CMakeLists.txt index b6392bcb4..dd165715a 100644 --- a/examples/cpp/ner/CMakeLists.txt +++ b/examples/cpp/ner/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}ner_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}ner${MITIE_EXAMPLES_SUFFIX}") set(source ner_example.cpp ) diff --git a/examples/cpp/relation_extraction/CMakeLists.txt b/examples/cpp/relation_extraction/CMakeLists.txt index c8b6332ee..c111d47b5 100644 --- a/examples/cpp/relation_extraction/CMakeLists.txt +++ b/examples/cpp/relation_extraction/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}relation_extraction_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}relation_extraction${MITIE_EXAMPLES_SUFFIX}") set(source relation_extraction_example.cpp ) diff --git a/examples/cpp/text_categorizer/CMakeLists.txt b/examples/cpp/text_categorizer/CMakeLists.txt index b2e2c47f7..4ffa01d43 100644 --- a/examples/cpp/text_categorizer/CMakeLists.txt +++ b/examples/cpp/text_categorizer/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}text_categorizer_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}text_categorizer${MITIE_EXAMPLES_SUFFIX}") set(source text_categorizer_example.cpp ) diff --git a/examples/cpp/train_ner/CMakeLists.txt b/examples/cpp/train_ner/CMakeLists.txt index 7a9ea7843..4123acdcd 100644 --- a/examples/cpp/train_ner/CMakeLists.txt +++ b/examples/cpp/train_ner/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}train_ner_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_ner${MITIE_EXAMPLES_SUFFIX}") set(source train_ner_example.cpp ) diff --git a/examples/cpp/train_relation_extraction/CMakeLists.txt b/examples/cpp/train_relation_extraction/CMakeLists.txt index ea8429488..7672944e9 100644 --- a/examples/cpp/train_relation_extraction/CMakeLists.txt +++ b/examples/cpp/train_relation_extraction/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}train_relation_extraction_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_relation_extraction${MITIE_EXAMPLES_SUFFIX}") set(source train_relation_extraction_example.cpp ) diff --git a/examples/cpp/train_text_categorizer/CMakeLists.txt b/examples/cpp/train_text_categorizer/CMakeLists.txt index a2baafbba..80f849b7b 100644 --- a/examples/cpp/train_text_categorizer/CMakeLists.txt +++ b/examples/cpp/train_text_categorizer/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}train_text_categorizer_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_text_categorizer${MITIE_EXAMPLES_SUFFIX}") set(source train_text_categorizer_example.cpp ) diff --git a/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt b/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt index c59579136..622121c53 100644 --- a/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt +++ b/examples/cpp/train_text_categorizer_BoW/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}train_text_categorizer_BoW_example") +set(project_name "${MITIE_EXECUTABLES_PREFIX}train_text_categorizer_BoW${MITIE_EXAMPLES_SUFFIX}") set(source train_text_categorizer_BoW_example.cpp ) diff --git a/mitielib/CMakeLists.txt b/mitielib/CMakeLists.txt index 7859c4a95..98055815b 100644 --- a/mitielib/CMakeLists.txt +++ b/mitielib/CMakeLists.txt @@ -43,9 +43,19 @@ if (NOT TARGET mitie) target_link_libraries(mitie dlib) else() find_package(dlib REQUIRED) + if (NOT dlib_FOUND) + message(FATAL_ERROR "System-installed dlib not found.") + endif() target_link_libraries(mitie dlib::dlib) endif() + # Omit lib prefix on Windows MinGW + if (WIN32) + set(CMAKE_STATIC_LIBRARY_PREFIX "") + set(CMAKE_SHARED_LIBRARY_PREFIX "") + set(CMAKE_SHARED_MODULE_PREFIX "") + endif() + include(GNUInstallDirs) install(TARGETS mitie) diff --git a/tools/ner_conll/CMakeLists.txt b/tools/ner_conll/CMakeLists.txt index 3eebe9615..db72e9725 100644 --- a/tools/ner_conll/CMakeLists.txt +++ b/tools/ner_conll/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) -set(project_name "${MITIE_EXECUTABLES_PREFIX}ner") +set(project_name "${MITIE_EXECUTABLES_PREFIX}ner_conll") set(source src/main.cpp ) @@ -29,7 +29,7 @@ install(PROGRAMS "conlleval" TYPE BIN RENAME "${MITIE_EXECUTABLES_PREFIX}conlleval" ) -install(PROGRAMS "train-ner" - TYPE BIN - RENAME "${MITIE_EXECUTABLES_PREFIX}train-ner" - ) +#install(PROGRAMS "train-ner" +# TYPE BIN +# RENAME "${MITIE_EXECUTABLES_PREFIX}train-ner" +# ) diff --git a/tools/ner_conll/train-ner b/tools/ner_conll/train-ner index 64e10407f..c36eb277b 100755 --- a/tools/ner_conll/train-ner +++ b/tools/ner_conll/train-ner @@ -7,11 +7,11 @@ run_default_params() { THREADS="--threads=16" LOG=test_default.txt - ./ner --train-chunker eng.train_all_some_sentences_combined $THREADS > $LOG - ./ner --train-id eng.train_all_some_sentences_combined $THREADS >> $LOG + ./ner_conll --train-chunker eng.train_all_some_sentences_combined $THREADS > $LOG + ./ner_conll --train-id eng.train_all_some_sentences_combined $THREADS >> $LOG - ./ner --test-id eng.testb >> $LOG - ./ner --tag-conll-file ner_model.dat eng.testb | ./conlleval + ./ner_conll --test-id eng.testb >> $LOG + ./ner_conll --tag-conll-file ner_model.dat eng.testb | ./conlleval echo $LOG tail -n1 $LOG } From 4abbff949f01a44efe6ddb9acae2c23692da24e4 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 28 Mar 2025 19:40:14 +1100 Subject: [PATCH 6/7] merge_changes_from_dlib : add latest version tag detection logic --- merge_changes_from_dlib | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/merge_changes_from_dlib b/merge_changes_from_dlib index eff178054..71965c355 100755 --- a/merge_changes_from_dlib +++ b/merge_changes_from_dlib @@ -1 +1,9 @@ -git subtree pull --prefix dlib https://github.com/davisking/dlib.git master --squash +#!/bin/sh + +DLIB_LATEST_TAG=$(git ls-remote --tags https://github.com/davisking/dlib.git | \ + awk '/refs\/tags\/v/ {print $2}' | \ + sed 's|refs/tags/||' | \ + sort -V | \ + tail -n 1) + +git subtree pull --prefix dlib https://github.com/davisking/dlib.git $DLIB_LATEST_TAG --squash From 13ed622950e2c191ace4c20ae91610fa2855eb3b Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Mar 2025 15:29:02 +1100 Subject: [PATCH 7/7] Add pkg-config and CMake package support for MITIE Add directives for mitie.pc, mitie-config.cmake and mitie-version.cmake metadata generation and install rules for package discovery --- mitielib/CMakeLists.txt | 37 ++++++++++++++++++++++++++++++++-- mitielib/mitie-config.cmake.in | 16 +++++++++++++++ mitielib/mitie.pc.in | 11 ++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 mitielib/mitie-config.cmake.in create mode 100644 mitielib/mitie.pc.in diff --git a/mitielib/CMakeLists.txt b/mitielib/CMakeLists.txt index 98055815b..c395ade47 100644 --- a/mitielib/CMakeLists.txt +++ b/mitielib/CMakeLists.txt @@ -2,8 +2,8 @@ # This is a CMake makefile. You can find the cmake utility and # information about it at http://www.cmake.org # -cmake_minimum_required(VERSION 3.10) -project(mitie C CXX) +cmake_minimum_required(VERSION 3.12) +project(mitie VERSION 0.7 LANGUAGES C CXX) include(tell_visual_studio_to_use_static_runtime.cmake) @@ -64,4 +64,37 @@ if (NOT TARGET mitie) FILES_MATCHING REGEX ".*\.h(pp)?$" ) + + include(CMakePackageConfigHelpers) + + # + # Generate metadata for pkg-config + # + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mitie.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/mitie.pc" + @ONLY) + + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mitie.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + + # + # Generate metadata for CMake package + # + configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/mitie-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/mitie-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mitie + ) + + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/mitie-version.cmake + VERSION ${MITIE_VERSION} + COMPATIBILITY SameMajorVersion + ) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mitie-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/mitie-version.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mitie + ) + endif() diff --git a/mitielib/mitie-config.cmake.in b/mitielib/mitie-config.cmake.in new file mode 100644 index 000000000..57b2b89e2 --- /dev/null +++ b/mitielib/mitie-config.cmake.in @@ -0,0 +1,16 @@ +set(MITIE_SHARED_LIB @BUILD_SHARED_LIBS@) + +@PACKAGE_INIT@ + +find_package(dlib REQUIRED) + +find_library(mitie_LIBRARY mitie REQUIRED) + +add_library(mitie::mitie UNKNOWN IMPORTED) +set_target_properties(mitie::mitie + PROPERTIES + IMPORTED_LOCATION "${mitie_LIBRARY}" + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + INTERFACE_LINK_LIBRARIES "dlib::dlib" + POSITION_INDEPENDENT_CODE ON +) diff --git a/mitielib/mitie.pc.in b/mitielib/mitie.pc.in new file mode 100644 index 000000000..693ba64de --- /dev/null +++ b/mitielib/mitie.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ + +Name: mitie +Description: MIT Information Extraction Library +Version: @PROJECT_VERSION@ +Requires: dlib-1 +Cflags: -I${includedir} +Libs: -L${libdir} -lmitie