36namespace Desagglutination
48 string resourcesPath=MediaticData::single().getResourcesPath();
52 loadMicroCategoriesMappingFromFile(file.toUtf8().constData());
56 LERROR <<
"no param 'categoriesMappingFile' in DesagglutinationResources group for language " << (int)m_language;
62 loadDelimitersFromFile(file.toUtf8().constData());
66 LERROR <<
"no param 'delimiterFile' in DesagglutinationResources group for language " << (int)m_language;
72void DesagglutinationResources::loadMicroCategoriesMappingFromFile(
const std::string& microcategoriesMappingFile)
76 LINFO <<
"load micro categories mapping from file " << microcategoriesMappingFile;
80 std::ifstream fin(microcategoriesMappingFile.data(), std::ifstream::binary);
83 LERROR <<
"can't open file : " << microcategoriesMappingFile;
84 throw std::runtime_error(
"can't open file for desagglutinator microcategories");
89 std::getline(fin,line);
92 size_t currentIndex,nextStop;
93 nextStop=line.find(
" ");
94 if (nextStop==std::string::npos)
96 LERROR <<
"invalid desagglutinator microcategories file";
97 throw std::runtime_error(
"invalid desagglutinator microcategories file");
100 CompoundCategories compoundCats;
101 currentIndex=nextStop+1;
102 nextStop=line.find(
" ",currentIndex);
103 if (nextStop==std::string::npos)
105 LERROR <<
"invalid desagglutinator microcategories file";
106 throw std::runtime_error(
"invalid desagglutinator microcategories file");
108 compoundCats.begin=microManager.
getPropertyValue(line.substr(currentIndex,nextStop-currentIndex));
109 currentIndex=nextStop+1;
110 nextStop=line.find(
" ",currentIndex);
111 if (nextStop==std::string::npos)
113 LERROR <<
"invalid desagglutinator microcategories file";
114 throw std::runtime_error(
"invalid desagglutinator microcategories file");
116 compoundCats.part=microManager.
getPropertyValue(line.substr(currentIndex,nextStop-currentIndex));
117 currentIndex=nextStop+1;
118 compoundCats.end=microManager.
getPropertyValue(line.substr(currentIndex,line.size()-currentIndex).data());
120 LDEBUG <<
"read CategorieMapping : " << cat <<
" => " << compoundCats.begin <<
" - " << compoundCats.part <<
" - " << compoundCats.end;
121 m_categoriesMapping.insert(std::make_pair(
LinguisticCode(cat),compoundCats));
127 LINFO <<
"loaded " << m_categoriesMapping.size() <<
" microcategory mappings";
130void DesagglutinationResources::loadDelimitersFromFile(
const std::string& delimitersFile)
134 LINFO <<
"load delimiters from file : " << delimitersFile;
136 std::ifstream ifs (delimitersFile.c_str(), std::ifstream::binary);
138 while(ifs.good()&&!ifs.eof())
141 m_delimiters.insert(del);