`
isiqi
  • 浏览: 16825588 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

stardict字典文件格式识别类

阅读更多
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;
}

}
}
分享到:
评论

相关推荐

    stardict字典-汉英

    星际译王的词典文件是二进制格式,包含词汇、释义、例句等信息,以提高查词速度。 在描述中提到,你需要将解压后的文件放在“/usr/share/stardict/dict/”目录下。这个路径通常是Linux系统中星际译王查找词典文件的...

    stardict字典-oxford

    标题中的"stardict字典-oxford"指的是这款软件中的一款词典资源,即牛津词典。牛津词典是世界上最权威的英语词典之一,提供详尽的英语词汇解释、例句、短语和用法指导,对于学习者来说是不可或缺的工具。 在描述中...

    DictUnifer

    这款小巧的应用程序可以将 Stardict 字典文件转换为 Mac Dictionary 能识别的格式,让 Mac 用户也能享受到 Stardict 的强大功能。通过 DictUnifer,用户只需简单几步操作,就能把 Stardict 字典导入到 Mac 的 ...

    英汉汉英专业词典+_stardict

    这些文件包含了词典的正文、索引和字典格式信息。 4. **更新软件索引**:完成文件复制后,需要更新StarDict软件的索引以使其能够识别新添加的词典。通常,可以通过启动StarDict程序,然后在设置或管理界面中进行...

    星际快译-stardict

    这些字典文件通常以压缩包的形式提供,下载后需要解压到星际快译的安装目录下的“dic”子目录中,以便软件能识别并加载这些新词库。 安装stardict-3.0.0.exe这个执行文件是使用星际快译的第一步。安装过程中,用户...

    怎么更换iPad默认字体和字典.docx

    如果你想使用其他词典,如英汉词典,你可以利用stardict转成OSX 10.6的字典格式,然后将文件重命名为New Oxford American Dictionary,以此来“欺骗”iBooks使用你指定的词典。需要注意的是,这种方法可能导致失去...

    dictd 中英/英中 xdict词典

    例如,用户可以先解压收到的两个压缩文件,然后使用`cat`命令将解压后的文件合并,再重新打包成dictd服务器可以识别的格式。 在安装和配置这些词典后,用户可以通过dictd服务器提供的查询接口进行词汇查找。常见的...

    linux星际译王part1

    在Linux操作系统中,星际译王(Stardict)是一款非常受欢迎的开源词典软件,它提供了丰富的词库和便捷的翻译功能。...记得按照提示将所有文件放在同一目录下,以确保星际译王能够正确识别和使用这些词库。

Global site tag (gtag.js) - Google Analytics