我正在编写一个软件项目,以人类语言输入文本并确定它所使用的语言。
我的想法是,我将字典存储在哈希图中,以单词为键,布尔值作为值。
如果文档中有该单词,我将把布尔值调高。
现在,我正在尝试一种阅读这些词典并将它们放入哈希表的好方法,我现在的做法非常幼稚且看起来笨拙,是否有更好的方法来填充这些哈希图?
而且,这些词典非常庞大。也许这不是执行此操作的最佳方法,即像这样连续地填充它们。
我认为一次只考虑一个词典,然后创建一个分数,在该文档中注册的输入文本中有多少个单词,保存该单词,然后处理下一个词典可能会更好。这样可以节省RAM,不是吗?那是一个好的解决方案吗?
到目前为止的代码如下所示:
static HashMap<String, Boolean> de_map = new HashMap<String, Boolean>();
static HashMap<String, Boolean> fr_map = new HashMap<String, Boolean>();
static HashMap<String, Boolean> ru_map = new HashMap<String, Boolean>();
static HashMap<String, Boolean> eng_map = new HashMap<String, Boolean>();
public static void main(String[] args) throws IOException
{
ArrayList<File> sub_dirs = new ArrayList<File>();
final String filePath = "/home/matthias/Desktop/language_detective/word_lists_2";
listf( filePath, sub_dirs );
for(File dir : sub_dirs)
{
String word_holding_directory_path = dir.toString().toLowerCase();
BufferedReader br = new BufferedReader(new FileReader( dir ));
String line = null;
while ((line = br.readLine()) != null)
{
//System.out.println(line);
if(word_holding_directory_path.toLowerCase().contains("/de/") )
{
de_map.put(line, false);
}
if(word_holding_directory_path.toLowerCase().contains("/ru/") )
{
ru_map.put(line, false);
}
if(word_holding_directory_path.toLowerCase().contains("/fr/") )
{
fr_map.put(line, false);
}
if(word_holding_directory_path.toLowerCase().contains("/eng/") )
{
eng_map.put(line, false);
}
}
}
因此,我正在寻找有关如何一次填充它们的建议,以及关于这是否是一种好的方法的意见,或者关于实现这一目标的可能更好的方法的建议。
完整的程序可以在我的GitHub页面上找到。
27日
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句