File: test_clause_eval.c

package info (click to toggle)
ladr 0.0.200902a-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,400 kB
  • ctags: 7,168
  • sloc: ansic: 59,953; perl: 1,006; python: 620; makefile: 403; sh: 86; csh: 58; modula3: 13
file content (76 lines) | stat: -rw-r--r-- 2,212 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*  Copyright (C) 2006, 2007 William McCune

    This file is part of the LADR Deduction Library.

    The LADR Deduction Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU General Public License,
    version 2.

    The LADR Deduction Library is distributed in the hope that it will be
    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with the LADR Deduction Library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "../ladr/top_input.h"
#include "../ladr/clause_eval.h"
#include "../ladr/weight.h"

#define PROGRAM_NAME    "test_clause_eval"
#include "../VERSION_DATE.h"

int main(int argc, char **argv)
{
  FILE *rule_fp;
  Topform c;
  Term t;
  int i;
  Clause_eval compiled_rule;
  Plist rules = NULL;

  init_standard_ladr();
  init_weight(NULL, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0);
  i = register_attribute("label",  STRING_ATTRIBUTE);  /* ignore these */
  i = register_attribute("answer", TERM_ATTRIBUTE);  /* ignore these */

  rule_fp = fopen(argv[1], "r");
  if (rule_fp == NULL)
    fatal_error("test_clause_eval, rule file cannot be opened for reading");

  t = read_term(rule_fp, stderr);  /* get first rule */

  while (t != NULL) {
    compiled_rule = compile_clause_eval_rule(t);
    rules = plist_append(rules, compiled_rule);
    fwrite_term_nl(stdout, t);
    zap_term(t);
    t = read_term(rule_fp, stderr);
  }
  fclose(rule_fp);

  /* Evaluate each clause on stdin. */

  c = read_clause(stdin, stderr);

  while (c != NULL && !end_of_list_clause(c)) {
    Plist p;
    c->weight = clause_weight(c->literals);
    for (p = rules; p; p = p->next) {
      Clause_eval rule = p->v;
      BOOL result = eval_clause_in_rule(c, rule);
      printf("%d  (wt=%.3f) : ", result, c->weight);
      fwrite_clause(stdout, c, CL_FORM_BARE);
    }
    printf("\n");
    
    zap_topform(c);
    c = read_clause(stdin, stderr);
  }
  
  exit(0);
}  /* main */