a question about map

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
1
2
3
4
5
6
7
8
9
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <map>
#include <string>
#include <iostream>
#include <iomanip>

// for clarity:
typedef std::string word_type ;
typedef std::string tag_type;

int main()
{
    std::map<word_type, std::map<tag_type, int>> 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.