📄 dictionaryhelper.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using WordNetParser.Objects;
using System.IO;
namespace WordNetParser.Helpers
{
internal class DictionaryHelper
{
private static long lastWordIndex = 0;
private static List<string> completedFiles = new List<string>();
#region GetDefinition
internal static Dictionary<string, List<Definition>> GetDefinition( string word )
{
Dictionary<string, List<Definition>> retVal = new Dictionary<string, List<Definition>>();
List<string> fileListIndex = DbFileHelper.GetIndexForType( DbPartOfSpechType.All );
List<string> fileListData = DbFileHelper.GetDBaseForType( DbPartOfSpechType.All );
for( int i = 0; i < fileListIndex.Count; i++ )
{
long offset = FileParser.FastSearch( word.ToLower(), fileListIndex[ i ] );
if( offset > 0 )
{
Index idx = FileParser.ParseIndex( offset, fileListIndex[ i ], null );
foreach( long synSetOffset in idx.SynSetsOffsets )
{
try
{
Definition def = FileParser.ParseDefinition( synSetOffset, fileListData[ i ], word );
string wordKey = string.Join( ", ", def.Words.ToArray() );
if( !retVal.ContainsKey( wordKey ) )
retVal.Add( wordKey, new List<Definition>() );
retVal[ wordKey ].Add( def );
}
catch( Exception ex )
{
string message = ex.Message;
}
}
}
}
return retVal;
}
#endregion GetDefinition
#region GetNextWord
internal static string GetNextWord()
{
string retVal = string.Empty;
List<string> indexFiles = DbFileHelper.GetIndexForType( DbPartOfSpechType.All );
foreach( string indexFile in indexFiles )
{
if( completedFiles.Contains( indexFile ) )
continue;
using( FileStream fs = File.OpenRead( indexFile ) )
{
string line = string.Empty;
do
{
fs.Seek( lastWordIndex, SeekOrigin.Begin );
while( fs.ReadByte() != '\n' && fs.Position < fs.Length )
{
fs.Seek( 1, SeekOrigin.Current );
}
byte[] btData = new byte[ Constants.KEY_LEN ];
int count = fs.Read( btData, 0, btData.Length );
lastWordIndex = ( fs.Position - count ) + 1;
string readData = Encoding.Default.GetString( btData );
int actualLineLength = readData.IndexOf( '\n' );
lastWordIndex = ( fs.Position - count ) + actualLineLength;
retVal = readData.Split( Constants.Tokenizer )[ 0 ];
}
while( string.IsNullOrEmpty( retVal ) );
if( fs.Position == fs.Length )
{
completedFiles.Add( indexFile );
lastWordIndex = 0L;
}
}
if( !string.IsNullOrEmpty( retVal ) )
break;
}
return retVal;
}
#endregion GetNextWord
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -