BotSharp/BotSharp.NLP/Corpus/FasttextDataReader.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2018-09-09 01:47:53 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace BotSharp.NLP.Corpus
{
/// <summary>
/// Fasttext labeled data reader
/// </summary>
public class FasttextDataReader
{
public List<Sentence> Read(ReaderOptions options)
{
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))
{
var ms = Regex.Matches(line, @"__label__\w+\s").Cast<Match>().ToList();
sentences.Add(new Sentence
{
// Label = lable,
Text = line
});
}
}
}
return sentences;
}
}
}