LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
EnhancedAnalysisDictionaryTest1-src.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6// clazy:skip
7
8#define BOOST_TEST_DYN_LINK
9#define BOOST_TEST_MODULE EnhancedAnalysisDictionaryTest
10#include <boost/test/unit_test.hpp>
11
23
24using namespace Lima;
25using namespace Lima::Common;
26using namespace Lima::Common::FsaAccess;
27
28// create EnhancedAnalysisDictionary and check most of public operation
29BOOST_AUTO_TEST_CASE( EnhancedAnalysisDictionaryTest1 )
30{
31 // Initialize MediaData (for fre)
32 //value of LIMA_RESOURCE_DIR is set by find_package(LIMADATA) and LIMALDATAConfig.cmake;
33 std::string resourcesPath("@LIMA_RESOURCE_DIR@");
34 std::string configDir(getenv("LIMA_CONF")==0?"@CMAKE_INSTALL_PREFIX@/share/config/lima/":getenv("LIMA_CONF"));
35 std::string commonConfigFile("lima-common.xml");
36 std::deque<std::string>langs(1,"fre");
37 Common::MediaticData::MediaticData::changeable().init(
38 resourcesPath,
39 configDir,
40 commonConfigFile,
41 langs);
42
43 const MediaticData::MediaData& mediaData = MediaticData::MediaticData::single().mediaData("fre");
44 MediaId mediaId = mediaData.getMedia();
45
46 // initialize minimal resources to test EnhancedDict = globalFsaAccess + mainDictionary
47 std::string lpFreConfFile("lima-lp-res-Enhanced.xml");
48 /* content of file is:
49 <modulesConfig>
50 <module name="Resources">
51 <group name="FsaStringsPool">
52 <param key="mainKeys" value="globalFsaAccess"/>
53 </group>
54 <group name="mainDictionary" class="EnhancedAnalysisDictionary">
55 <param key="accessKeys" value="globalFsaAccess"/>
56 <param key="dictionaryValuesFile" value="LinguisticProcessings/fre/dicoDat-fre.dat"/>
57 </group>
58 <group name="globalFsaAccess" class="FsaAccess">
59 <param key="keyFile" value="LinguisticProcessings/fre/dicoKey-fre.dat"/>
60 </group>
61 </module>
62</modulesConfig>
63*/
65 std::cout << "configure resources for language " << *(langs.begin());
66 try
67 {
68 Common::XMLConfigurationFiles::ModuleConfigurationStructure& module=langParser.getModuleConfiguration("Resources");
69 LinguisticProcessing::LinguisticResources::changeable().initLanguage(
70 mediaId,
71 module,
72 true); // Initialize StringPool with keys of globalFsaAccess
73 }
75 {
76 std::cerr << "no module 'Resources' in configuration file " << lpFreConfFile;
77 throw InvalidConfiguration("no module 'Resources' in configuration file ");
78 }
79
80 // get globalFsaAccess (convert keys to Id)
81 const Lima::LinguisticProcessing::AbstractResource* globalFsaAccess=Lima::LinguisticProcessing::LinguisticResources::single().getResource(mediaId,"globalFsaAccess");
82 // check if it an AbstractAccessResource
84 BOOST_REQUIRE(aar != 0);
85 std::cout << "EnhancedAnalysisDictionaryTest1: test aar != 0 OK\n";
86 // check if it isMainKeys
87 BOOST_REQUIRE(aar->isMainKeys());
88 // check if it a FsaAccessResource
90 BOOST_REQUIRE(far != 0);
91 std::cout << "EnhancedAnalysisDictionaryTest1: test far != 0 OK\n";
92 // get AbstractAccessByString
94 // check if it a FsaAccess::FsaAccessSpare16*
95 const FsaAccess::FsaAccessSpare16* fas=static_cast<const FsaAccess::FsaAccessSpare16*>(aas);
96 BOOST_REQUIRE(fas != 0);
97 uint64_t nbEntries = fas->getSize();
98 std::cout << "nbEntries=" << nbEntries << std::endl;
99
100 // get mainDictionary
101 const Lima::LinguisticProcessing::AbstractResource* mainDictionary=Lima::LinguisticProcessing::LinguisticResources::single().getResource(mediaId,"mainDictionary");
102 // check if it a AbstractAnalysisDictionary
104 BOOST_REQUIRE( aad != 0 );
105 // check if it a EnhancedAnalysisDictionary
107 BOOST_REQUIRE( ead != 0 );
108
109 // test uint64_t getSize() const;
110 // check size is size of accessKeys
111 BOOST_REQUIRE( ead->getSize() == nbEntries );
112
113 // test DictionaryEntry getEntry(const Lima::LimaString& word) const;
114 // create DictionaryEntry from string or StringPool
115
116/*
117 * <entry k="porte">
118 <i l="porte">
119 <p v="Ncgfs-"/>
120 </i>
121 <i l="porter">
122 <p v="Vpipi3-s"/>
123 <p v="Vpipp3-s"/>
124 <p v="Vpmpi2-s"/>
125 <p v="Vpmpp2-s"/>
126 </i>
127</entry>
128*/
129 const Lima::LimaString entryKey("porte");
130 // get id for key entryKey
131 StringsPoolIndex id = static_cast<StringsPoolIndex>(aas->getIndex(entryKey));
132 // get entry for key entryKey
134 // check that id of entry is id of entryKey
135 BOOST_REQUIRE( id == entry1.getEntryId() );
136
137 BOOST_REQUIRE( !entry1.isEmpty() );
138 BOOST_REQUIRE( !entry1.isFinal() );
139 BOOST_REQUIRE( entry1.hasLingInfos() );
140
141 // test DictionaryEntry getEntry(const StringsPoolIndex wordId) const;
143 BOOST_REQUIRE( id == entry2.getEntryId() );
144 // test DictionaryEntry getEntry(const StringsPoolIndex wordId, const Lima::LimaString& word) const;
146 BOOST_REQUIRE( id == entry3.getEntryId() );
147
148 // void parseLingInfos(AbstractDictionaryEntryHandler* handler) const;
149 // bool hasConcatenated() const;
150 // void parseConcatenated(AbstractDictionaryEntryHandler* handler) const;
151 // bool hasAccentedForms() const;
152 // void parseAccentedForms(AbstractDictionaryEntryHandler* handler) const;
155 LinguisticProcessing::AnalysisDict::AbstractDictionaryEntryHandler* lingInfoHandler=&morphoSyntacticDataHandler;
156 entry1.parseLingInfos(lingInfoHandler);
157
158 // std::set<StringsPoolIndex> allInflectedForms() const;
159 // std::set<StringsPoolIndex> allLemma() const;
160 // std::set<StringsPoolIndex> allNormalizedForms() const;
161
162 std::set<StringsPoolIndex> forms;
163 forms = msd.allInflectedForms();
164 std::set<StringsPoolIndex>::const_iterator formsIt = forms.begin();
165 std::cout << "allInflectedForms: ";
166 for( ; formsIt != forms.end() ; formsIt++ ) {
167 StringsPoolIndex formId = *formsIt;
168 LimaString formLimaString = aas->getSpelling(formId);
169 std::string formStdString = Lima::Common::Misc::limastring2utf8stdstring(formLimaString);
170 std::cout << formStdString << ", ";
171 }
172 std::cout << std::endl;
173
174 std::set<StringsPoolIndex> lemmas;
175 lemmas = msd.allLemma();
176 std::set<StringsPoolIndex>::const_iterator lemmasIt = lemmas.begin();
177 std::cout << "allLemma: ";
178 for( ; lemmasIt != lemmas.end() ; lemmasIt++ ) {
179 StringsPoolIndex lemmaId = *lemmasIt;
180 LimaString lemmaLimaString = aas->getSpelling(lemmaId);
181 std::string lemmaStdString = Lima::Common::Misc::limastring2utf8stdstring(lemmaLimaString);
182 std::cout << lemmaStdString << ", ";
183 }
184 std::cout << std::endl;
185
186 std::set<StringsPoolIndex> normalized;
187 normalized = msd.allNormalizedForms();
188 std::cout << "allNormalizedForms: ";
189 std::set<StringsPoolIndex>::const_iterator normalizedIt = normalized.begin();
190 for( ; normalizedIt != normalized.end() ; normalizedIt++ ) {
191 StringsPoolIndex normalizedId = *normalizedIt;
192 LimaString normalizedLimaString = aas->getSpelling(normalizedId);
193 std::string normalizedStdString = Lima::Common::Misc::limastring2utf8stdstring(normalizedLimaString);
194 std::cout << normalizedStdString << ", ";
195 }
196 std::cout << std::endl;
197
198}
BOOST_AUTO_TEST_CASE(EnhancedAnalysisDictionaryTest1)
define abstract interface for access method
virtual uint64_t getIndex(const Lima::LimaString &word) const =0
get key index
virtual Lima::LimaString getSpelling(const uint64_t index) const =0
get string from index
virtual uint64_t getSize() const override
gives the number of entries
Holds mediatic data for one media.
Definition mediaData.h:50
return a message when a 'module' is not found
Parser class for the lima's xml configuration files.
Use this exception to signal an error in one of the configuration files.
Definition LimaCommon.h:345
virtual std::shared_ptr< Common::AbstractAccessByString > getAccessByString() const =0
void parseLingInfos(AbstractDictionaryEntryHandler *handler) const
virtual DictionaryEntry getEntry(const Lima::LimaString &word) const override
get dictionary entry for a word
virtual uint64_t getSize() const override
return number of keys in dictionary
static const LinguisticResources & single()
const singleton accessor
Definition Singleton.h:51
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
NAUTITIA.
QString LimaString
Definition LimaString.h:33