hi, everyone ,I have a map<string ,int > innermap, and put it in a map, map<string, innermap> outtermap, now I put word/tag/number in it ,tag is the characteristic or property of a certain word, number is how many times the pair (word , tag) have shown, but one word can have several tag, now I have a word, let's call it 'firstword' , how can I find every number in the innermap by the 'firstword'
.thank you.
Last edited on
Your explanation is unclear, could you try to explain in a different way?
ok, say , for the word "fly" , there are two tag, V and N , and when fly used as a verb , it appears 35 times ， and as a noun ， it appears 150 times， so fly/verb/35, and fly/noun/150, are stored, now I have the word "fly", how to find the value 35 and 150 in the map ,respectively
 ``123456789`` ``````struct WordUsed { int asNoun; int asVerb; }; std::map< std::string, WordUsed > yourmap; yourmap["fly"].asNoun += 1;``````

EDIT:
If the tags have to be dynamic, that gets a little trickier. You could use a map of a map... or you could use a map with a tuple key instead of a string.
Last edited on
Following the strategy described in the OP:
 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include #include #include #include // for clarity: typedef std::string word_type ; typedef std::string tag_type; int main() { std::map> wordcount; wordcount["fly"]["V"] = 35; wordcount["fly"]["N"] = 150; wordcount["fill"]["V"] = 49; wordcount["fill"]["N"] = 20; wordcount["time"]["V"] = 19; wordcount["time"]["N"] = 90; for (auto& tag : wordcount) { std::cout << std::left << std::setw(10) << tag.first << '\n'; for (auto & count : tag.second) { std::cout << std::setw(10) << ""; std::cout << '[' << count.first << ']'; std::cout << std::right << std::setw(5) << count.second << '\n'; } std::cout << '\n'; } }``````

http://ideone.com/HHpmRm
Topic archived. No new replies allowed.