Beispiel #1
0
        /**
         * 使用用户词典合并粗分结果
         * @param vertexList 粗分结果
         * @return 合并后的结果
         */
        protected static LinkedList <Vertex> combineByCustomDictionary(LinkedList <Vertex> vertexList)
        {
            Vertex[] wordNet = vertexList.ToArray();
            // DAT合并
            DoubleArrayTrie <CoreDictionary.Attribute> dat = CustomDictionary.dat;

            for (int i = 0; i < wordNet.Length; ++i)
            {
                int state = 1;
                state = dat.transition(wordNet[i].realWord, state);
                if (state > 0)
                {
                    int start = i;
                    int to    = i + 1;
                    int end   = to;
                    //CoreDictionary.Attribute value = dat.output(state);
                    //for (; to < wordNet.Length; ++to)
                    //{
                    //    state = dat.transition(wordNet[to].realWord, state);
                    //    if (state < 0) break;
                    //    CoreDictionary.Attribute output = dat.output(state);
                    //    if (output != null)
                    //    {
                    //        value = output;
                    //        end = to + 1;
                    //    }
                    //}
                    //if (value != null)
                    //{
                    //    StringBuilder sbTerm = new StringBuilder();
                    //    for (int j = start; j < end; ++j)
                    //    {
                    //        sbTerm.Append(wordNet[j]);
                    //        wordNet[j] = null;
                    //    }
                    //    wordNet[i] = new Vertex(sbTerm.ToString(), value);
                    //    i = end - 1;
                    //}
                }
            }
            // BinTrie合并
            if (CustomDictionary.trie != null)
            {
                for (int i = 0; i < wordNet.Length; ++i)
                {
                    if (wordNet[i] == null)
                    {
                        continue;
                    }
                    BaseNode <CoreDictionary.Attribute> state = CustomDictionary.trie.transition(wordNet[i].realWord.ToCharArray(), 0);
                    if (state != null)
                    {
                        int start = i;
                        int to    = i + 1;
                        int end   = to;
                        CoreDictionary.Attribute value = state.getValue();
                        for (; to < wordNet.Length; ++to)
                        {
                            if (wordNet[to] == null)
                            {
                                continue;
                            }
                            state = state.transition(wordNet[to].realWord.ToCharArray(), 0);
                            if (state == null)
                            {
                                break;
                            }
                            if (state.getValue() != null)
                            {
                                value = state.getValue();
                                end   = to + 1;
                            }
                        }
                        if (value != null)
                        {
                            StringBuilder sbTerm = new StringBuilder();
                            for (int j = start; j < end; ++j)
                            {
                                if (wordNet[j] == null)
                                {
                                    continue;
                                }
                                sbTerm.Append(wordNet[j]);
                                wordNet[j] = null;
                            }
                            wordNet[i] = new Vertex(sbTerm.ToString(), value);
                            i          = end - 1;
                        }
                    }
                }
            }
            vertexList.Clear();
            foreach (Vertex vertex in wordNet)
            {
                if (vertex != null)
                {
                    vertexList.AddLast(vertex);
                }
            }
            return(vertexList);
        }