I have a situation where I have several text documents and I want to create a list that contains the words in those documents. But I also need to record several properties of each word. These properties are

  • The index of the word within all the words in the documents (Integer)
  • The word itself (String)
  • The document that the word is in (Integer)
  • The topic value associated with this word (Integer)

I can think of two ways of doing this. The first is simply creating a list of tuples of the form (word,doc,topic) where the word index is given by the index of the tuple in the list. My second idea is to create a word class where the given properties are member variables in the class. Then just create a list of objects from this class.

So my question is which is the best solution - the list of tuples or the list of word objects? And a related question is what are the situations when either of these approaches is preferable?

  • How many are "several?" What is your persistence mechanism? A SQL database? – Robert Harvey May 11 '14 at 0:56
  • See possibly related programmers.stackexchange.com/questions/166908 – 9000 May 11 '14 at 1:03
  • 'Several' just means the 4 that I mentioned. There is no persistance mechanism. The set of documents is the input to the algorithm that I am coding. It's all in-memory. – user1893354 May 11 '14 at 1:10
  • 2
    go with tuple if you're lazy, but you must go with Word object if gonna be passed a lot or used by another person. List<Tuple<int, string, int, int>> is confusing while List<Word> is self explanatory. – kirie May 11 '14 at 8:13

The answer to this question will depend also on how the words will be searched, will the search key be whole words or can they be incomplete words, will you search on basis of document etc. etc.

Also how are you planning to use the words and properties.

  • No real searching would be done, just iterating through the list – user1893354 May 12 '14 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.