W dniu 2013-04-29 17:28, Paolo Bianchini pisze: > > On Apr 29, 2013, at 10:11 AM, Marcin Miłkowski wrote: > >> W dniu 2013-04-28 23:37, Jaume Ortolà i Font pisze: >>> Hi Marcin, >>> >>> The condition >>> >>> >>> && !(containsSeparators && >>> candidate[depth]==(char)dictionaryMetadata.separator) >>> >>> >>> >>> at line 345, should go, instead, at line 339, as we don't want to "add >>> candidates" containing a separator character. >> >> We don't want to add such candidates, but a candidate is only added when >> its last character is the terminal arc or when it is immediately >> preceding the separator. So basically the candidate with a separator >> cannot be added here at all because we stopped processing at the >> separator on line 345. >> >> This is why adding any further condition doesn't make sense to me. >> >>> >>> >>> >>> As for getAllReplacements, I think it could be recursive with an index >>> (starting fromIndex=0). Something like this (I haven't tried it): >> >> Could you try it? From how I understand your code, it would only lead to >> replacing all instances but we want to replace more... Let me use a >> trivial example: >> >> AbAcAdAe >> >> Say we want to replace "A" with "123". Then we want to have: >> >> 123bAcAdAe >> Ab123cAdAe >> AbAc123dAe >> AbAcAd123e >> 123b123cAdAe >> 123bAc123d123e >> Ab123Acd123e >> 123bAc123d123e >> >> etc. >> >> In other words, we have 4 possible slots for "123" (all matches of "A"), >> and we should have cases where: >> >> - only one slot is filled at any position >> - only two slots are filled at any position >> - only three slots are filled at any position >> - all four slots are filled >> >> So, we need to have something like a Cartesian product... Something like >> this: >> http://stackoverflow.com/questions/14841652/string-replacement-combinations >> > > I did not look at the link you sent but... to stick with your example, you > have four occurrences of the pattern that you want to replace. This means > that you have 2^4 possible strings resulting and you need to replace the > occurrences just as if you were counting on a binary basis > > 0001 > 0010 > 0011 > 0100 > 0101 > 0110 > 0111 > 1000 > 1001 > … > 1111 > > therefore, a possible solution could be: > > 1) find the number of occurrences of the pattern to replace, store it in N > > 2) iterate for i until 2^N > > 3) at each iteration replace or not occurrence in position j (with 0 < j < N) > if the binary representation of i in pos j is on or off (you might want to > use some kind of bitwise AND operation i && 2^0, i && 2^1, I && 2^2, … , i && > 2^N, add to result list
Not really, I did some further analysis and I need a sum of k-permutations (permutations with repetition) from the set. Let's call perm(x,y) the function that computes the k-permutation of x elements out of y-element set. perm(k,n) = n! / (n! - k!), so the number of replacements for 4 instances of the replaced pattern in the string is: perm(4,1) + perm(4,2) + perm(4,3) + perm(4,4) = 4 + 6 + 4 + 1 = 15 Which is not 2^4 (=16). But your solution is similar to the Lehmer code algorithm for permutations. Regards, Marcin ------------------------------------------------------------------------------ Try New Relic Now & We'll Send You this Cool Shirt New Relic is the only SaaS-based application performance monitoring service that delivers powerful full stack analytics. Optimize and monitor your browser, app, & servers with just a few lines of code. Try New Relic and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr _______________________________________________ Languagetool-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/languagetool-devel
