コード例 #1
0
        /// <summary>
        /// Deserializes from text file to DistalDendrite
        /// </summary>
        /// <param name="sr"></param>
        /// <returns>DistalDendrite</returns>
        public Synapse DeserializeSynapse(StreamReader sr)
        {
            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();

                if (data == ReadBegin(nameof(Synapse)))
                {
                    Synapse synapseT1 = Synapse.Deserialize(sr);

                    Cell cell1 = synapseT1.SourceCell;

                    DistalDendrite distSegment1 = synapseT1.SourceCell.DistalDendrites[0];

                    DistalDendrite distSegment2 = synapseT1.SourceCell.DistalDendrites[1];

                    distSegment1.ParentCell = cell1;
                    distSegment2.ParentCell = cell1;
                    synapseT1.SourceCell    = cell1;

                    return(synapseT1);
                }
            }
            return(null);
        }
コード例 #2
0
ファイル: Cell.cs プロジェクト: rabiul64/neocortexapi
        public static Cell Deserialize(StreamReader sr)
        {
            Cell cell = new Cell();

            HtmSerializer2 ser = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();
                if (data == String.Empty || data == ser.ReadBegin(nameof(Cell)) || data.ToCharArray()[0] == HtmSerializer2.ElementsDelimiter || (data.ToCharArray()[0] == HtmSerializer2.ElementsDelimiter && data.ToCharArray()[1] == HtmSerializer2.ParameterDelimiter))
                {
                    continue;
                }
                else if (data == ser.ReadBegin(nameof(DistalDendrite)))
                {
                    cell.DistalDendrites.Add(DistalDendrite.Deserialize(sr));
                }
                else if (data == ser.ReadBegin(nameof(Synapse)))
                {
                    return(cell);
                }
                else if (data == ser.ReadEnd(nameof(Cell)))
                {
                    break;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            cell.Index = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 1:
                        {
                            cell.CellId = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 2:
                        {
                            cell.ParentColumnIndex = ser.ReadIntValue(str[i]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }
            return(cell);
        }
コード例 #3
0
        /// <summary>
        /// Deserialize the array of cells.
        /// </summary>
        /// <param name="reader"></param>
        public Cell[] DeserializeCellArray(string data, StreamReader reader)
        {
            List <Cell> cells = new List <Cell>();

            if (data == ReadBegin(nameof(Cell)))
            {
                Cell cell1 = Cell.Deserialize(reader);

                if (cell1.DistalDendrites.Count != 0)
                {
                    DistalDendrite distSegment1 = cell1.DistalDendrites[0];

                    DistalDendrite distSegment2 = cell1.DistalDendrites[1];


                    distSegment1.ParentCell = cell1;
                    distSegment2.ParentCell = cell1;
                }
                cells.Add(cell1);
            }
            while (reader.Peek() >= 0)
            {
                string val = reader.ReadLine();
                if (val == ReadBegin(nameof(Cell)))
                {
                    Cell cell1 = Cell.Deserialize(reader);
                    if (cell1.DistalDendrites.Count != 0)
                    {
                        DistalDendrite distSegment1 = cell1.DistalDendrites[0];

                        DistalDendrite distSegment2 = cell1.DistalDendrites[1];

                        distSegment1.ParentCell = cell1;
                        distSegment2.ParentCell = cell1;
                    }
                    cells.Add(cell1);
                }
            }

            Cell[] cells1 = cells.ToArray();
            return(cells1);
        }
コード例 #4
0
        ///// <summary>
        ///// Deserializes from text file to Cell
        ///// </summary>
        ///// <param name="sr"></param>
        ///// <returns>Cell</returns>
        public Cell DeserializeCell(StreamReader sr)
        {
            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();

                if (data == ReadBegin(nameof(Cell)))
                {
                    Cell cell1 = Cell.Deserialize(sr);

                    DistalDendrite distSegment1 = cell1.DistalDendrites[0];

                    DistalDendrite distSegment2 = cell1.DistalDendrites[1];

                    distSegment1.ParentCell = cell1;
                    distSegment2.ParentCell = cell1;

                    return(cell1);
                }
            }
            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Deserializes from text file to DistalDendrite
        /// </summary>
        /// <param name="sr"></param>
        /// <returns>DistalDendrite</returns>
        public DistalDendrite DeserializeDistalDendrite(StreamReader sr)
        {
            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();

                if (data == ReadBegin(nameof(DistalDendrite)))
                {
                    DistalDendrite distSegment1 = DistalDendrite.Deserialize(sr);

                    Cell cell1 = distSegment1.ParentCell;

                    distSegment1            = distSegment1.ParentCell.DistalDendrites[0];
                    distSegment1.ParentCell = cell1;
                    DistalDendrite distSegment2 = distSegment1.ParentCell.DistalDendrites[1];
                    distSegment2.ParentCell = cell1;

                    return(distSegment1);
                }
            }
            return(null);
        }
コード例 #6
0
ファイル: Cell.cs プロジェクト: ddobric/neocortexapi
        /// <summary>
        /// Deserializes the cell from the stream.
        /// </summary>
        /// <param name="sr"></param>
        /// <returns></returns>
        public static Cell Deserialize(StreamReader sr)
        {
            Cell cell = new Cell();

            HtmSerializer2 ser = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();

                if (data == String.Empty || data == ser.ReadBegin(nameof(Cell)))
                {
                    continue;
                }
                else if (data == ser.ReadEnd(nameof(Cell)))
                {
                    break;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            cell.Index = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 1:
                        {
                            cell.CellId = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 2:
                        {
                            cell.ParentColumnIndex = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 3:
                        {
                            int[] vs = ser.ReadArrayInt(str[i]);
                            cell.DistalDendrites = new List <DistalDendrite>();
                            for (int j = 0; j < vs.Count(); j++)
                            {
                                cell.DistalDendrites.Add(new DistalDendrite());
                                cell.DistalDendrites[j].Ordinal = vs[j];
                                using (StreamReader swLD = new StreamReader($"ser_SerializeDistalDendrite_{cell.DistalDendrites[j].Ordinal}.txt"))
                                {
                                    cell.DistalDendrites[j] = DistalDendrite.Deserialize(swLD);
                                }
                            }
                            break;
                        }

                        case 4:
                        {
                            int[] vs = ser.ReadArrayInt(str[i]);
                            cell.ReceptorSynapses = new List <Synapse>();
                            for (int j = 0; j < vs.Count(); j++)
                            {
                                cell.ReceptorSynapses.Add(new Synapse());
                                cell.ReceptorSynapses[j].SynapseIndex = vs[j];

                                using (StreamReader swLS = new StreamReader($"ser_SerializeSynapseTest_{cell.ReceptorSynapses[j].SynapseIndex}.txt"))
                                {
                                    cell.ReceptorSynapses[j] = Synapse.Deserialize(swLS);
                                }
                            }

                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }

            return(cell);
        }