当前位置: 首页>>代码示例>>C#>>正文


C# IReader.Read方法代码示例

本文整理汇总了C#中IReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# IReader.Read方法的具体用法?C# IReader.Read怎么用?C# IReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IReader的用法示例。


在下文中一共展示了IReader.Read方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TFIDF

        public TFIDF(string filePath1, string filePath2, IReworder reworder, IReader reader, bool train)
        {
            Console.Write(Environment.NewLine + "Preparing IDF");
            int linesRead = 0;

            foreach (string line in LinesEnumerator.YieldLines(filePath1))
            {
                List<string> res = reader.Read(ReworderHelper.Map(line, reworder)).Split(' ').ToList();

                foreach (string element in res.Distinct())
                {
                    if (_idf.ContainsKey(element))
                        _idf[element]++;
                    else
                        _idf.Add(element, 1);
                }

                if ((linesRead % DisplaySettings.PrintProgressEveryLine) == 0)
                    Console.Write('.');

                linesRead++;
            }

            foreach (string line in LinesEnumerator.YieldLines(filePath2))
            {
                RawQuestion rq = new RawQuestion(line, train);
                string[] combinations = rq.GetCombinations();
                for (int i = 0; i < combinations.Length; i++)
                    foreach (string element in reader.Read(ReworderHelper.Map(combinations[i], reworder)).Split(' ').Distinct())
                    {
                        if (_idf.ContainsKey(element))
                            _idf[element]++;
                        else
                            _idf.Add(element, 1);
                    }
                if ((linesRead % DisplaySettings.PrintProgressEveryLine) == 0)
                    Console.Write('.');

                linesRead++;
            }

            int n = _idf.Count;

            string[] originalKeys = _idf.Keys.ToArray();

            foreach (string key in originalKeys)
                _idf[key] = Math.Log(n * 1f / _idf[key]);
        }
开发者ID:turboNinja2,项目名称:Rob-The-Robot,代码行数:48,代码来源:TFIDF.cs

示例2: Copy

 public static void Copy(IReader reader, IWriter writer)
 {
     if (reader != null && writer != null)
     {
         string data = reader.Read();
         writer.Write(data);
     }
 }
开发者ID:liupanpansmile,项目名称:AgileDevelopmentStudy,代码行数:8,代码来源:Operation.cs

示例3: ReadTypeUsingCtor

        private object ReadTypeUsingCtor(IReader reader)
        {
            List<object> parameters = new List<object>();
            foreach (var parameter in ctor.GetParameters())
            {
                var paramValue = reader.Read(parameter.ParameterType);
                parameters.Add(paramValue);
            }

            return Activator.CreateInstance(this.type, parameters.ToArray());
        }
开发者ID:TheFlyingFiddle,项目名称:Project-Monocle,代码行数:11,代码来源:ReflectionTypeReader.cs

示例4: ReadType

        public object ReadType(IReader reader)
        {
            var enumVal = reader.Read<int>();
            foreach (var e in Enum.GetValues(enumType))
            {
                if (enumVal == (int)e)
                    return e;
            }

            throw new ArgumentException("Enum value does not exist.");
        }
开发者ID:TheFlyingFiddle,项目名称:Project-Monocle,代码行数:11,代码来源:EnumTypeReader.cs

示例5: DoImport

        private void DoImport(IReader reader)
        {
            string[] values;
            uint lineNumber = 0;

            while ((values = reader.Read()) != null)
            {
                lineNumber++;

                if (string.Join(string.Empty, values).Trim() == string.Empty) // skip empty line
                    continue;

                var item = _formatter.FromString(values, lineNumber);
                _quoteRepository.AddQuote(item);
            }
        }
开发者ID:dminik,项目名称:QuoteLoaderTask,代码行数:16,代码来源:QuoteImporterBase.cs

示例6: ImportSparse

        public static IDictionary<string, double>[] ImportSparse(string filePath, IReworder reworder, IReader reader, ITokenizer tokenizer)
        {
            List<IDictionary<string, double>> encyclopedia = new List<IDictionary<string, double>>();
            int linesRead = 0;

            foreach (string line in LinesEnumerator.YieldLines(filePath))
            {
                IDictionary<string, double> res = tokenizer.Tokenize(reader.Read(ReworderHelper.Map(line,reworder)));

                encyclopedia.Add(res);
                linesRead++;

                if ((linesRead % DisplaySettings.PrintProgressEveryLine) == 0)
                {
                    Console.Write('.');
                }
            }
            return encyclopedia.ToArray();
        }
开发者ID:turboNinja2,项目名称:Rob-The-Robot,代码行数:19,代码来源:EncyclopediaReader.cs

示例7: MainProcess

 /// Main Process. Takes reader and returns boolean if there is such a plan to destroy all robots.
 public static bool MainProcess(IReader reader)
 {
     var result = reader.Read();
     var colors = Algorithm.ColorGraph(result.Graph);
     int firstColorNumber = 0;
     int secondColorNumber = 0;
     for (int i = 0; i < colors.Length; ++i)
     {
         switch (colors[i])
         {
             case Algorithm.Color.noColor:
             {
                 throw new Logic.WrongArgument("Not connected graph given.");
             }
             case Algorithm.Color.firstColor:
             {
                 if (result.IsRobotThere[i])
                 {
                     firstColorNumber++;
                 }
                 break;
             }
             case Algorithm.Color.secondColor:
             {
                 if (result.IsRobotThere[i])
                 {
                     secondColorNumber++;
                 }
                 break;
             }
             default:
             {
                 throw new UnexpectedSwitchCase();
             }
         }
     }
     return firstColorNumber != 1 && secondColorNumber != 1;
 }
开发者ID:alexander-bzikadze,项目名称:University_tasks,代码行数:39,代码来源:Logic.cs

示例8: Parse

		public void Parse(IReader reader, IHandler handler) {
			if (reader == null) throw new ArgumentNullException("reader");
			if (handler == null) handler = new HandlerAdapter();

			AttrListImpl attrList = new AttrListImpl();
			string lastAttrName = null;
			Stack tagStack = new Stack();
			string elementName = null;
			line = 1;
			col = 0;
			int currCh = 0;
			int stateCode = 0;
			StringBuilder sbChars = new StringBuilder();
			bool seenCData = false;
			bool isComment = false;
			bool isDTD = false;
			int bracketSwitch = 0;

			handler.OnStartParsing(this);

			while (true) {
				++this.col;

				currCh = reader.Read();

				if (currCh == -1) {
					if (stateCode != 0) {
						FatalErr("Unexpected EOF");
					}
					break;
				}

				int charCode = "<>/?=&'\"![ ]\t\r\n".IndexOf((char)currCh) & 0xF;
				if (charCode == (int)CharKind.CR) continue; // ignore
				// whitepace ::= (#x20 | #x9 | #xd | #xa)+
				if (charCode == (int)CharKind.TAB) charCode = (int)CharKind.SPACE; // tab == space
				if (charCode == (int)CharKind.EOL) {
					this.col = 0;
					this.line++;
					charCode = (int)CharKind.SPACE;
				}

				int actionCode = MiniParser.Xlat(charCode, stateCode);
				stateCode = actionCode & 0xFF;
				// Ignore newline inside attribute value.
				if (currCh == '\n' && (stateCode == 0xE || stateCode == 0xF)) continue;
				actionCode >>= 8;

				if (stateCode >= 0x80) {
					if (stateCode == 0xFF) {
						FatalErr("State dispatch error.");
					} else {
						FatalErr(errors[stateCode ^ 0x80]);
					}
				}

				switch (actionCode) {
				case (int)ActionCode.START_ELEM:
					handler.OnStartElement(elementName, attrList);
					if (currCh != '/') {
						tagStack.Push(elementName);
					} else {
						handler.OnEndElement(elementName);
					}
					attrList.Clear();
					break;

				case (int)ActionCode.END_ELEM:
					elementName = sbChars.ToString();
					sbChars = new StringBuilder();
					string endName = null;
					if (tagStack.Count == 0 ||
						elementName != (endName = tagStack.Pop() as string)) {
						if (endName == null) {
							FatalErr("Tag stack underflow");
						} else {
							FatalErr(String.Format("Expected end tag '{0}' but found '{1}'", elementName, endName));
						}
					}
					handler.OnEndElement(elementName);
					break;

				case (int)ActionCode.END_NAME:
					elementName = sbChars.ToString();
					sbChars = new StringBuilder();
					if (currCh != '/' && currCh != '>') break;
					goto case (int)ActionCode.START_ELEM;

				case (int)ActionCode.SET_ATTR_NAME:
					lastAttrName = sbChars.ToString();
					sbChars = new StringBuilder();
					break;

				case (int)ActionCode.SET_ATTR_VAL:
					if (lastAttrName == null) FatalErr("Internal error.");
					attrList.Add(lastAttrName, sbChars.ToString());
					sbChars = new StringBuilder();
					lastAttrName = null;
					break;

//.........这里部分代码省略.........
开发者ID:japanhero,项目名称:kbengine_unity3d_demo,代码行数:101,代码来源:MiniParser.cs

示例9: WriteItems

        private static int WriteItems(long expectedCount, XmlWriter writer, IReader reader)
        {
            int count = 0;
            bool itemBegan = false;

            while (reader.Read())
            {
                if (reader.Position == ReaderPosition.EmptyItem ||
                    reader.Position == ReaderPosition.Item)
                {
                    if (itemBegan)
                    {
                        writer.WriteEndElement();
                    }

                    BeginWriteItem(writer, reader);

                    if (!itemBegan)
                    {
                        itemBegan = true;
                    }

                    if (reader.Position != ReaderPosition.EmptyItem)
                    {
                        WriteAttribute(writer, reader);
                    }

                    if (expectedCount != -1)
                    {
                        WriteProgress("Saved {0:F1} %", ((float)count / (float)expectedCount) * 100.0);
                    }
                    else
                    {
                        WriteProgress("Saved {0} items", count);
                    }

                    count++;
                }
                else
                {
                    WriteAttribute(writer, reader);
                }
            }

            if (itemBegan)
            {
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();

            return count;
        }
开发者ID:petrohi,项目名称:Stratosphere,代码行数:54,代码来源:Program.cs

示例10: ReadInt32

        /// <summary>
        /// Read reads structured binary data from <paramref name="r"/>.
        /// Bytes read from <paramref name="r"/> are decoded using the
        /// specified byte <paramref name="order"/> and written to successive
        /// fields of the data.
        /// </summary>
        /// <param name="r">The reader.</param>
        /// <param name="order">The byte order.</param>
        public static int ReadInt32(IReader r, IByteOrder order)
        {
            // NOTE: Departing from "binary.Read", don't want to box/unbox for this low-level call

            var buf = new byte[4];
            r.Read(buf);
            return order.Int32(buf);
        }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:16,代码来源:Binary.cs

示例11: ReadTypeUsingType

        private object ReadTypeUsingType(IReader reader)
        {
            object obj = Activator.CreateInstance(type);

            foreach (var field in type.GetAllFields())
            {
                if (!CanReadField(field))
                    continue;

                object fieldValue = reader.Read(field.FieldType);
                field.SetValue(obj, fieldValue);
            }

            return obj;
        }
开发者ID:TheFlyingFiddle,项目名称:Project-Monocle,代码行数:15,代码来源:ReflectionTypeReader.cs


注:本文中的IReader.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。