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

📄 unit1.pas

📁 人工智能中专家系统源代码,用delphi语言编写的
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, Grids, DBGrids, DBCtrls, StdCtrls, ExtCtrls,
  CheckLst, ADODB;

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    GroupBox1: TGroupBox;
    Panel2: TPanel;
    Panel1: TPanel;
    Panel3: TPanel;
    Splitter1: TSplitter;
    Splitter2: TSplitter;
    ListBox1: TListBox;
    ListBox2: TListBox;
    Button1: TButton;
    Button3: TButton;
    Button5: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Button2: TButton;
    Query1: TADOQuery;
    Table1: TADOTable;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

//uses Unit2,Unit4;
 var sql,strWhere:String;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
 var MyPath:string;
begin

  MyPath:=ExtractFilePath(ParamStr(0));

  Query1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Mypath+'animal.mdb;Persist Security Info=False';
  Table1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Mypath+'animal.mdb;Persist Security Info=False';
  Table1.Active:=True;

  sql:='SELECT 结论 FROM 推导 ';
  with table1 do
  begin
    first;
    while not eof do
    begin
    ListBox1.Items.Add(fieldbyname('条件').asString);
    next;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
 var i:integer;
begin
 i:=0;
 while i<Listbox1.Items.Count do
    if ListBox1.Selected[i] then
      begin
        ListBox2.Items.Add(ListBox1.Items[i]);
        ListBox1.Items.Delete(i);
      end
    Else
      i:=i+1;
end;

procedure TForm1.Button3Click(Sender: TObject);
  var i:integer;
begin
  i:=0;
  while i<Listbox2.Items.Count do
    if ListBox2.Selected[i] then
      ListBox2.Items.Delete(i)
    Else
      i:=i+1;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ListBox2.Items.Clear;
end;

procedure TForm1.Button5Click(Sender: TObject);
var i,tag:integer;
    sqlTest,sWtest,sub:String;
begin
  i:=0;
  strWhere:='';
  while i<Listbox2.Items.Count do
      begin
        if strWhere='' then
        begin
          sWtest:='WHERE 条件 like '+'''%'+ListBox2.Items[i]+'%'' ';
          sWtest:=sWtest+'and '+'条件 not like ''%不'+ListBox2.Items[i]+'%'' ';
          sqlTest:=sql+sWtest;
          tag:=0;
          if Query1.Active then query1.Close;
          query1.SQL.Clear;
          query1.SQL.Add(sqlTest);
          query1.Active:=true;
          query1.First;
          while not query1.Eof do
          begin
            if(Pos('类',query1.fieldbyname('结论').asString)<>0)then
                  begin
                    if strWhere='' then strWhere:='WHERE 条件 like '+'''%'+query1.fieldbyname('结论').asString+'%'' '
                    else strWhere:=strWhere+'or 条件 like '+'''%'+query1.fieldbyname('结论').asString+'%'' ';
                    tag:=1;
                  end;
            query1.Next;
          end;
          if tag=0 then
             begin
               strWhere:='WHERE 条件 like '+'''%'+ListBox2.Items[i]+'%'' ';
               strWhere:=strWhere+'and '+'条件 not like ''%不'+ListBox2.Items[i]+'%'' ';
             end;
        end
        else
        begin
          sWtest:='WHERE 条件 like '+'''%'+ListBox2.Items[i]+'%'' ';
          sWtest:=sWtest+'and '+'条件 not like ''%不'+ListBox2.Items[i]+'%'' ';
          sqlTest:=sql+sWtest;
          if Query1.Active then query1.Close;
          query1.SQL.Clear;
          query1.SQL.Add(sqlTest);
          query1.Active:=true;
          query1.First;
          tag:=0;
          while not query1.Eof do
          begin
            if(Pos('类',query1.fieldbyname('结论').asString)<>0)then
                  begin
                    sub:=query1.fieldbyname('结论').asString;
                    if(Pos(sub,strWhere)<>0)then
                    begin
                       tag:=1;
                       break;
                    end
                    else
                    begin
                       strWhere:=strWhere+'and 条件 like '+'''%'+query1.fieldbyname('结论').asString+'%'' ';
                       tag:=1;
                    end;
                  end;
            query1.Next;
          end;
          if tag=1 then begin i:=i+1;continue; end;
          sWtest:=strWhere+'and 条件 like '+'''%'+ListBox2.Items[i]+'%'' ';
          sWtest:=sWtest+'and '+'条件 not like ''%不'+ListBox2.Items[i]+'%'' ';
          sqlTest:=sql+sWtest;
          if Query1.Active then query1.Close;
          query1.SQL.Clear;
          query1.SQL.Add(sqlTest);
          query1.Active:=true;
          query1.First;
          tag:=0;
          while not query1.Eof do
          begin
            if(Pos('类',query1.fieldbyname('结论').asString)<>0)then
                  begin
                    strWhere:=strWhere+'and 条件 like '+'''%'+query1.fieldbyname('结论').asString+'%'' ';
                    tag:=1;
                  end;
            query1.Next;
          end;
          if tag=0 then
             begin
               strWhere:=strWhere+'and 条件 like '+'''%'+ListBox2.Items[i]+'%'' ';
               strWhere:=strWhere+'and '+'条件 not like ''%不'+ListBox2.Items[i]+'%'' ';
             end;
        end;
      i:=i+1;
      end;
  sql:=sql+strWhere;
  if Query1.Active then query1.Close;
  query1.SQL.Clear;
  query1.SQL.Add(sql);
  query1.Active:=true;
  if query1.RecordCount=1 then
  begin
    form2:=Tform2.create(nil);
    form2.Left:=form1.Left+30;
    form2.Top:=form1.Top+20;
    sub:=query1.fieldbyname('结论').asString;
    tag:=0;
    if sub='金钱豹' then tag:=1
    else if sub='老虎' then tag:=2
    else if sub='长颈鹿' then tag:=3
    else if sub='斑马' then tag:=4
    else if sub='鸵鸟' then tag:=5
    else if sub='企鹅' then tag:=6
    else if sub='信天翁' then tag:=7;
    case tag of
      1:begin
        form2.Image1.Picture.LoadFromFile('图片/金钱豹.jpg');
        form2.Label2.Caption:='金钱豹';
        end;
      2:begin
        form2.Image1.Picture.LoadFromFile('图片/老虎.jpg');
        form2.Label2.Caption:='老虎';
        end;
      3:begin
        form2.Image1.Picture.LoadFromFile('图片/长颈鹿.jpg');
        form2.Label2.Caption:='长颈鹿';
        end;
      4:begin
        form2.Image1.Picture.LoadFromFile('图片/斑马.jpg');
        form2.Label2.Caption:='斑马';
        end;
      5:begin
        form2.Image1.Picture.LoadFromFile('图片/鸵鸟.jpg');
        form2.Label2.Caption:='鸵鸟';
        end;
      6:begin
        form2.Image1.Picture.LoadFromFile('图片/企鹅.jpg');
        form2.Label2.Caption:='企鹅';
        end;
      7:begin
        form2.Image1.Picture.LoadFromFile('图片/信天翁.jpg');
        form2.Label2.Caption:='信天翁';
        end;
      else
        begin
          form2.Image1.Visible:=false;
          form2.DBGrid1.Visible:=true;
        end;
    end;
    form1.Enabled:=false;
  end
  else
    if query1.RecordCount>1 then
       ShowMessage('条件不足,请输入充足的条件')
    else
       showMessage('条件相悖,不存在这样的动物');
  sql:='SELECT 结论 FROM 推导 ';
  ListBox1.Clear;
  ListBox2.Clear;
  with table1 do
  begin
    first;
    while not eof do
    begin
    ListBox1.Items.Add(fieldbyname('条件').asString);
    next;
    end;
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
form4.Show;
end;

end.

⌨️ 快捷键说明

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