gpt4 book ai didi

java - 在 2 个输入文件上使用方法 - 第二个是多次打印 - Java

转载 作者:行者123 更新时间:2023-12-01 16:05:00 25 4
gpt4 key购买 nike

我有以下代码可以在文本中读取,作为二元组存储在 HashMap 中(使用其他方法按频率对它们进行排序并进行 v.v. 基本加法平滑。

我让它非常适合一种语言输入文件(英语),然后我想使用相同的方法将其扩展为第二种语言输入文件(日语 - 不;我想它是什么),但使用日语二元组hashmap 使用 diff 连续打印 3 次。值(value)观。

我尝试在输入文件中使用差异文本,确保文本中没有间隙等。我还在代码的日语部分的某些位置放置了打印语句,看看是否能得到任何线索但所有打印语句每次都会打印,所以我无法确定它是否在某个地方循环。

我已经用细牙梳子浏览过了,但显然我错过了一些东西,并且在这里慢慢变得疯狂 - 任何帮助将不胜感激。提前致谢...

package languagerecognition2;
import java.lang.String;
import java.io.InputStreamReader;
import java.util.*;
import java.util.Iterator;
import java.util.List.*;
import java.util.ArrayList;
import java.util.AbstractMap.*;
import java.lang.Object;
import java.io.*;
import java.util.Enumeration;
import java.util.Arrays;
import java.lang.Math;


public class Main { /**

public static void main(String[] args) {

//training English -----------------------------------------------------------------
File file = new File("english1.txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;

try
{
reader = new BufferedReader(new FileReader(file));
String test = null;
//test = reader.readLine();
// repeat until all lines are read
while ((test = reader.readLine()) != null)

{
test = test.toLowerCase();
char[] charArrayEng = test.toCharArray();
HashMap<String, Integer> hashMapEng = new HashMap<String, Integer>(bigrams(charArrayEng));


LinkedHashMap<String, Integer> sortedListEng = new LinkedHashMap<String, Integer>(sort(hashMapEng));


int sizeEng=sortedListEng.size();
System.out.println("Total count of English bigrams is " + sizeEng);
LinkedHashMap<String, Integer> smoothedListEng = new LinkedHashMap<String, Integer>(smooth(sortedListEng, sizeEng));
//print linkedHashMap to check values
Set set= smoothedListEng.entrySet();
Iterator iter = set.iterator ( ) ;
System.out.println("Beginning English");

while ( iter.hasNext())
{
Map.Entry entry = ( Map.Entry ) iter.next ( ) ;
Object key = entry.getKey ( ) ;
Object value = entry.getValue ( ) ;

System.out.println( key+" : " + value);

}
System.out.println("End English");
}//end while

}//end try
catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
try
{
if (reader != null)
{
reader.close();
}
} catch (IOException e)
{
e.printStackTrace();
}
}


//End training English-----------------------------------------------------------

//Training japanese--------------------------------------------------------------

File file2 = new File("japanese1.txt");
StringBuffer contents2 = new StringBuffer();
BufferedReader reader2 = null;

try
{
reader2 = new BufferedReader(new FileReader(file2));
String test2 = null;

//repeat until all lines are read
while ((test2 = reader2.readLine()) != null)
{

test2 = test2.toLowerCase();
char[] charArrayJap = test2.toCharArray();

HashMap<String, Integer> hashMapJap = new HashMap<String, Integer>(bigrams(charArrayJap));
//System.out.println( "bigrams stage");

LinkedHashMap<String, Integer> sortedListJap = new LinkedHashMap<String, Integer>(sort(hashMapJap));
//System.out.println( "sort stage");

int sizeJap=sortedListJap.size();
//System.out.println("Total count of Japanese bigrams is " + sizeJap);

LinkedHashMap<String, Integer> smoothedListJap = new LinkedHashMap<String, Integer>(smooth(sortedListJap, sizeJap));
System.out.println( "smooth stage");
//print linkedHashMap to check values

Set set2= smoothedListJap.entrySet();
Iterator iter2 = set2.iterator();
System.out.println("Beginning Japanese");

while ( iter2.hasNext())
{
Map.Entry entry2 = ( Map.Entry ) iter2.next ( ) ;
Object key = entry2.getKey ( ) ;
Object value = entry2.getValue ( ) ;

System.out.println( key+" : " + value);
}//end while
System.out.println("End Japanese");
}//end while


}//end try
catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
try
{
if (reader2 != null)
{
reader2.close();
}
} catch (IOException e)
{
e.printStackTrace();
}

}

//end training Japanese---------------------------------------------------------


} //end main (inner)

最佳答案

我认为这是一个输入文件问题,所以我现在已经解决了。

关于java - 在 2 个输入文件上使用方法 - 第二个是多次打印 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2798116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com