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 package io.github.prolobjectlink.prolog;
27
28
29
30
31
32
33 final class DefaultClauseBuilder extends AbstractBuilder implements PrologClauseBuilder {
34
35 DefaultClauseBuilder(PrologEngine engine) {
36 super(engine);
37 }
38
39 public PrologClauseBuilder begin(PrologTerm term) {
40 append(' ');
41 append(term);
42 return this;
43 }
44
45 public PrologClauseBuilder begin(String functor, PrologTerm... arguments) {
46 append(functor, arguments);
47 return this;
48 }
49
50 public PrologClauseBuilder neck(PrologTerm body) {
51 append(':');
52 append('-');
53 append(' ');
54 append(body);
55 return this;
56 }
57
58 public PrologClauseBuilder neck(String functor, PrologTerm... arguments) {
59 append(':');
60 append('-');
61 append(' ');
62 append(functor, arguments);
63 return this;
64 }
65
66 public PrologClauseBuilder neck(PrologTerm left, String operator, int right) {
67 append(':');
68 append('-');
69 append(' ');
70 append(left, operator, right);
71 return this;
72 }
73
74 public PrologClauseBuilder neck(PrologTerm left, String operator, PrologTerm right) {
75 append(':');
76 append('-');
77 append(' ');
78 append(left, operator, right);
79 return this;
80 }
81
82 public PrologClauseBuilder comma(PrologTerm body) {
83 append(',');
84 append(' ');
85 append(body);
86 return this;
87 }
88
89 public PrologClauseBuilder comma(String functor, PrologTerm... arguments) {
90 append(',');
91 append(' ');
92 append(functor, arguments);
93 return this;
94 }
95
96 public PrologClauseBuilder comma(PrologTerm left, String operator, PrologTerm right) {
97 append(',');
98 append(' ');
99 append(left, operator, right);
100 return this;
101 }
102
103 public String getClauseString() {
104 return "" + builder + "";
105 }
106
107 public boolean clause() {
108 String c = getClauseString();
109 builder = new StringBuilder();
110 return engine.clause(c);
111 }
112
113 public void asserta() {
114 String c = getClauseString();
115 builder = new StringBuilder();
116 engine.asserta(c);
117 }
118
119 public void assertz() {
120 String c = getClauseString();
121 builder = new StringBuilder();
122 engine.assertz(c);
123 }
124
125 public void retract() {
126 String c = getClauseString();
127 builder = new StringBuilder();
128 engine.retract(c);
129 }
130
131 }