1

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?

4
  • How many are "several?" What is your persistence mechanism? A SQL database? Commented May 11, 2014 at 0:56
  • See possibly related programmers.stackexchange.com/questions/166908 Commented May 11, 2014 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. Commented May 11, 2014 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. Commented May 11, 2014 at 8:13

1 Answer 1

1

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.

1
  • No real searching would be done, just iterating through the list Commented May 12, 2014 at 17:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.