BotSharp/BotSharp.NLP/Corpus/LabeledPerFileNameReader.cs

40 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace BotSharp.NLP.Corpus
{
/// <summary>
/// It used to read labeled data which is seperated by file.
/// The same category data is in one file.
/// File name is the label.
/// </summary>
public class LabeledPerFileNameReader
{
public List<Sentence> Read(ReaderOptions options)
{
2018-09-09 03:59:01 +00:00
string label = options.FileName.Split('.')[0];
var sentences = new List<Sentence>();
using (StreamReader reader = new StreamReader(Path.Combine(options.DataDir, options.FileName)))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (!String.IsNullOrEmpty(line))
{
sentences.Add(new Sentence
{
2018-09-09 03:59:01 +00:00
Label = label,
Text = line
});
}
}
}
return sentences;
}
}
}