Ejemplo n.º 1
0
        /*
         * Function: PhraseTriad
         * Description:TRIStrategy算法读取函数
         * Parameters:
         *      ref cNet cNetwork   待处理网络
         *      string sLine        待分析字符串
         *      string Separator    分隔符
         * Return Value:
         */
        private static void PhraseTriad(ref cNet cNetwork, string sLine, string Separator)
        {
            int intSour, intTar;
            double dubValue;
            string[] strSeg;

            dubValue = 1.0;
            strSeg = sLine.Split(new string[] { Separator }, StringSplitOptions.None);//首先使用Separator进行信息区块划分
            intSour = Convert.ToInt32(strSeg[intSourceOffset]);
            intTar = Convert.ToInt32(strSeg[intTargetOffset]);
            if (strSeg.Length == 3)
            {
                dubValue = Convert.ToDouble(strSeg[intValueOffset]);
            }
            cNetwork.AddEdge(intSour, intTar, dubValue);                              //根据读出的信息加边
        }
Ejemplo n.º 2
0
        /*
         * Function: BuildKeyWordNet
         * Description:构建关键词网络
         * Parameters:
         *      List<kNode> NodeList        待构建节点
         *      List<WordResult> WordList   词语列表
         *      StyleSet PaintStyle     绘制样式集
         * Return Value:cNet
         */
        cNet BuildKeyWordNet(List<kNode> NodeList, List<WordResult> WordList)
        {//核心算法C, 构造网络,主要任务是找到符合条件的两个节点,在他们之间加边。
            cNet NewNet = null;
            int intSource, intTarget, intSourLine, intSourPos;

            //1 构造网络并加入节点
            NewNet = new cNet(NodeList.Count);
            foreach (IfPlatform curNode in NodeList)
            {
                NewNet.Network.Add(curNode);
            }
            //遍历词语列表
            foreach (WordResult word in WordList)
            {
                if(word.IsIgnore == true)
                {//被忽略节点则直接跳到下一个。
                    continue;
                }
                intSourLine = word.Line;//获取词语的句号,位置,作为词语的唯一全局索引(每个词语都不同)
                intSourPos = word.Position;
                //查找对应索引在cNet中的节点的编号,查到返回,查不到返回-1
                intSource = FindNode(intSourLine, intSourPos, WordList, NewNet);
                for (int i = 1; i <= intFollowUp; i++)
                {//对当前节点的后面intFollowUp个邻居节点进行遍历
                    //返回对应索引的邻居节点在cNet中的节点的编号
                    intTarget = FindNode(intSourLine, intSourPos + i, WordList, NewNet);
                    if (intTarget < 0)
                    {//没有邻居则跳出
                        break;
                    }
                    //执行加边
                    NewNet.AddEdge(intSource, intTarget, 1);
                }

            }
            if (NewNet.intNumber == 0)
            {
                return null;
            }
            return NewNet;
        }