My objects structure in a current program is organized so that a Doc
object contains a list of Mention
objects, and each Mention
object contains a list of Word
objects. Words are identified by their position in the Doc's text and also store some other information (its text, its wordnet sense...)
In the processing of the program (through user interaction, etc..) Word
objects inside a Mention
can be accessed and modified value (for example, update its sense). User interaction with each Mention
is a requirement.
The problem I met here is that several Mention
s that belong to the same Doc
might share some same Word
s (after all, all words are in the Doc). So when such a Word is updated, how should I update the corresponding Word
contained in other Mention
s ? In other words, these Word
s are in the same exact location in the text and should be updated together, but they are stored separately in Mentions. So how should one update change the others ?
One approach I used is when a Word
inside a Mention
is modified, I retrieve all mentions (from a stored Doc
reference) and then update the corresponding Word
in any Mention
that contains it. This requires a for loop with Equals checks on each update, which is quite a lot processing.
The second approach I think of is not to store separate Word
lists in Mention
s. Only a single list of Word
s is store in Doc
, and in each Mention
the indices of which Word
s belong to the Mention
is store in a list. So when updating a Word
, I will call an update function from the Doc
's reference to update the Doc
's list. However, the problem lies in the function that returns the whole list of Word
s for a Mention
. I have to return a new list of Word
s, using the indices I have to pick actual Word
s inside the Doc
's list. This is needed because all Word
s inside that Mention
may have been modified by some other Mention
(s) just shortly before. Alternatively, I can check if a Word
is updated and copy the update. But it still requires a for loop through all Word
s in the Mention
, so it still seems weird (Each time retrieving the list = long operation)
What I want to ask is if there is any better solution to this update problem. Any help is much appreciated :) If it is necessary, I will add part of my code here.