in reply to Re^2: makeing refering faster ?
in thread makeing refering faster ?
Well, I'm answering now... You'd need to change the code to place information about the words that bind the sentences among each other inside the @temp array. This means something like this:
So, to clarify, here is the logical structure of the @temp array:my %referencedSentences = (); foreach my $j (@{$words[$i]}) { if (($j ne "$j") || ($j ne "v")) { if (exists $sentences->{$j}) { %referencedSentences{%j} = $sentences->{$j}; } } } push (@temp, \%referencedSentences);
- @temp contains the sentence no. i at position 2 * i and a hash indexed by words that other sentences start with at position 2 * i + 1. Assume sentence my $sentence = $temp[2 * 10] and its hash my $hash = $temp[2 * 10 + 1]
- The hash contains all words in the sentence that other sentences start with. You can get a list of these words like this: my @listOfWordsOtherSentencesStartWith = keys %{$hash}. Say a word (my $word) belongs to this list of words. Then, $hash->{$word} returns a reference to an array that contains the indices (starting from 0) of all sentences that start with word $word. So to get a list of these sentences, you'd write: my @listOfSentencesThatStartWithThisWord = @{$hash->{$word}}
- To get a list of all sentences referenced by a sentence, you'd write something like
my @list; foreach my $refToIndicesArray (values %{$hash}) { push (@list, @{$refToIndicesArray}); }
|
---|
In Section
Seekers of Perl Wisdom