nlp.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2021 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "platform.h"
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <ctype.h>
  17. #include <assert.h>
  18. #include "eclrtl.hpp"
  19. #include "nlp.hpp"
  20. #define NLP_VERSION "nlp plugin 1.0.0"
  21. ECL_NLP_API bool getECLPluginDefinition(ECLPluginDefinitionBlock *pb)
  22. {
  23. if (pb->size != sizeof(ECLPluginDefinitionBlock))
  24. return false;
  25. pb->magicVersion = PLUGIN_VERSION;
  26. pb->version = NLP_VERSION;
  27. pb->moduleName = "lib_nlp";
  28. pb->ECL = NULL;
  29. pb->flags = PLUGIN_IMPLICIT_MODULE;
  30. pb->description = "ECL plugin library for nlp\n";
  31. return true;
  32. }
  33. #include <fstream>
  34. namespace nlp {
  35. IPluginContext * parentCtx = NULL;
  36. static CriticalSection cs;
  37. static NLPEng *nlpEng = NULL;
  38. ECL_NLP_API void setPluginContext(IPluginContext * _ctx) { parentCtx = _ctx; }
  39. //--------------------------------------------------------------------------------
  40. // ECL SERVICE ENTRYPOINTS
  41. //--------------------------------------------------------------------------------
  42. ECL_NLP_API void ECL_NLP_CALL AnalyzeText(size32_t & tgtLen, char * & tgt, size32_t anaLen, const char * ana, size32_t txtLen, const char * txt)
  43. {
  44. {
  45. CriticalBlock block(cs);
  46. if (nlpEng == NULL) {
  47. nlpEng = new NLPEng();
  48. }
  49. }
  50. StringBuffer txtBuff(txtLen,txt);
  51. ostringstream sso;
  52. tgtLen = nlpEng->nlpEngAnalyze(ana,txtBuff,sso);
  53. tgt = (char *) CTXMALLOC(parentCtx, tgtLen);
  54. memcpy_iflen(tgt, sso.str().c_str(), tgtLen);
  55. }
  56. } // namespace nlp