public void LoadParsing( string _corpus_path )
{
corpus_path = _corpus_path;
sent2pos = new List<long>();
// Читаем файл filepath построчно, запоминая позиции узлов <sentence ...> в особом
// индексном файле
index_path = System.IO.Path.Combine( System.IO.Path.GetTempPath(), System.IO.Path.GetFileNameWithoutExtension( corpus_path ) + ".XMLINDEX" );
// проверить, если такой файл уже существует и создан после файла парсинга, то можно просто загрузить его содержимое.
if( System.IO.File.Exists( index_path ) && System.IO.File.GetLastWriteTime( corpus_path ) < System.IO.File.GetLastWriteTime( index_path ) )
{
using( System.IO.BinaryReader rdr = new System.IO.BinaryReader( System.IO.File.Open( index_path, System.IO.FileMode.Open ) ) )
{
long filesize = rdr.BaseStream.Length;
long nrec = filesize / sizeof( long );
long[] recs = new long[nrec];
for( long i = 0; i < nrec; ++i )
{
sent2pos.Add( rdr.ReadInt64() );
}
}
}
else
{
using( System.IO.BinaryWriter index_wrt = new System.IO.BinaryWriter( System.IO.File.Open( index_path, System.IO.FileMode.Create ) ) )
{
using( System.IO.FileStream rdr = new System.IO.FileStream( corpus_path, System.IO.FileMode.Open ) )
{
while( true )
{
long pos = rdr.Position;
string line = ReadLine( rdr );
if( string.IsNullOrEmpty( line ) )
{
continue;
}
if( line == "</parsing>" )
break;
if( line.StartsWith( "<sentence" ) )
{
index_wrt.Write( pos );
sent2pos.Add( pos );
}
}
}
}
}
return;
}