ExpressionClassifyEngine.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "ExpressionClassifyEngine.h"
  4. #include "ExpressionParseEngine/LogicExp.h"
  5. #include "XMLSerialization.h"
  6. #include <map>
  7. #include <Element.h>
  8. #include "OTSSTDLibFileMgr.h"
  9. #include "COTSUtilityDllFunExport.h"
  10. namespace OTSClassifyEngine
  11. {
  12. using namespace expInterpreter;
  13. bool ExpressionClassifyEngine::Init()
  14. {
  15. CSTDLibFileMgrPtr pLibFileMgr = CSTDLibFileMgrPtr(new CSTDLibFileMgr(m_StrName));
  16. m_std = ParticleSTDPtr(new ParticleSTD());
  17. if (!pLibFileMgr->LoadPartSTD(m_std))
  18. {
  19. return FALSE;
  20. }
  21. pLibFileMgr->LoadMaxEDSRulesData(m_std);
  22. pLibFileMgr->LoadZeroElementRulesData(m_std);
  23. string constantStr = pLibFileMgr->LoadConstantsData();
  24. std::map<std::string, double> m_mapConstants;
  25. m_mapConstants.clear();
  26. std::vector<std::string> strs;
  27. xmls::SplitString(constantStr, strs, ",");
  28. for (std::string s : strs)
  29. {
  30. std::vector<std::string> oneExp;
  31. xmls::SplitString(s, oneExp, "=");
  32. m_mapConstants[oneExp[0]] = std::atof(oneExp[1].c_str());
  33. }
  34. m_std->setConstantsMap(m_mapConstants);
  35. return true;
  36. }
  37. bool ExpressionClassifyEngine::ClassifyExpression(COTSParticlePtr particle, CPosXrayPtr xray)
  38. {
  39. if (particle != nullptr && xray != nullptr)//process the particle with the xray data
  40. {
  41. auto& originalPartEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
  42. //zero element process,if satisfied the condition than set the particular element percentage to 0.and make it 100% of all the element percentage.
  43. auto partEles = ZeroElementProcess(particle, xray);//
  44. std::map<std::string, CElementChemistryPtr> mapChemistrys;
  45. for (auto ch : partEles)
  46. {
  47. mapChemistrys[ch->GetName().GetBuffer()] = ch;
  48. }
  49. PartSTDRuleItemList ruleItems = m_std->GetSTDRuleItems();
  50. for (auto itm : ruleItems)
  51. {
  52. //if the element quantity is not match the std item's keyelement num than they are unmatching.
  53. if (partEles.size() < itm->GetKeyElementList().size())
  54. {
  55. continue;
  56. }
  57. auto& mapStdEles = itm->GetMapElements();
  58. bool bMatch = true;
  59. // if the particle does not contain all the key elements of the item than they are unmatching.
  60. for (auto che : mapStdEles)
  61. {
  62. auto chemical = mapChemistrys.find(che.second->GetName().GetBuffer());
  63. if (chemical == mapChemistrys.end())
  64. {
  65. bMatch = false;
  66. break;
  67. }
  68. }
  69. if (!bMatch) continue;
  70. std::string exp = itm->GetExpressionStr();
  71. ProcessAllPropertiesWithParticleData(exp, mapChemistrys, itm, particle);
  72. //calculate the expression which has been processed.
  73. bool rst = CalcuExp(exp);
  74. if (rst)
  75. {
  76. particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
  77. particle->SetClassifyId(itm->GetID());
  78. particle->SetColor(itm->GetColor());
  79. particle->SetClassifyName(itm->GetName());
  80. particle->SetHardness(itm->GetHardness());
  81. particle->SetDensity(itm->GetDensity());
  82. particle->SetConductivity(itm->GetElectrical_conductivity());
  83. particle->SetGroupId(itm->GetGrpID());
  84. particle->SetGroupColor(itm->GetGrpColor());
  85. particle->SetGroupName(itm->GetGrpName());
  86. //if this item is a spectrum compared item then we should memory these spectrum to be used when doing spectrum compare.
  87. if (itm->GetIsElementAnalysis() == false)
  88. {
  89. itm->AddXraySpectrum(particle->GetXrayInfo());
  90. }
  91. return true;
  92. }
  93. else
  94. {
  95. continue;
  96. }
  97. }
  98. particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
  99. particle->SetClassifyName("Not Identified");
  100. particle->SetColor("#000000");
  101. particle->SetGroupId((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED);
  102. particle->SetGroupName("Not Identified");
  103. particle->SetGroupColor("#000000");
  104. return true;
  105. }
  106. else if(particle != nullptr && xray == nullptr)//process particle without xray data
  107. {
  108. PartSTDRuleItemList stdItems = m_std->GetSTDRuleItems();
  109. for (auto itm : stdItems)
  110. {
  111. std::string exp = itm->GetExpressionStr();
  112. //if the rule demand any element infomation then they won't match.
  113. if (itm->GetKeyElementList().size() > 0 || itm->GetSubElementList().size() > 0)
  114. {
  115. continue;
  116. }
  117. ProcessImgPropertiesWithParticleData(exp, itm, particle);
  118. //calculate the expression which has been processed.
  119. bool rst = CalcuExp(exp);
  120. if (rst)
  121. {
  122. //int id = itm->GetID();
  123. particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
  124. particle->SetClassifyId(itm->GetID());
  125. particle->SetColor(itm->GetColor());
  126. particle->SetClassifyName(itm->GetName());
  127. particle->SetHardness(itm->GetHardness());
  128. particle->SetDensity(itm->GetDensity());
  129. particle->SetConductivity(itm->GetElectrical_conductivity());
  130. particle->SetGroupId(itm->GetGrpID());
  131. particle->SetGroupColor(itm->GetGrpColor());
  132. particle->SetGroupName(itm->GetGrpName());
  133. return true;
  134. }
  135. else
  136. {
  137. continue;
  138. }
  139. }
  140. particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
  141. particle->SetClassifyName("Not Identified");
  142. particle->SetColor("#000000");
  143. particle->SetGroupId((int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
  144. particle->SetGroupColor("#000000");
  145. particle->SetGroupName("Not Identified");
  146. return true;
  147. }
  148. }
  149. bool ExpressionClassifyEngine::IfNeedMaxEDS(COTSParticlePtr particle, CPosXrayPtr xray, double& MaxEDSTime)
  150. {
  151. if (particle == nullptr || xray == nullptr) return false;
  152. MaxEDSRuleList Rules = m_std->GetMaxEDSRules();
  153. for (auto rule : Rules)
  154. {
  155. std::string exp = rule->m_expressionStr;
  156. auto& partEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
  157. if (partEles.size() < rule->m_elementList.size())
  158. {
  159. continue;// if the size not match then continue.
  160. }
  161. std::map<CString, CElementChemistryPtr> mapChe;
  162. for (auto ch : partEles)
  163. {
  164. mapChe[ch->GetName()] = ch;
  165. }
  166. auto& usingEles = rule->m_elementList;
  167. bool bMatch=true;
  168. for (auto che : usingEles)
  169. {
  170. auto chemical = mapChe.find(che->GetName());
  171. if (chemical == mapChe.end())
  172. {
  173. bMatch = false;
  174. break;
  175. }
  176. }
  177. if (!bMatch) continue;//if cann't find the element in the particle's element,then continue.
  178. // all the rule's using element are contained in the particle then we replace the element with the percentage value
  179. for (std::string s : rule->m_OtherpropertyList)
  180. {
  181. if (s.find("_elem")!=std::string::npos)
  182. {
  183. auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
  184. xmls::ReplaceAll(exp, s, std::to_string(val));
  185. }
  186. if (s.find("Element#")!=std::string::npos)
  187. {
  188. auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
  189. auto& elelist = rule->m_elementList;
  190. elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
  191. xmls::ReplaceAll(exp, s, val.GetBuffer());
  192. }
  193. }
  194. for (auto eleChemistry : rule->m_elementList)
  195. {
  196. auto e = mapChe[eleChemistry->GetName()];
  197. std::string name = eleChemistry->GetName();
  198. xmls::ReplaceAll(exp, name, std::to_string(e->GetPercentage()));
  199. }
  200. for (std::string s : rule->m_ImgPropertyList)
  201. {
  202. auto val = particle->GetImgPropertyValueByName(s.c_str());
  203. xmls::ReplaceAll(exp, s, std::to_string(val));
  204. }
  205. bool rst = CalcuExp(exp);
  206. if (rst)
  207. {
  208. MaxEDSTime = rule->m_MaxEDSTime;
  209. return true;
  210. }
  211. else
  212. {
  213. continue;
  214. }
  215. }
  216. MaxEDSTime = 0;
  217. return false;
  218. }
  219. CString ExpressionClassifyEngine::GetEleNameBySortingPercentage(CString sortingNostr, CPosXrayPtr xrayInfo)
  220. {
  221. std::map<double, CElementChemistryPtr> mapPercent;
  222. std::map<int, CElementChemistryPtr> mapSorted;
  223. auto eles = xrayInfo->GetElementQuantifyData();
  224. for (auto e : eles)
  225. {
  226. mapPercent[e->GetPercentage()] = e;
  227. }
  228. auto itr = --mapPercent.end();
  229. for (int i=0;itr != mapPercent.begin();)
  230. {
  231. mapSorted.insert(std::pair<int, CElementChemistryPtr>(i, itr->second));
  232. itr--;
  233. i++;
  234. }
  235. std::string NoStr = sortingNostr;
  236. std::vector<string> strs;
  237. xmls::SplitString(NoStr, strs, "#");
  238. int No = std::stoi(strs[1]);
  239. if (mapSorted.size() > No)
  240. {
  241. return mapSorted[No]->GetName();
  242. }
  243. else
  244. {
  245. return _T("");
  246. }
  247. }
  248. double ExpressionClassifyEngine::GetMacValue(CString MacStr)
  249. {
  250. auto mapconstant = m_std->GetMapConstants();
  251. if (mapconstant.find(MacStr.GetBuffer()) != mapconstant.end())
  252. {
  253. return mapconstant[MacStr.GetBuffer()];
  254. }
  255. else
  256. {
  257. return 0.0;
  258. }
  259. }
  260. int ExpressionClassifyEngine::GetAtomicNoBySortingPercentage(CString sortingNostr, CPosXrayPtr xrayInfo)
  261. {
  262. std::map<double, CElementChemistryPtr> mapPercent;
  263. std::map<int, CElementChemistryPtr> mapSorted;
  264. auto eles = xrayInfo->GetElementQuantifyData();
  265. if (eles.size() == 0)
  266. {
  267. return 0;
  268. }
  269. for (auto e : eles)
  270. {
  271. mapPercent[e->GetPercentage()] = e;
  272. }
  273. auto itr = --mapPercent.end();
  274. for (int i = 0; itr != mapPercent.begin(); )
  275. {
  276. mapSorted.insert(std::pair<int, CElementChemistryPtr>(i, itr->second));
  277. itr--;
  278. i++;
  279. }
  280. std::string NoStr = sortingNostr;
  281. int No=10;
  282. if (sortingNostr == "first_elem") No = 0;
  283. if (sortingNostr == "second_elem") No = 1;
  284. if (sortingNostr == "third_elem") No = 2;
  285. if (sortingNostr == "fourth_elem") No = 3;
  286. if (sortingNostr == "fifth_elem") No = 4;
  287. if (sortingNostr == "sixth_elem") No = 5;
  288. if (sortingNostr == "seventh_elem") No =6;
  289. if (sortingNostr == "eighth_elem") No = 7;
  290. if (sortingNostr == "ninth_elem") No = 8;
  291. if (sortingNostr == "tenth_elem") No =9;
  292. if (mapSorted.size() > No)
  293. {
  294. std::string elename = mapSorted[No]->GetName();
  295. CElementPtr ele = CElementPtr(new CElement(elename.c_str()));
  296. return ele->GetAtomNum();
  297. }
  298. else
  299. {
  300. return 0;
  301. }
  302. }
  303. CElementChemistriesList ExpressionClassifyEngine::ZeroElementProcess(COTSParticlePtr particle, CPosXrayPtr xray)
  304. {
  305. auto& originalPartEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
  306. CElementChemistriesList partEles;
  307. for (auto che : originalPartEles)
  308. {
  309. auto newChe = CElementChemistryPtr(new CElementChemistry(che.get()));
  310. partEles.push_back(newChe);
  311. }
  312. //make it 100% in total.(so called the "Normalization")
  313. double rawPercentage = 0;
  314. for (auto ele : partEles)
  315. {
  316. rawPercentage += ele->GetPercentage();
  317. }
  318. for (auto ele : partEles)
  319. {
  320. ele->SetPercentage(ele->GetPercentage() / rawPercentage * 100);
  321. }
  322. //zero element process
  323. std::map<CString, CElementChemistryPtr> mapChe;
  324. for (auto ch : partEles)
  325. {
  326. mapChe[ch->GetName()] = ch;
  327. }
  328. ZeroElementRuleList Rules = m_std->GetZeroRules();
  329. for (auto rule : Rules)
  330. {
  331. std::string exp = rule->GetExpressionStr();
  332. if (partEles.size() < rule->GetUsingElementList().size())
  333. {
  334. continue;// if the size not match then continue.
  335. }
  336. auto& usingEles = rule->GetUsingElementList();
  337. bool bMatch = true;
  338. for (auto che : usingEles)
  339. {
  340. auto chemical = mapChe.find(che->GetName());
  341. if (chemical == mapChe.end())
  342. {
  343. bMatch = false;
  344. break;//if cann't find the element in the particle's element,then continue.
  345. }
  346. }
  347. if (bMatch == false) continue;
  348. // all the rule's using element are contained in the particle then we replace the element with the percentage value
  349. for (std::string s : rule->GetOtherpropertyList())
  350. {
  351. if (s.find("_elem")!=std::string::npos)
  352. {
  353. auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
  354. xmls::ReplaceAll(exp, s, std::to_string(val));
  355. }
  356. if (s.find("Element#")!=std::string::npos)
  357. {
  358. auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
  359. auto elelist = rule->GetUsingElementList();
  360. elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
  361. rule->SetUsingElementList(elelist);
  362. xmls::ReplaceAll(exp, s, val.GetBuffer());
  363. }
  364. }
  365. for (auto eleChemistry : rule->GetUsingElementList())
  366. {
  367. auto e = mapChe.find(eleChemistry->GetName());
  368. if (e != mapChe.end())
  369. {
  370. std::string name = eleChemistry->GetName();
  371. xmls::ReplaceAll(exp, name, std::to_string((*e).second->GetPercentage()));
  372. }
  373. }
  374. for (std::string s : rule->GetImgPropertyList())
  375. {
  376. auto val = particle->GetImgPropertyValueByName(s.c_str());
  377. xmls::ReplaceAll(exp, s, std::to_string(val));
  378. }
  379. for (int i = 0; i < 10; i++)
  380. {
  381. std::string macStr = "MAC#" + std::to_string(i);
  382. if (exp.find(macStr) != std::string::npos)
  383. {
  384. auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
  385. xmls::ReplaceAll(exp, macStr, std::to_string(val));
  386. }
  387. }
  388. bool rst = CalcuExp(exp);
  389. if (rst)
  390. {
  391. auto itr = std::find_if(partEles.begin(), partEles.end(), [rule](CElementChemistryPtr ele) {return ele->GetName() == CString(rule->GetZeroElementName().c_str()); });
  392. if (itr != partEles.end())
  393. {
  394. //partEles.erase(itr);//if satisfied the condition then erase the element(zero the element).
  395. (*itr)->SetPercentage(0);//if satisfied the condition then set element percentage to 0(zero the element).
  396. double sumPercentage=0;
  397. for (auto ele : partEles)
  398. {
  399. sumPercentage += ele->GetPercentage();
  400. }
  401. for (auto ele : partEles)
  402. {
  403. if (sumPercentage != 0)
  404. {
  405. ele->SetPercentage(ele->GetPercentage() / sumPercentage * 100);
  406. }
  407. }
  408. }
  409. }
  410. else
  411. {
  412. continue;
  413. }
  414. }
  415. return partEles;
  416. }
  417. void ExpressionClassifyEngine::ProcessAllPropertiesWithParticleData(std::string& exp,
  418. std::map<std::string, CElementChemistryPtr>& mapChemistrys,
  419. PartSTDRuleItemPtr itm,
  420. COTSParticlePtr particle
  421. )
  422. {
  423. // process the special property name such as "first_elem" and "Element#1" etc.
  424. auto xray = particle->GetXrayInfo();
  425. for (std::string s : itm->GetUsingOtherpropertyList())
  426. {
  427. if (s.find("_elem") != std::string::npos)
  428. {
  429. auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
  430. xmls::ReplaceAll(exp, s, std::to_string(val));
  431. }
  432. if (s.find("Element#") != std::string::npos)
  433. {
  434. auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
  435. auto elelist = itm->GetKeyElementList();
  436. elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
  437. itm->SetKeyElementList(elelist);
  438. xmls::ReplaceAll(exp, s, val.GetBuffer());
  439. }
  440. }
  441. //process the element property
  442. for (auto eleChemistry : itm->GetAllSortedEleList())
  443. {
  444. auto e = mapChemistrys.find(eleChemistry->GetName().GetBuffer());
  445. if (e != mapChemistrys.end())
  446. {
  447. std::string name = eleChemistry->GetName();
  448. xmls::ReplaceAll(exp, name, std::to_string(e->second->GetPercentage()));
  449. }
  450. else
  451. {
  452. std::string name = eleChemistry->GetName();
  453. xmls::ReplaceAll(exp, name, "0");
  454. }
  455. }
  456. //process the image property
  457. for (std::string s : itm->GetUsingImgPropertyNameList())
  458. {
  459. auto val = particle->GetImgPropertyValueByName(s.c_str());
  460. xmls::ReplaceAll(exp, s, std::to_string(val));
  461. }
  462. //process the "true" keyword.
  463. if (exp.find("true") != std::string::npos)
  464. {
  465. xmls::ReplaceAll(exp, "true", "(1=1)");
  466. }
  467. //process the "false" keyword.
  468. if (exp.find("false") != std::string::npos)
  469. {
  470. xmls::ReplaceAll(exp, "false", "(1=0)");
  471. }
  472. //process the contant value
  473. for (int i = 0; i < 10; i++)
  474. {
  475. std::string macStr = "MAC#" + std::to_string(i);
  476. if (exp.find(macStr) != std::string::npos)
  477. {
  478. auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
  479. xmls::ReplaceAll(exp, macStr, std::to_string(val));
  480. }
  481. }
  482. }
  483. void ExpressionClassifyEngine::ProcessImgPropertiesWithParticleData(std::string& exp, PartSTDRuleItemPtr itm, COTSParticlePtr particle)
  484. {
  485. //process the image property
  486. for (std::string s : itm->GetUsingImgPropertyNameList())
  487. {
  488. auto val = particle->GetImgPropertyValueByName(s.c_str());
  489. xmls::ReplaceAll(exp, s, std::to_string(val));
  490. }
  491. //process the "true" keyword.
  492. if (exp.find("true") != std::string::npos)
  493. {
  494. xmls::ReplaceAll(exp, "true", "(1=1)");
  495. }
  496. //process the "false" keyword.
  497. if (exp.find("false") != std::string::npos)
  498. {
  499. xmls::ReplaceAll(exp, "false", "(1=0)");
  500. }
  501. //process the constant value
  502. for (int i = 0; i < 10; i++)
  503. {
  504. std::string macStr = "MAC#" + std::to_string(i);
  505. if (exp.find(macStr) != std::string::npos)
  506. {
  507. auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
  508. xmls::ReplaceAll(exp, macStr, std::to_string(val));
  509. }
  510. }
  511. }
  512. bool ExpressionClassifyEngine::ZeroElementProcess(COTSParticlePtr particle)
  513. {
  514. auto chems = ZeroElementProcess(particle, particle->GetXrayInfo());
  515. particle->GetXrayInfo()->SetElementQuantifyData(chems);
  516. return true;
  517. }
  518. bool ExpressionClassifyEngine::ClassifyBySpectrum(COTSParticlePtr particle, CPosXrayPtr xray)
  519. {
  520. return false;
  521. }
  522. bool ExpressionClassifyEngine::ClassifyByExpressionTemporarySpectrum(COTSParticlePtr particle, CPosXrayPtr xray)
  523. {
  524. PartSTDRuleItemList ruleItems = m_std->GetSTDRuleItems();
  525. for (auto itm : ruleItems)
  526. {
  527. if (itm->GetIsElementAnalysis() == false)
  528. {
  529. auto sim = itm->CalculateSimilarity(xray);
  530. if (sim > 0.90)
  531. {
  532. particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
  533. particle->SetClassifyId(itm->GetID());
  534. particle->SetColor(itm->GetColor());
  535. particle->SetClassifyName(itm->GetName());
  536. particle->SetHardness(itm->GetHardness());
  537. particle->SetDensity(itm->GetDensity());
  538. particle->SetConductivity(itm->GetElectrical_conductivity());
  539. particle->SetGroupId(itm->GetGrpID());
  540. particle->SetGroupColor(itm->GetGrpColor());
  541. particle->SetGroupName(itm->GetGrpName());
  542. break;
  543. }
  544. }
  545. }
  546. return true;
  547. }
  548. bool ExpressionClassifyEngine::ClassifyIncA(COTSParticlePtr particle, int SteelTech, CPosXrayPtr xray)
  549. {
  550. return false;
  551. }
  552. OTSClassifyEngine::CLEEnginePtr GetParticleEngine(std::string a_libName)
  553. {
  554. static CLEEnginePtr engine;
  555. static std::string libName="";
  556. if (engine == NULL || libName != a_libName)
  557. {
  558. engine = CLEEnginePtr(new ExpressionClassifyEngine(a_libName));
  559. libName = a_libName;
  560. if (!engine->Init())
  561. {
  562. return NULL;
  563. }
  564. }
  565. return engine;
  566. }
  567. }