2014-12-17 2 views
-1

배포 지점 아래에 언급 된 번호의 첫 번째 부분 만 읽으 려합니다. 즉, "-5.344029659372277"이며 이러한 모든 점을 java의 배열에 저장하십시오.java의 텍스트 파일에서 필요한 데이터의 일부만 읽는 방법 (double) [double] [

Using fixed random seed for repeat ability. 
............................................ 
Constructing inference engine of class blog.engine.SamplingEngine 
Constructing sampler of class blog.sample.LWSampler 
Evidence: [] 
Query: [x, y, z] 
Running for 20 samples... 
Query Reporting interval is 10000 
======== LW Trial Stats ========= 
Log of average likelihood weight (this trial): -4.440892098500626E-16 
Average likelihood weight (this trial): 0.9999999999999996 
Fraction of consistent worlds (this trial): 1.0 
Fraction of consistent worlds (running avg, all trials): 1.0 
======== Query Results ========= 
Number of samples: 20 
Distribution of values for x 
-5.344029659372277 0.05000000000000003 
-3.6282706290477384 0.05000000000000003 
-3.497553178865327 0.05000000000000003 
-0.8324886197923229 0.05000000000000003 
Distribution of values for y 
-3.8401834274154405 0.05000000000000003 
-2.8617608524112454 0.05000000000000003 
-2.8211880095793065 0.05000000000000003 
-2.1727081725855695 0.05000000000000003 
Distribution of values for z 
-3.6803989664398955 0.05000000000000003 
-2.3049623281250717 0.05000000000000003 
-2.300277789550218 0.05000000000000003 
-2.110311642917156 0.05000000000000003 
======== Done ======== 

이것은 BLOG 프로그램에서 output.txt를 찾는 방법입니다.

+0

는 위에서 언급 한 데이터가 일정 파일의 특정 시작 위치/인덱스를 가지고 있는가? –

+0

시도한 것을 보여줄 수 있습니까? – WannaBeCoder

+0

텍스트 파일의 시작 부분에서 공통된 15 줄의 텍스트가 있고 배포 지점이 시작됩니다. BLOG 프로그래밍 언어의 출력을 텍스트 파일로 가져 와서 이것을 Java 프로그램으로 읽으려고합니다. – Balu

답변

0

여기에 예가 나와 있습니다. 설명은 코드입니다.

public static void main(String[] args) throws FileNotFoundException, IOException { 
    List<String> xValues = new ArrayList<String>(); 
    List<String> yValues = new ArrayList<String>(); 
    List<String> zValues = new ArrayList<String>(); 
    //convert these lists of String to double yourself. 

    xValues = readValuesFor("x"); 
    yValues = readValuesFor("y"); 
    zValues = readValuesFor("z"); 

    //print contents 
    System.out.println("X values: "); 
    for (final String x : xValues) { 
     System.out.println(x); 
    } 

    System.out.println("Y values: "); 
    for (final String y : yValues) { 
     System.out.println(y); 
    } 

    System.out.println("Z values:"); 
    for (final String z : zValues) { 
     System.out.println(z); 
    } 
} 

public static List<String> readValuesFor(String variableName) throws FileNotFoundException, IOException { 
    final List<String> result = new ArrayList<String>(); 
    final BufferedReader br = new BufferedReader(new FileReader("output.txt")); //change file name and path to yours 
    String line; 
    //read through file until you find a line that end with the variable x ,y, or z 
    while ((line = br.readLine()) != null) { 
     if (line.endsWith("for "+variableName.trim())) { 
      break; 
     } 
    } 

    if (!variableName.equals("z")) { //if variable is x or y 
     while (!(line = br.readLine()).contains("Distribution")) { 
      //read the lines between line ending in letters x or y and line containing word "Distribution" 
      final String[] values = line.split(" "); 
      result.add(values[0]); //get the first value of the split 
     } 
    } 
    else{ 
     while (!(line = br.readLine()).contains("Done")) { //if variable is z 
      //read the lines between line ending with letter z and line containing word "Done" 
      final String[] values = line.split(" "); 
      result.add(values[0]); //get the first value of the split 
     } 
    } 
    return result; //array with first values as string 
} 

출력은 다음과 같습니다

 
X values: 
-5.344029659372277 
-3.6282706290477384 
-3.497553178865327 
-0.8324886197923229 
Y values: 
-3.8401834274154405 
-2.8617608524112454 
-2.8211880095793065 
-2.1727081725855695 
Z values: 
-3.6803989664398955 
-2.3049623281250717 
-2.300277789550218 
-2.110311642917156 
+0

분할이 작동하지 않는다. 두 값을 모두 얻고있다. – Balu