0

Apparently ArrayList.getValue().size() is not the right answer.

I've looked around, not an easy question to pose to Google.

I've explained pretty comprehensively what I'm trying to do in the pseudocode comments, maybe someone knows how to iterate over that array list?

public static void perceptron_data_struc_generateur(Set<String> GLOBO_DICT, 
                                                    Map<File, ArrayList<String> > fileDict,
                                                    Map<File, int[] > perceptron_input)
{

    //create a new entry in the array list 'perceptron_input'
    //with the key as the file name from fileDict
        //create a new array which is the length of GLOBO_DICT
        //iterate through the indicies of GLOBO_DICT
            //for all words in globo dict, if that word appears in fileDict,
            //increment the perceptron_input index that corresponds to that
            //word in GLOBO_DICT by the number of times that word appears in fileDict

    for (Map.Entry entry : fileDict.entrySet()) 
    {
        //System.out.println(entry.getKey());
        int[] cross_czech = new int[GLOBO_DICT.size()];

        for (String s : GLOBO_DICT)
        {
            for(int i = 0; i < entry.getValue() ).size(); i++)
            {

            }
        }

    }
}

Ultimately the goal is to achieve the first answer to this question, in case you're interested.

Community
  • 1
  • 1
smatthewenglish
  • 2,831
  • 4
  • 36
  • 72

1 Answers1

2

Iterating over the ArrayList values of your map :

for (Map.Entry<File, ArrayList<String>> entry : fileDict.entrySet()) 
{
    int[] cross_czech = new int[GLOBO_DICT.size()];

    for (String s : GLOBO_DICT)
    {
        for(String st : entry.getValue()) // iterates over all the Strings
                                          // of the ArrayList of the 
                                          // current entry
        {

        }
    }

}
Eran
  • 387,369
  • 54
  • 702
  • 768
  • 1
    do you know how I could structure the internal component so replicate the data structure described in the linked question, i.e. [this one](http://stackoverflow.com/questions/28536678/run-perceptron-algorithm-on-a-hash-map-feature-vecteur-java) – smatthewenglish Feb 17 '15 at 07:34
  • how could I grab the index of GLOBO_DICT in place of 's'? – smatthewenglish Feb 17 '15 at 07:42
  • @flavius_valens What do you mean by `index of GLOBO_DICT`? `GLOBO_DICT` is a Set, so the elements don't have indices. – Eran Feb 17 '15 at 07:46
  • i just tried with [this wierd method](http://stackoverflow.com/questions/7069052/how-to-obtain-index-of-a-given-set-element-without-iteration), but... didn't work, i edited the answer to show you how I did it. is that a faux pas by the way? – smatthewenglish Feb 17 '15 at 07:49
  • maybe convert the set to a list? – smatthewenglish Feb 17 '15 at 07:53