|
|
@ -68,9 +68,8 @@ |
|
|
|
public long GetPhrasesCount() |
|
|
|
public long GetPhrasesCount() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return this.VectorsProcessor.GenerateSequences() |
|
|
|
return this.VectorsProcessor.GenerateSequences() |
|
|
|
.Select(this.ConvertVectorsToWords) |
|
|
|
.Select(this.ConvertVectorsToWordsNumber) |
|
|
|
.SelectMany(Flattener.Flatten) |
|
|
|
.Sum(tuple => tuple.Item2 * PrecomputedPermutationsGenerator.GetPermutationsNumber(tuple.Item1)); |
|
|
|
.Sum(words => (long)PrecomputedPermutationsGenerator.HamiltonianPermutations(words.Length).Count()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private byte[][][] ConvertVectorsToWords(int[] vectors) |
|
|
|
private byte[][][] ConvertVectorsToWords(int[] vectors) |
|
|
@ -85,6 +84,17 @@ |
|
|
|
return words; |
|
|
|
return words; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Tuple<int, long> ConvertVectorsToWordsNumber(int[] vectors) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
long result = 1; |
|
|
|
|
|
|
|
for (var i = 0; i < vectors.Length; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
result *= this.WordsDictionary[vectors[i]].Length; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Tuple.Create(vectors.Length, result); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<PhraseSet> ConvertWordsToPhrases(byte[][] words) |
|
|
|
private IEnumerable<PhraseSet> ConvertWordsToPhrases(byte[][] words) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var permutations = PrecomputedPermutationsGenerator.HamiltonianPermutations(words.Length); |
|
|
|
var permutations = PrecomputedPermutationsGenerator.HamiltonianPermutations(words.Length); |
|
|
|