前言 我們在學習機器學習相關內容時,一般是不需要我們自己去爬取數據的,因為很多的演算法學習很友好的幫助我們打包好了相關數據,但是這並不代表我們不需要進行學習和瞭解相關知識。在這裡我們瞭解三種數據的爬取:鮮花/明星圖像的爬取、中國藝人圖像的爬取、股票數據的爬取。分別對著三種爬蟲進行學習和使用。 體會 個 ...
本例是通過工具將cobol代碼自動生成java代碼。生成後的java代碼是按照java編程風格生成的,完全屏蔽了cobol的特性。
一個cobol代碼生成了4個java代碼,分別說文件定義,變數定義,語句代碼。
生成的代碼有可執行程式,本例只展示生成的代碼。
cobol代碼
****************************************************************** * Author: * Date: * Purpose: * Tectonics: cobc ****************************************************************** IDENTIFICATION DIVISION. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- PROGRAM-ID. YOUR-PROGRAM-NAME. ENVIRONMENT DIVISION. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- CONFIGURATION SECTION. *----------------------- INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUTFILE1 ASSIGN TO "E:\source\cobol\testdata\src\testfile\input.txt" status fs. SELECT OUTPUT1 ASSIGN TO "E:\source\cobol\testdata\src\testfile\out.txt". *----------------------- DATA DIVISION. FILE SECTION. FD INPUTFILE1. 01 INRECORD. 02 ID1 PIC 9999. 02 NAME1 PIC XXXXXXXX. 02 KEMU1 PIC 9999. 02 CHENGJI1 PIC 99V9. FD OUTPUT1. 01 OUTRECORD. 02 ID2 PIC 9999. 02 NAME2 PIC XXXXXXXX. 02 SUM2 PIC 999V9. 02 HEGE PIC X. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- *----------------------- WORKING-STORAGE SECTION. 01 test1. 02 aa comp-2. 77 EOFMOD PIC 9. 77 FS PIC XX. 01 testred pic xxxx. 01 testred2 REDEFINES testred. 02 testred21 pic 9999. *----------------------- PROCEDURE DIVISION. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- DISPLAY "start exec ". MAIN-PROCEDURE. ** * The main procedure of the program ** move all 'a' to test1. display test1 "b". DISPLAY "Hello world" PERFORM CREATFILEDATA. *合計學生di為1的成績綜合併輸入到出力文件中 perform SUMCHEGNJI. STOP RUN. CREATFILEDATA. OPEN OUTPUT INPUTFILE1. * 1 MOVE 1 TO ID1. ADD 1 TO 1 GIVING ID1. MOVE '張三' to NAME1. MOVE 1 TO KEMU1. MOVE 80.5 TO CHENGJI1. WRITE INRECORD. DISPLAY 'TEST1'. * 1 MOVE 1 TO ID1. MOVE '張三' to NAME1. MOVE 2 TO KEMU1. MOVE 90 TO CHENGJI1. DISPLAY 'TEST21' '.'. IF CHENGJI1 <= 0 THEN DISPLAY 'ERROR' ' END' STOP RUN END-IF. WRITE INRECORD. DISPLAY 'WRITE OK'. CLOSE INPUTFILE1. exit. SUMCHEGNJI. * MOVE 1 TO ID2. * MOVE '張三' to NAME2. MOVE INRECORD TO OUTRECORD. move 0 to SUM2. move ' ' to HEGE. MOVE 0 TO EOFMOD. MOVE '00' TO FS. OPEN INPUT INPUTFILE1. perform until FS NOT = '00' READ INPUTFILE1 DISPLAY FS IF FS = '00' THEN IF ID1 = 1 THEN ADD CHENGJI1 TO SUM2 END-IF END-IF END-PERFORM. CLOSE INPUTFILE1. DISPLAY SUM2 . PERFORM OUTDATA. OUTDATA SECTION. OPEN OUTPUT OUTPUT1. IF SUM2 >= 120 THEN MOVE 'A' TO HEGE ELSE MOVE 'D' TO HEGE END-IF. WRITE OUTRECORD. CLOSE OUTPUT1. text2. exit. ** add other procedures here END PROGRAM YOUR-PROGRAM-NAME.
工具轉換生成的java代碼
1:文件結構
package cobol.filevar; import java.math.BigDecimal; import comm.BaseFile; import comm.StringDataUtils; /** * a 工具轉換生成類 * a 數據文件使用的數據結構定義 * @author lihaibo * */ public class Inputfile1 extends BaseFile{ public int id1 = 0; public String name1 = ""; public int kemu1 = 0; public BigDecimal chengji1 = new BigDecimal(0); public Inputfile1(String fileName) { super(fileName); } public String getData() { String rowData = ""; rowData += StringDataUtils.getData(id1, true); rowData += StringDataUtils.getData(name1, false); rowData += StringDataUtils.getData(kemu1, false); rowData += StringDataUtils.getData(chengji1, false); return rowData; } public void setData(String rowData) { String[] arr = StringDataUtils.split(rowData); id1 = StringDataUtils.getInt(arr, 0); name1 = StringDataUtils.getStr(arr, 1); kemu1 = StringDataUtils.getInt(arr, 2); chengji1 = StringDataUtils.getBigDecimal(arr, 3); } }
文件的定義2
package cobol.filevar; import java.math.BigDecimal; import comm.BaseFile; import comm.StringDataUtils; /** * a 工具轉換生成類 * a 數據文件使用的數據結構定義 * @author lihaibo * */ public class Output1 extends BaseFile{ public int id2 = 0; public String name2 = ""; public BigDecimal sum2 = new BigDecimal(0); public String hege = ""; public Output1(String fileName) { super(fileName); } public String getData() { String rowData = ""; rowData += StringDataUtils.getData(id2, true); rowData += StringDataUtils.getData(name2, false); rowData += StringDataUtils.getData(sum2, false); rowData += StringDataUtils.getData(hege, false); return rowData; } public void setData(String rowData) { String[] arr = StringDataUtils.split(rowData); id2 = StringDataUtils.getInt(arr, 0); name2 = StringDataUtils.getStr(arr, 1); sum2 = StringDataUtils.getBigDecimal(arr, 2); hege = StringDataUtils.getStr(arr, 3); } }
變數定義
package cobol.src; import cobol.filevar.Inputfile1; import cobol.filevar.Output1; /** * a 工具轉換生成類 * a 程式用變數定義 * @author lihaibo * */ public class YourProgramNameVar{ // 文件對象變數 public Inputfile1 inputfile1 = new Inputfile1("E:\\source\\cobol\\testdata\\src\\testfile\\input.txt"); public Output1 output1 = new Output1("E:\\source\\cobol\\testdata\\src\\testfile\\out.txt"); // work內部對象變數 public int aa = 0; public int eofmod = 0; public String fs = ""; public int testred = 0; // Param參數對象變數 }
執行代碼
package cobol.src; import java.math.BigDecimal; import cobol.filevar.Inputfile1; import cobol.filevar.Output1; import comm.FileOpenEnum; /** * a 工具轉換生成類 * a 程式轉換後代碼 * @author lihaibo * */ public class YourProgramNameSrc{ // 程式使用的變數對象 public YourProgramNameVar yourProgramNameVar = new YourProgramNameVar(); // 外部介面方法 public void mainExec(){ System.out.println("start exec "); mainProcedure(); } private int mainProcedure(){ yourProgramNameVar.aa = 0; System.out.println(String.valueOf(yourProgramNameVar.aa) + "b"); System.out.println("Hello world"); if(creatfiledata() == 1){ return 1; } sumchegnji(); return 1; } private int creatfiledata(){ yourProgramNameVar.inputfile1.open(FileOpenEnum.OUTPUT); yourProgramNameVar.inputfile1.id1 = 1; yourProgramNameVar.inputfile1.id1 = 1 + 1; yourProgramNameVar.inputfile1.name1 = "張三"; yourProgramNameVar.inputfile1.kemu1 = 1; yourProgramNameVar.inputfile1.chengji1 = new BigDecimal(80.5); yourProgramNameVar.inputfile1.writeLine(yourProgramNameVar.inputfile1.getData()); System.out.println("TEST1"); yourProgramNameVar.inputfile1.id1 = 1; yourProgramNameVar.inputfile1.name1 = "張三"; yourProgramNameVar.inputfile1.kemu1 = 2; yourProgramNameVar.inputfile1.chengji1 = new BigDecimal(90); System.out.println("TEST21" + "."); if( yourProgramNameVar.inputfile1.chengji1.compareTo(new BigDecimal(0)) <= 0){ System.out.println("ERROR" + " END"); return 1; } yourProgramNameVar.inputfile1.writeLine(yourProgramNameVar.inputfile1.getData()); System.out.println("WRITE OK"); yourProgramNameVar.inputfile1.close(); return 0; } private void sumchegnji(){ yourProgramNameVar.output1.id2 = yourProgramNameVar.inputfile1.id1; yourProgramNameVar.output1.name2 = yourProgramNameVar.inputfile1.name1; yourProgramNameVar.output1.sum2 = new BigDecimal(0); yourProgramNameVar.output1.hege = " "; yourProgramNameVar.eofmod = 0; yourProgramNameVar.fs = "00"; yourProgramNameVar.inputfile1.open(FileOpenEnum.INPUT); while(!( yourProgramNameVar.fs.compareTo("00") != 0)) { yourProgramNameVar.inputfile1.readLine(); yourProgramNameVar.fs = yourProgramNameVar.inputfile1.statu1; System.out.println(yourProgramNameVar.fs); if( yourProgramNameVar.fs.compareTo("00") == 0){ if( yourProgramNameVar.inputfile1.id1 == 1){ yourProgramNameVar.output1.sum2 = yourProgramNameVar.output1.sum2.add(yourProgramNameVar.inputfile1.chengji1); } } } yourProgramNameVar.inputfile1.close(); System.out.println(String.valueOf(yourProgramNameVar.output1.sum2)); outdata(); } private void outdata(){ yourProgramNameVar.output1.open(FileOpenEnum.OUTPUT); if( yourProgramNameVar.output1.sum2.compareTo(new BigDecimal(120)) >= 0){ yourProgramNameVar.output1.hege = "A"; }else{ yourProgramNameVar.output1.hege = "D"; } yourProgramNameVar.output1.writeLine(yourProgramNameVar.output1.getData()); yourProgramNameVar.output1.close(); outdataText2(); } private void outdataText2(){ } }