⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zjm.~pas

📁 delphi开发的一个文书理解系统
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
    
//词法分析代码:
procedure TForm1.Button5Click(Sender: TObject);
  var mstr,str,str1:string;
      fx1,fx2,fx3,cf,s:array[1..600] of string;
      m: array[1..600] of integer;
      len,k,i,guanjianlen: integer;
      CfTexFile:Textfile; // CfTexFile用于指定存放词法分析结果

begin
  CloseFile(f1);
  //diming:array of DimingRecord;
  str:=Memo1.Text;//str为存放文书内容的字符串类型
  len:=StrLen(PChar(string(str)));
  
   //逐行把文本文件中的内容读到字符串数组中
  AssignFile(guanjianci,'cifa.txt');
  Reset(guanjianci);
    t:=0; //用于计算关键词库中记录的行数;
    guanjianlen:=0;
  while not Eof(guanjianci) do
      begin
       t:=t+1;
       guanjianlen:=t;
       Readln(guanjianci,cifastr[t]);
       kongge[t]:=pos(' ',cifastr[t]);
       for i:=1 to kongge[t] do
          begin
          s[t]:=Copy(cifastr[t],1,kongge[t]-1); //将关键词存放在相应的字符串数组s[i]中
          mstr:=cifastr[t];
          m[t]:=StrLen(PChar(string(mstr)));       //计算每一行的长度;
          cf[t]:=Copy(cifastr[t],kongge[t]+1,m[t]-kongge[t]); //将经过词法分析后关键词对应的字符串存放到相应的字符串数组cf[i]中;
          end;
  end;
  CloseFile(guanjianci);


  i:=1; k:=1;
  while i<len  do
  begin
    fx1[i]:=copy(str,i,2);
    fx2[k]:=fx1[i];  //fx2中存放着文书中的每一个汉字;
    i:=i+2;
    k:=k+1;
  end;
 //将关键词对应的字符翻译并存放到字符串型数组fx3[i]中 
  for i:=1 to len do
   begin 
    for k:=1 to guanjianlen do
      begin
        if fx2[i]=s[k] then
            fx3[i]:=cf[k];
        end;
    end;


 
 //在Memo2中显示词法分析结果
     Memo2.Text:='';
   for k:=1 to len do
    Memo2.Text:=Memo2.Text+fx3[k];

    //将词法分析结果保存在相应的文本文档内:
    str1:=Memo2.Text;
    AssignFile(CfTexFile,'cifaresult.txt');
    rewrite(CfTexFile);
    write(CfTexFile,str1) ;
    closefile(CfTexFile);

    //在Memo2中显示词法分析结果
    Memo2.Text:='';
    for k:=1 to len do
    Memo2.Text:=Memo2.Text+fx3[k];
     //form3.show;
     //form1.Hide;
  end;


  

//语法分析程序段:

procedure TForm1.Button6Click(Sender: TObject);
 var
  diming:array of DimingRecord;//地名记录
  strstack:array[1..60] of string;
  GENCODE:array[1..60] of string;
  dongzuo:array[1..60] of string;
  yfstack:array[1..60] of string;
  szstack:array[1..10] of string;
  biaodian:array[1..10] of string;
  zhuanhuan:array[1..10] of string;
  sz,wz:array[1..10] of integer;
  cfstr,str3,str4,str5,str6,unitno,unitlevel,unittype,poslong,poslat,yfstr,bdlen:string;
  i,j,length,k,ch,flag1,flag2:integer;

  begin
    //读取地名库内容:不会做啊!!!!!!!!!!!!!



   //地名数据的存放格式:
      SetLength(diming,20);
      diming[1].id:='40';
      diming[1].name:='庙山';
      diming[1].x:='52495';
      diming[1].y:='62312';

      diming[2].id:='50';
      diming[2].name:='和尚山';
      diming[2].x:='47243';
      diming[2].y:='51426';
                             

      //计算词法分析后字符串的长度:        
      cfstr:=Memo2.Text;
      length:= StrLen(PChar(string(cfstr)));
       //将每个字符赋值给用于语法分析的堆栈:
      for i:=1 to  length do
      begin
      strstack[i]:=Copy(cfstr,i, 1);
      end;

      //判断是否有标点符号,并且记录标点符号的位置:
   flag1:=0;
   for i:=1 to length do
    begin
    if  (strstack[i]='.') then
      begin
        flag1:=flag1+1;    //flag1记录了句子的个数;
        biaodian[flag1]:=inttostr(i) ;
        biaodian[flag1+1]:=inttostr(i+1) ;
      end;
    end; 


    flag1:=flag1+1;
       //开始将每句话存放到字符串数组的各个成员中:
       zhuanhuan[1]:=copy(cfstr,1,strtoint(biaodian[1])-1 );
   for i:=1 to flag1-1 do
       begin
        zhuanhuan[i+1]:=copy(cfstr,strtoint(biaodian[i])+1,strtoint(biaodian[i+1])-strtoint(biaodian[i])-1);
       end;

   for j:=1 to flag1 do
    begin
      yfstr:=scanner(zhuanhuan[j]);
     if (yfstr='1') or (yfstr='2') or (yfstr='3') then
       //以下部分为第一种句式的理解:
      begin
      //部队番号理解,以标点符号为划分:
      for i:=1 to strtoint(biaodian[1]) do
        yfstack[i]:=strstack[i];
      //找到部队编号:
      for i:=1 to 3 do
        begin
          sz[i]:=i;
          szstack[i]:=inttostr(sz[i]);  //记录部队编号:1至3;
        end;

       //确定部队编号在文档中的位置:
       for i:=1 to strtoint(biaodian[1]) do
        begin
          wz[i]:=pos(szstack[i],cfstr);  //wz[i]存放部队标号
        end;
          flag2:=0;
         for i:=1 to strtoint(biaodian[1]) do
          begin
            if wz[i]<>0 then        //wz[i]存放的数字作为部队的起始位置
              flag2:=wz[i]        //记录部队编号的下一个位置                                           
              else flag2:=flag2;
          end;

           
  for  i:=1 to strtoint(biaodian[1]) do
    begin
        for k:=wz[i] to flag2 do   //从部队编号开始判断部队级别
         begin
          if yfstack[k] ='1' then
             unitno:='1';
          if yfstack[k] ='2' then
             unitno:='2';
          if yfstack[k] ='3' then
             unitno:='3';
          if yfstack[k] ='J' then
             unitlevel:='J';
          if yfstack[k] ='S' then
             unitlevel:='S';
          if yfstack[k] ='L' then
             unitlevel:='L';
          if yfstack[k] ='T' then
             unitlevel:='T';
          if yfstack[k] ='Y' then
             unitlevel:='Y';
          if yfstack[k] ='I' then    //连
             unitlevel:='I';
          if yfstack[k] ='P' then
             unitlevel:='P';
          if yfstack[k] ='B' then
             unitlevel:='B';
        end;

    end;
          if unitlevel+unitno='' then
           ShowMessage('部队编号、级别分析处语法错误')
          else
            ShowMessage('部队编号、级别分析处语法正确');
          dongzuo[1]:=GENCODE[1]+GENCODE[2];



         //作战单位类型理解:
         ch:=flag2+1;
         //flag2指定的部队级别的字符串位置,默认部队级别的字符串后是作战单位,所以ch:=flag2作为变量
        while ch<=strtoint(biaodian[1]) do            //biaodian[1]表示第一句话结束,即第一个逗号标点符号;
        begin
          str3:=str3+strstack[ch];
          ch:=ch+1;
          if str3='TXSN' then
            break;
          if str3='TXQB' then
            break;
        end;
          if (str3='TXSN') or (str3='TXQB') then
            ShowMessage('作战单位分析处语法正确')
          else
            ShowMessage('作战单位分析处语法错误');
          dongzuo[2]:=str3;
          unittype:=str3;

        //根据作战单位后是行动的理解:  (ch:=7;)
         while ch<=strtoint(biaodian[1]) do
          begin
          str4:=str4+strstack[ch];
          ch:=ch+1;
          if str4='KS' then
           break;
          if str4='KJ' then
           break;
        end;
          if str4<>'KS' then
             ShowMessage('行进动作分析处语法错误');


        //根据作战行动后是介词的理解:(ch:=8;)
        while ch<=strtoint(biaodian[1]) do
          begin
            str5:=str5+strstack[ch];
            ch:=ch+1;
            if str5='Z' then
              break;
            if str5='Y' then
              break;
          end;
          if str5<>'Z' then
             ShowMessage('介词分析处语法错误');


   //地名理解:(ch:=10;)
        while ch<=strtoint(biaodian[1]) do
          begin
            str6:=str6+strstack[ch];
            ch:=ch+1;
            if str6='40' then    //地名以Record数据类型存放,其用字符串40——90表示
              break;
            if str6='50' then
              break;
            if str6='60' then
              break;
          end;
         if str6<>'60' then
             ShowMessage('介词分析处语法错误');
          Memo3.Text:=str6+inttostr(ch);
          if str6='60' then
            begin
               poslong:=diming[1].x;
               poslat:=diming[1].y;
            end;
       Memo3.Text:='Drawicon'+'('+unittype+','+unitno+unitlevel+','+poslong+','+poslat+')';

   end;
     //else  ShowMessage('语法错误');
   end;//与最外面的循环begin相对应,即用于判断首字母的循环;

      //第二种句式的理解:
      bdlen:=inttostr(strtoint(biaodian[2])-strtoint(biaodian[1]));
      Memo3.Text:=Memo3.Text+yffunction1(zhuanhuan[2],bdlen);

     
 
end;





procedure TForm1.X1Click(Sender: TObject);
begin
 Application.Terminate;  //关闭文件
end;

procedure TForm1.N9Click(Sender: TObject);
begin
Form1.Hide;
Form2.show;

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -