CLIPS C code,它从事实中读取值(回答,是的值),如果它被称为第一场回答,是什么? [英] CLIPS C code that read a value from the fact (Answer-is value) if it is known first field Answer-is?

查看:172
本文介绍了CLIPS C code,它从事实中读取值(回答,是的值),如果它被称为第一场回答,是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试CLIPS连接到我的C程序。组规则将从外部.clp文件被加载到剪辑。我的新C程序将在固定的时间间隔设置新的事实(例如(温度35℃)),这将重新从一些温度传感器present电流测量。然后,专家系统将会启动,并提出一些结论,并给出了基于测量提供了必要的行动。结论将成为事实的形式(答案 - 为x)。

我怎么能在C变量的形式读CLIPS预期的事实场?例如,如果感兴趣的事实是(答案 - 是,X),如果我知道,第一场就是答案 - 是的,我怎样才能让我的C程序发现这一事实,并读出用X?

举例code,它可以帮助你理解我愿做的是以下内容:

  INT主(INT ARGC,CHAR *的argv []){    无效* theEnv;
    theEnv = CreateEnvironment();
    InitializeEnvironment();
    明确();
    重启();    //加载规则CLIPS
    负载(example.clp);    //设置的事实和开始CLIPS
    AssertString((TemperatureSensor1 35));
    AssertString((TemperatureSensor2 32));
    AssertString((TemperatureSensor2 41));    润(-1L);    //提取专家系统的答案为C
    //从example.clp阅读的事实上产生第二场
    //这是一样的形式(答案 - 是XXX)    // ????????????????????????????
    //这部分我不知道....
    // ????????????????????????????    返回(-1);
  }


解决方案

您可以使用Eval API函数调用发现,所有的事实其实CLIPS查询功能。从评估和演示的返回值将满足您的查询的事实清单。然后可以将每个事实遍历(如果有一个以上的),并使用GetFactSlot函数来检索的事实槽值

I try to connect CLIPS to my C program. Set of rules will be loaded from external .clp file into CLIPS. My new C program will in fixed time intervals set new facts (example (temperature 35C)) which will represent current measurements from some temperature sensors. Then expert system will be started and make some conclusions and give necessary actions based on provided measurements. Conclusions will be in the form of facts (Answer-is x).

How I can read desired fact field from CLIPS in the form of C variable ? For example, if fact of interest is (Answer-is, x), and if I know that first field is Answer-is, how can I make my C program to find that fact and read x ?

Example code which can help you to understand what I would like to do is the following:

int main(int argc,char *argv[]) {

    void *theEnv;
    theEnv = CreateEnvironment();
    InitializeEnvironment();


    Clear();
    Reset();

    // Load rules to CLIPS
    Load("example.clp");

    // Set facts and start CLIPS
    AssertString("(TemperatureSensor1 35)");
    AssertString("(TemperatureSensor2 32)");
    AssertString("(TemperatureSensor2 41)");

    Run(-1L);

    // Extract expert system answer to C
    // Read second field of generated fact from the example.clp
    // which is in the form like (Answer-is xxx)

    // ????????????????????????????
    // This part I do not know ....
    // ????????????????????????????

    return(-1);
  }

解决方案

You can use the Eval API function to invoke the find-all-facts fact CLIPS query function. The return value from Eval will have the list of facts satisfying your query. You can then iterate over each fact (if there is more than one) and use the GetFactSlot function to retrieve the slot values of the fact.

这篇关于CLIPS C code,它从事实中读取值(回答,是的值),如果它被称为第一场回答,是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆