usingSystem;
usingSystem.Collections.Generic;
usingSystem.IO;
usingSystem.Linq;
usingSystem.Text;
namespacecn.Laiyunqing
{
publicclassnStarDict
{
privatestringidxFile;
privatestringdictFile;
publicnStarDict(stringidx,stringdict)
{
this.idxFile=idx;
this.dictFile=dict;
}
publicList<string>Words(stringkey)
{
List<string>words=newList<string>();
FileStreamfsIdx=newFileStream(this.idxFile,FileMode.Open,FileAccess.Read);
BinaryReaderbrIdx=newBinaryReader(fsIdx,Encoding.UTF8);
byte[]ch=newbyte[4096];
byteend=(byte)'';
intindex=0;
for(index=0;index<4096;index++)
ch[index]=(byte)'';
index=0;
while(true)
{
try
{
ch[index]=brIdx.ReadByte();
index++;
}
catch(EndOfStreamException)
{
break;
}
if(ch[index-1]==end)
{
byte[]word=newbyte[index-1];
for(inti=0;i<index-1;i++)
{
word[i]=ch[i];
ch[i]=0;
}
stringqueryString=Encoding.UTF8.GetString(word);
if(queryString.StartsWith(key,true,System.Globalization.CultureInfo.CurrentCulture))
{
words.Add(queryString);
}
}
}
brIdx.Close();
fsIdx.Close();
returnwords;
}
publicstringResult(stringoriginalText)
{
stringtranslatedText=string.Empty;
FileStreamfsIdx=newFileStream(this.idxFile,FileMode.Open,FileAccess.Read);
BinaryReaderbrIdx=newBinaryReader(fsIdx,Encoding.UTF8);
FileStreamfsDict=newFileStream(this.dictFile,FileMode.Open,FileAccess.Read);
BinaryReaderbrDict=newBinaryReader(fsDict,Encoding.UTF8);
byte[]ch=newbyte[4096];
byteend=(byte)'';
intpos,size;
intindex=0;
for(index=0;index<4096;index++)
ch[index]=(byte)'';
index=0;
while(true)
{
try
{
ch[index]=brIdx.ReadByte();
index++;
}
catch(EndOfStreamException)
{
break;
}
if(ch[index-1]==end)
{
byte[]word=newbyte[index-1];
for(inti=0;i<index-1;i++)
{
word[i]=ch[i];
ch[i]=0;
}
stringqueryString=Encoding.UTF8.GetString(word);
index=0;
byte[]tmp=brIdx.ReadBytes(4);
pos=tmp[3]+(tmp[2]<<8)+(tmp[1]<<16)+(tmp[0]<<24);
tmp=brIdx.ReadBytes(4);
size=tmp[3]+(tmp[2]<<8)+(tmp[1]<<16)+(tmp[0]<<24);
byte[]content=brDict.ReadBytes(size);
stringoutText=Encoding.UTF8.GetString(content).Replace(" ","</br>")+"</br>";
//是查询的单词
if(queryString==originalText)
{
translatedText=outText;
break;
}
}
}
brDict.Close();
fsDict.Close();
brIdx.Close();
fsIdx.Close();
returntranslatedText;
}
}
}
usingSystem.Collections.Generic;
usingSystem.IO;
usingSystem.Linq;
usingSystem.Text;
namespacecn.Laiyunqing
{
publicclassnStarDict
{
privatestringidxFile;
privatestringdictFile;
publicnStarDict(stringidx,stringdict)
{
this.idxFile=idx;
this.dictFile=dict;
}
publicList<string>Words(stringkey)
{
List<string>words=newList<string>();
FileStreamfsIdx=newFileStream(this.idxFile,FileMode.Open,FileAccess.Read);
BinaryReaderbrIdx=newBinaryReader(fsIdx,Encoding.UTF8);
byte[]ch=newbyte[4096];
byteend=(byte)'';
intindex=0;
for(index=0;index<4096;index++)
ch[index]=(byte)'';
index=0;
while(true)
{
try
{
ch[index]=brIdx.ReadByte();
index++;
}
catch(EndOfStreamException)
{
break;
}
if(ch[index-1]==end)
{
byte[]word=newbyte[index-1];
for(inti=0;i<index-1;i++)
{
word[i]=ch[i];
ch[i]=0;
}
stringqueryString=Encoding.UTF8.GetString(word);
if(queryString.StartsWith(key,true,System.Globalization.CultureInfo.CurrentCulture))
{
words.Add(queryString);
}
}
}
brIdx.Close();
fsIdx.Close();
returnwords;
}
publicstringResult(stringoriginalText)
{
stringtranslatedText=string.Empty;
FileStreamfsIdx=newFileStream(this.idxFile,FileMode.Open,FileAccess.Read);
BinaryReaderbrIdx=newBinaryReader(fsIdx,Encoding.UTF8);
FileStreamfsDict=newFileStream(this.dictFile,FileMode.Open,FileAccess.Read);
BinaryReaderbrDict=newBinaryReader(fsDict,Encoding.UTF8);
byte[]ch=newbyte[4096];
byteend=(byte)'';
intpos,size;
intindex=0;
for(index=0;index<4096;index++)
ch[index]=(byte)'';
index=0;
while(true)
{
try
{
ch[index]=brIdx.ReadByte();
index++;
}
catch(EndOfStreamException)
{
break;
}
if(ch[index-1]==end)
{
byte[]word=newbyte[index-1];
for(inti=0;i<index-1;i++)
{
word[i]=ch[i];
ch[i]=0;
}
stringqueryString=Encoding.UTF8.GetString(word);
index=0;
byte[]tmp=brIdx.ReadBytes(4);
pos=tmp[3]+(tmp[2]<<8)+(tmp[1]<<16)+(tmp[0]<<24);
tmp=brIdx.ReadBytes(4);
size=tmp[3]+(tmp[2]<<8)+(tmp[1]<<16)+(tmp[0]<<24);
byte[]content=brDict.ReadBytes(size);
stringoutText=Encoding.UTF8.GetString(content).Replace(" ","</br>")+"</br>";
//是查询的单词
if(queryString==originalText)
{
translatedText=outText;
break;
}
}
}
brDict.Close();
fsDict.Close();
brIdx.Close();
fsIdx.Close();
returntranslatedText;
}
}
}
本文介绍了一个名为nStarDict的.NET类库,该工具用于读取星愿词典(.dict)文件,并提供词典查询功能。通过该类库可以获取指定词汇的所有可能匹配项及其对应的解释。
1万+

被折叠的 条评论
为什么被折叠?



