示例#1
0
 static void loadFile(string filename,MasterNodeList<string> masterNodeList,bool quiet,bool splitLetters)
 {
     List<string> sentences;
     List<string> words;
     DataChunkRouteBlazer<string> blazer;
     using (TextReader reader = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
     {
         sentences = SentenceChunkLoader.ToSentenceChunks(reader);
     }
     foreach (string sentence in sentences)
     {
         words = SentenceChunkLoader.ToWordValues(sentence);
         if (splitLetters)
         {
             foreach (string wordChunk in words)
             {
                 blazer = new DataChunkRouteBlazer<string>(charStringsOf(wordChunk), masterNodeList);
                 blazer.computeFullRoute();
                 Console.Out.WriteLine("Added word starting with " + wordChunk.Substring(0,1) + " at start node " +
                     blazer.chunkRoute.startNode.SequenceNumber);
             }
         }
         else
         {
             blazer = new DataChunkRouteBlazer<string>(words, masterNodeList);
             blazer.computeFullRoute();
             if (!quiet)
             {
                 Console.Out.WriteLine("Added sentence starting with " + words.First() + " at start node " +
                     blazer.chunkRoute.startNode.SequenceNumber);
             }
         }
     }
 }
        public void reuseNodeValueByRef()
        {
            MasterNodeList<string> nodeList = new MasterNodeList<string>();
            Dictionary<Node, List<Route>> prefixD = new Dictionary<Node, List<Route>>();
            DataChunkRouteBlazerTest.threeThreeChunks(nodeList, prefixD);
            XmlDocument threeThreeDoc = new XMLGraphFormat<string>().ToXMLDocument(nodeList);
            XmlNode nodesElement = threeThreeDoc.DocumentElement.ChildNodes[0];
            XmlNodeList nodeElements = nodesElement.ChildNodes;

            int firstAIndex = nodeList.getValueNodesByValue("A").ElementAt(0).SequenceNumber;
            int secondAIndex = nodeList.getValueNodesByValue("A").ElementAt(1).SequenceNumber;
            XmlNode secondAXmlElem = nodeElements[secondAIndex];
            Assert.AreEqual(firstAIndex.ToString(), secondAXmlElem.Attributes[XMLGraphFormat<ushort>.VALUEREFATTR].Value);
            Assert.AreEqual("", secondAXmlElem.InnerText);

            MasterNodeList<string> destinationList = new MasterNodeList<string>();
            Dictionary<Node, List<Route>> destinationDict = new Dictionary<Node, List<Route>>();
            DataChunkRoute<string> firstRoute = nodeList.nthDataChunkRoute(0);
            var missingComponents = firstRoute.specsForMissingComponents(destinationList);
            Assert.AreEqual(4, missingComponents.Item1.Count);
            Assert.AreEqual(3, missingComponents.Item2.Count);
            destinationList.reloadNodesThenRoutesFromSpecs(missingComponents.Item1, missingComponents.Item2);

            DataChunkRoute<string> secondRoute = nodeList.nthDataChunkRoute(1);
            Assert.AreEqual(3,secondRoute.componentEdges.Count);
            Assert.AreEqual(1, secondRoute.componentEdges[0].edge.link.from.SequenceNumber);
            Assert.AreEqual(3, secondRoute.componentEdges[1].edge.link.from.SequenceNumber);
            Assert.AreEqual(6, secondRoute.componentEdges[2].edge.link.from.SequenceNumber);
            Assert.AreEqual(7, secondRoute.componentEdges[2].edge.link.to.SequenceNumber);
            foreach(EdgeRoute rt in secondRoute.componentEdges)
            {
                Assert.AreNotEqual(0, rt.edge.link.from.SequenceNumber);
                Assert.AreNotEqual(0, rt.edge.link.to.SequenceNumber);
            }
            var secondMissingComponents = secondRoute.specsForMissingComponents(destinationList);
            var secondMissingNodeSpecs = secondMissingComponents.Item1;
            Assert.AreEqual(3, secondMissingNodeSpecs.Count);
            var secondMissingEdgeSpecs = secondMissingComponents.Item2;
            XmlDocument secondMissingDoc = new XMLGraphFormat<string>().ToXMLDocument(destinationList, secondMissingNodeSpecs, secondMissingEdgeSpecs);
            Assert.AreEqual(2, secondMissingDoc.DocumentElement.ChildNodes.Count);
            nodesElement = secondMissingDoc.DocumentElement.ChildNodes[0];
            nodeElements = nodesElement.ChildNodes;
            Assert.AreEqual(3, nodeElements.Count);
            Assert.AreEqual(NodeKind.GateNode.ToString(), nodeElements[0].Attributes[XMLGraphFormat<bool>.NODEKINDATTR].Value);
            Assert.AreEqual(NodeKind.ValueNode.ToString(), nodeElements[1].Attributes[XMLGraphFormat<bool>.NODEKINDATTR].Value);
            XmlNode AXmlElem = nodeElements[1];
            Assert.AreEqual(6, Convert.ToInt32(AXmlElem.Attributes[XMLGraphFormat<bool>.SEQNUMATTR].Value));
            Assert.AreEqual("", AXmlElem.InnerText);
            Assert.AreEqual(firstAIndex.ToString(), AXmlElem.Attributes[XMLGraphFormat<long>.VALUEREFATTR].Value);

            DataChunkRouteBlazer<string> blaz = new DataChunkRouteBlazer<string>(new List<string> { "G", "G", "G" }, nodeList);
            blaz.computeFullRoute();
            DataChunkRoute<string> GGG = nodeList.nthDataChunkRoute(3);
            secondMissingComponents = GGG.specsForMissingComponents(destinationList);
            secondMissingNodeSpecs = secondMissingComponents.Item1;
            Assert.AreEqual(4, secondMissingNodeSpecs.Count);
            secondMissingDoc = new XMLGraphFormat<string>().ToXMLDocument(destinationList, secondMissingNodeSpecs, secondMissingEdgeSpecs);
            nodesElement = secondMissingDoc.DocumentElement.ChildNodes[0];
            nodeElements = nodesElement.ChildNodes;
            XmlNode G2Elem = nodeElements[2];
            Assert.AreEqual(NodeKind.ValueNode.ToString(), G2Elem.Attributes[XMLGraphFormat<bool>.NODEKINDATTR].Value);
            Assert.AreEqual("", G2Elem.InnerText);
            Assert.IsNotNull(G2Elem.Attributes[XMLGraphFormat<bool>.VALUEREFATTR]);
        }
示例#3
0
        static void threeThreeRoutes(MasterNodeList<string> masterNodeList, Dictionary<Node, List<Route>> routePrefixDictionary)
        {
            List<string> srcDataList = new List<string>() { "A", "B", "C" };
            List<string> srcData2List = new List<string>() { "A", "A", "D" };
            List<string> srcData3List = new List<string>() { "A", "A", "E" };

            DataChunkRouteBlazer<string> chunkRoute = new DataChunkRouteBlazer<string>(srcDataList, masterNodeList);
            DataChunkRouteBlazer<string> chunkRoute2 = new DataChunkRouteBlazer<string>(srcData2List, masterNodeList);
            DataChunkRouteBlazer<string> chunkRoute3 = new DataChunkRouteBlazer<string>(srcData3List, masterNodeList);

            chunkRoute.computeFullRoute();
            chunkRoute2.computeFullRoute();
            chunkRoute3.computeFullRoute();
        }
示例#4
0
        static void threeSixRoutes(MasterNodeList<string> masterNodeList, Dictionary<Node, List<Route>> routePrefixDictionary)
        {
            List<string> srcData4List = new List<string>() { "A", "B", "C", "D", "E", "F" };
            DataChunkRouteBlazer<string> chunkRoute4 = new DataChunkRouteBlazer<string>(srcData4List, masterNodeList);
            chunkRoute4.computeFullRoute();

            List<string> srcData5List = new List<string>() { "G", "B", "C", "D", "J", "K" };
            DataChunkRouteBlazer<string> chunkRoute5 = new DataChunkRouteBlazer<string>(srcData5List, masterNodeList);
            chunkRoute5.computeFullRoute();

            List<string> srcData6List = new List<string>() { "G", "B", "D", "M", "N", "O" };
            DataChunkRouteBlazer<string> chunkRoute6 = new DataChunkRouteBlazer<string>(srcData6List, masterNodeList);
            chunkRoute6.computeFullRoute();
        }
 public void dataSetup46()
 {
     chunkRoute4 = new DataChunkRouteBlazer<string>(srcData4List, list);
     chunkRoute5 = new DataChunkRouteBlazer<string>(srcData5List, list);
     chunkRoute6 = new DataChunkRouteBlazer<string>(srcData6List, list);
 }
 public void dataSetup13()
 {
     chunkRoute = new DataChunkRouteBlazer<string>(srcDataList, list);
     chunkRoute2 = new DataChunkRouteBlazer<string>(srcData2List, list);
     chunkRoute3 = new DataChunkRouteBlazer<string>(srcData3List, list);
 }