예제 #1
0
        public static WordsDictionary Construct(IDictionaryStream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            return(new WordsDictionary(stream.ReadDataFromStream(double.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase)));
        }
        private void ReadDataFromInternalStream(IDictionaryStream stream)
        {
            int index = 0;

            foreach (var record in stream.ReadDataFromStream(int.Parse))
            {
                if (!table.TryGetValue(record.Item1, out var nrcRecord))
                {
                    nrcRecord           = new NRCRecord(record.Item1);
                    table[record.Item1] = nrcRecord;
                    index = 0;
                }

                index++;
                if (record.Item2 == 0)
                {
                    continue;
                }

                switch (index)
                {
                case 1:
                    nrcRecord.IsAnger = true;
                    break;

                case 2:
                    nrcRecord.IsAnticipation = true;
                    break;

                case 3:
                    nrcRecord.IsDisgust = true;
                    break;

                case 4:
                    nrcRecord.IsFear = true;
                    break;

                case 5:
                    nrcRecord.IsJoy = true;
                    break;

                case 6:
                    nrcRecord.IsNegative = true;
                    break;

                case 7:
                    nrcRecord.IsPositive = true;
                    break;

                case 8:
                    nrcRecord.IsSadness = true;
                    break;

                case 9:
                    nrcRecord.IsSurprise = true;
                    break;

                case 10:
                    nrcRecord.IsTrust = true;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("index", index.ToString());
                }
            }
        }