MikeTeo.net

A Software Technologist's Blog (Wanna Email Me?)

CLIPS专家系统实现经验

November 29, 2011 By miketeo

此贴原先以英文语言刊登在此处

本人在前些时候有机会推行一项结合CLIPS专家系统的网上订购和实时系统监控的项目。这两样功能无论是以过程语言或是面向对象语言来实现都有相当大的难度。主要是当逻辑因子和监控变量增加时,要评价这些变量的复杂性将会以指数增长的方式变得极其复杂。我们尝试以Python语言来实现这两样功能,可是初步实现这两样功能的源码出现六层次的嵌套IF-ELSE结构,而最终得被迫放弃。若我们坚持以Python来继续实现,想必将来的软件维护将会是一项艰巨的任务。

虽然CLIPS专家系统最终为我们解决了评价变量复杂性的问题,但是本人还是觉得CLIPS专家系统并不适用于所有的逻辑问题。

CLIPS编程范式需要激进的思想转变

必须放弃以过程方式来思考如何实现各个评价操作,各个操作须以个别规则来实现,而这些规则要以识别动作周期的方式在CLIPS环境里运行。当一组的规则匹配成功时,这将引发相关的动作指令。这些指令可能修正这些规则的一些先前条件,而匹配其他(甚至是原先)的规则。另一项值得注意的是要如何设计这些规则,让这些规则能按照您想要的顺序来引发,而要在同时避免添加太多的约束。各个规则的引发条件应该避免依赖其他规则的状态,也就是规则之间的耦合度应该降到最低点。

要有深层的领域知识

在编写CLIPS规则时,您要将您领域里的各个事物运行的知识整理成一系列的规则和模式。您可以尝试进行这一个过程,或是聘请专家来协助您。

执行应该是数据驱动或是模式驱动

当您需要以多个IF语句来推理多个变量时,这执行过程很可能是数据驱动或是模式驱动的。任何有一定规模的领域都会牵涉到十几个或更多的变量,这意味着您的过程或面向对象源码将会呈现网格结构或是包含多层次的嵌套IF-ELSE结构。CLIPS的语言规范能让您针对各组指令而设置个别的引发条件,但是要注意对CLIPS事实和类的规划,CLIPS事实和类的属性应该遵循数据封装的原理来设计。

Python Mutant Tester 0.1.0 Released

November 27, 2011 By miketeo

I have just released Python Mutant Tester (PyMuTester) version 0.1.0 to the public. More details can be found at the Python Mutant Tester project page.

PyMuTester is a testing tool to facilitate mutant testing in Python applications. By making small (and syntactically correct) modifications to the application’s source code and re-run the unit tests over these mutated source code, we can uncover missed checks and loopholes in the test cases.

Read the rest of this entry »

JSON Functions for PostgreSQL

November 5, 2011 By miketeo

Hi, I have released a PostgreSQL contrib module for encoding database rows into JSON structures.

More information can be found at the JSON Functions for PostgreSQL project page.

PostgreSQL Extensions for CLIPS Expert System

October 30, 2011 By miketeo

Hi, I have released a patch to the CLIPS (and also pyclips) expert system which allows CLIPS users to be able to send SQL queries to a PostgreSQL database from the CLIPS environment.

More information can be obtained at the PostgreSQL Extensions for CLIPS Expert System project page.

Large-scale server systems are common in this age. A small computing grid can easily consist of a few hundred nodes. Configuring such a server network can be tedious and usually requires a centralized change management system. If the centralized change management system went down, configuration/updates on the nodes can be affected.

By establishing a standard in your DNS TXT records, we can embed information such as:

  • Remote upstream server’s hostname
  • Listening TCP ports on this hostname
  • Available services (in the form of a bitmask) on this server

For instance, we have a node with a hostname called node123.abc.com which connects to job1.abc.com to communicate information. We can embed the upstream hostname information (job1) in the DNS TXT record for node123. We will also embed the TCP listening ports and the type of services available in job1’s DNS TXT record. Now, the client software on node123 only needs to retrieve node123’s DNS TXT and learns that it needs to connect job1 as its upstream server. It will then retrieve job1’s DNS TXT record and learns of the listening TCP ports on job1 machine that will listen for incoming TCP connections.

Advantages

  • Resilient distribution mechanism built on top of DNS infrastructure with DNS caching and secondary DNS servers.
  • Centralized configuration node can be “hidden” behind a firewall without being exposed on the Internet.
  • Zero-configuration on the nodes as all configuration information could potentially be learnt from the DNS TXT records, so a single installation base can be utilized for all computing nodes. In fact, in theory, you will only need to configure the node’s hostname and IP network information.

Disadvantages

  • Delay in changes from configuration updates to actual change implementation on the server (due to DNS cache)
  • Potential leaks in configuration information as anyone can “lookup” the DNS records.
  • Often requires significant changes in client source code to use DNS TXT records to learn about its connection configuration
  • Limited by the small data size (approx 250 bytes) in the DNS TXT record specification.