public override void Build(InputIterator tfit) { if (tfit.HasPayloads) { throw new ArgumentException("this suggester doesn't support payloads"); } if (tfit.Comparator != null) { // make sure it's unsorted // WTF - this could result in yet another sorted iteration.... tfit = new UnsortedInputIterator(tfit); } if (tfit.HasContexts) { throw new System.ArgumentException("this suggester doesn't support contexts"); } count = 0; trie = new JaspellTernarySearchTrie(); trie.MatchAlmostDiff = editDistance; BytesRef spare; CharsRef charsSpare = new CharsRef(); while ((spare = tfit.Next()) != null) { long weight = tfit.Weight; if (spare.Length == 0) { continue; } charsSpare.Grow(spare.Length); UnicodeUtil.UTF8toUTF16(spare.Bytes, spare.Offset, spare.Length, charsSpare); trie.Put(charsSpare.ToString(), Convert.ToInt64(weight)); } }
public override void Build(IInputEnumerator enumerator) { // LUCENENET: Added guard clause for null if (enumerator is null) { throw new ArgumentNullException(nameof(enumerator)); } if (enumerator.HasPayloads) { throw new ArgumentException("this suggester doesn't support payloads"); } if (enumerator.Comparer != null) { // make sure it's unsorted // WTF - this could result in yet another sorted iteration.... enumerator = new UnsortedInputEnumerator(enumerator); } if (enumerator.HasContexts) { throw new ArgumentException("this suggester doesn't support contexts"); } count = 0; trie = new JaspellTernarySearchTrie { MatchAlmostDiff = editDistance }; BytesRef spare; var charsSpare = new CharsRef(); while (enumerator.MoveNext()) { spare = enumerator.Current; long weight = enumerator.Weight; if (spare.Length == 0) { continue; } charsSpare.Grow(spare.Length); UnicodeUtil.UTF8toUTF16(spare.Bytes, spare.Offset, spare.Length, charsSpare); trie.Put(charsSpare.ToString(), weight); } }
/// <summary> /// Constructor method. /// </summary> /// <param name="outerInstance">The containing <see cref="JaspellTernarySearchTrie"/></param> /// <param name="splitchar"> /// The char used in the split. </param> /// <param name="parent"> /// The parent node. </param> internal TSTNode(JaspellTernarySearchTrie outerInstance, char splitchar, TSTNode parent) { this.outerInstance = outerInstance; this.splitchar = splitchar; relatives[PARENT] = parent; }
public override void Build(IInputIterator tfit) { if (tfit.HasPayloads) { throw new ArgumentException("this suggester doesn't support payloads"); } if (tfit.Comparator != null) { // make sure it's unsorted // WTF - this could result in yet another sorted iteration.... tfit = new UnsortedInputIterator(tfit); } if (tfit.HasContexts) { throw new System.ArgumentException("this suggester doesn't support contexts"); } count = 0; trie = new JaspellTernarySearchTrie { MatchAlmostDiff = editDistance }; BytesRef spare; var charsSpare = new CharsRef(); while ((spare = tfit.Next()) != null) { long weight = tfit.Weight; if (spare.Length == 0) { continue; } charsSpare.Grow(spare.Length); UnicodeUtil.UTF8toUTF16(spare.Bytes, spare.Offset, spare.Length, charsSpare); trie.Put(charsSpare.ToString(), Convert.ToInt64(weight)); } }
private void WriteRecursively(DataOutput @out, JaspellTernarySearchTrie.TSTNode node) { if (node == null) { return; } @out.WriteString(new string(new char[] { node.splitchar }, 0, 1)); sbyte mask = 0; if (node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID] != null) { mask |= LO_KID; } if (node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID] != null) { mask |= EQ_KID; } if (node.relatives[JaspellTernarySearchTrie.TSTNode.HIKID] != null) { mask |= HI_KID; } if (node.data != null) { mask |= HAS_VALUE; } @out.WriteByte((byte)mask); if (node.data != null) { @out.WriteLong((long)(node.data)); } WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID]); WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID]); WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.HIKID]); }
private void ReadRecursively(DataInput @in, JaspellTernarySearchTrie.TSTNode node) { node.splitchar = @in.ReadString()[0]; sbyte mask = (sbyte)@in.ReadByte(); if ((mask & HAS_VALUE) != 0) { node.data = Convert.ToInt64(@in.ReadLong()); } if ((mask & LO_KID) != 0) { var kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node); node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID] = kid; ReadRecursively(@in, kid); } if ((mask & EQ_KID) != 0) { var kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node); node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID] = kid; ReadRecursively(@in, kid); } if ((mask & HI_KID) != 0) { var kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node); node.relatives[JaspellTernarySearchTrie.TSTNode.HIKID] = kid; ReadRecursively(@in, kid); } }
/// <summary> /// Constructor method. /// </summary> /// <param name="splitchar"> /// The char used in the split. </param> /// <param name="parent"> /// The parent node. </param> protected internal TSTNode(JaspellTernarySearchTrie outerInstance, char splitchar, TSTNode parent) { this.outerInstance = outerInstance; this.splitchar = splitchar; relatives[PARENT] = parent; }