1

In NLP context, I am researching an efficient way to define a list of singles&combinations as point seperated representation for a string input like: 1 2 3 4 5 6 7 8 9. Whereby each position number is actually a word.

Imagine a sentence with 2 words:

I want.

Splitting this sentence results in 2 words, where the positions are I=1, want=2. The positions of possible singles&combinations are then:

1, 2, 1.2, 2.1, = 4 results

If the input is 3, then I got: 1, 2,3,1.2,1.3, 2.1, 2.3, 3.1, 3.2, 1.2.3, 1.3.2, 2.1.3, 2.3.1, 3.2.1, 3.1.2.= 15 results

I want to define a Java action which gives a list of singles/combinations for a string input like: 1 2 3 4 5 6 7 8 9. Which should be like a list of strings like:

1,2,...., 9.8.7.6.5.4.3.2.1

N-results

Seen some results differ then suggested factorials (3*2*1!=15) I think this is another formula.

user3394645
  • 87
  • 2
  • 11
  • Please see: [Why is “Can someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236) – lexicore Aug 19 '18 at 20:33
  • 1
    A duplicate: https://stackoverflow.com/questions/4240080/generating-all-permutations-of-a-given-string – lexicore Aug 19 '18 at 20:34
  • Possible duplicate of [Generating all permutations of a given string](https://stackoverflow.com/questions/4240080/generating-all-permutations-of-a-given-string) – Johannes Kuhn Aug 20 '18 at 00:42
  • How should the result look like? E.g. for input 2, should the result be the shown "1.2 , 2.1" ? How would the desired result for input 3 look like? I am asking to protect your question from being closed as duplicate, if the "original" does not really help you. – Yunnosch Aug 20 '18 at 13:33
  • Yes the result should be shown as 1.2, 2.1. If the input is 3, then I got: 1,2,3,1.2,1.3, 2.1, 2.3, 3.1, 3.2, 1.2.3, 1.3.2, 2.1.3, 2.3.1, 3.2.1, 3.1.2...I think it is not a duplicate of the above links. The word can have alone a meaning and a combined different meaning, therefore should the single words also count, but also same words in different order (1.2, 2.1). – user3394645 Aug 21 '18 at 06:48

1 Answers1

0

You want permutations without replacement:

number of permutations = n!/(n-r)!

If you have n words in a sentence, and you want to see how many permutations there are without replacement in sentences of r words, then this formula is your answer.

If n = r, then number of permutations = n!, since 0! = 1.

Update:

If you allow the permutations for r = 1, 2, 3...n, then you have to sum over r. The formula is still correct.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • In case of 3 words the formula's result (3*2*1=6) is not correct, seen I got (at least): 1,2,3,1.2,1.3, 2.1, 2.3, 3.1, 3.2, 1.2.3, 1.3.2, 2.1.3, 2.3.1, 3.2.1, 3.1.2... The word can have alone a meaning and a combined different meaning, therefore should the single words also count, but also same words in different order (1.2, 2.1) – user3394645 Aug 21 '18 at 06:53