@@ -22,18 +22,6 @@ The search engine:
2222
2323## Creating a Search Engine
2424
25- === "Python"
26-
27- ```python
28- import apyds
29-
30- # Create with default sizes
31- search = apyds.Search()
32-
33- # Create with custom sizes
34- search = apyds.Search(limit_size=1000, buffer_size=10000)
35- ```
36-
3725=== "TypeScript"
3826
3927 ```typescript
@@ -46,6 +34,18 @@ The search engine:
4634 const search2 = new Search(1000, 10000);
4735 ```
4836
37+ === "Python"
38+
39+ ```python
40+ import apyds
41+
42+ # Create with default sizes
43+ search = apyds.Search()
44+
45+ # Create with custom sizes
46+ search = apyds.Search(limit_size=1000, buffer_size=10000)
47+ ```
48+
4949=== "C++"
5050
5151 ```cpp
@@ -64,20 +64,6 @@ The search engine:
6464
6565Use the ` add() ` method to add rules and facts to the knowledge base.
6666
67- === "Python"
68-
69- ```python
70- import apyds
71-
72- search = apyds.Search()
73-
74- # Add a fact
75- search.add("(parent john mary)")
76-
77- # Add a rule with premises
78- search.add("(father `X `Y)\n----------\n(parent `X `Y)\n")
79- ```
80-
8167=== "TypeScript"
8268
8369 ```typescript
@@ -92,6 +78,20 @@ Use the `add()` method to add rules and facts to the knowledge base.
9278 search.add("(father `X `Y)\n----------\n(parent `X `Y)\n");
9379 ```
9480
81+ === "Python"
82+
83+ ```python
84+ import apyds
85+
86+ search = apyds.Search()
87+
88+ # Add a fact
89+ search.add("(parent john mary)")
90+
91+ # Add a rule with premises
92+ search.add("(father `X `Y)\n----------\n(parent `X `Y)\n")
93+ ```
94+
9595=== "C++"
9696
9797 ```cpp
@@ -108,6 +108,23 @@ Use the `add()` method to add rules and facts to the knowledge base.
108108
109109The ` execute() ` method performs one round of inference. It matches all rules against all facts and generates new conclusions.
110110
111+ === "TypeScript"
112+
113+ ```typescript
114+ import { Search } from "atsds";
115+
116+ const search = new Search();
117+ search.add("(father `X `Y)\n----------\n(parent `X `Y)\n");
118+ search.add("(father john mary)");
119+
120+ const count = search.execute((rule) => {
121+ console.log(`Found: ${rule.toString()}`);
122+ return false; // Continue searching
123+ });
124+
125+ console.log(`Generated ${count} new facts`);
126+ ```
127+
111128=== "Python"
112129
113130 ```python
@@ -126,23 +143,6 @@ The `execute()` method performs one round of inference. It matches all rules aga
126143 print(f"Generated {count} new facts")
127144 ```
128145
129- === "TypeScript"
130-
131- ```typescript
132- import { Search } from "atsds";
133-
134- const search = new Search();
135- search.add("(father `X `Y)\n----------\n(parent `X `Y)\n");
136- search.add("(father john mary)");
137-
138- const count = search.execute((rule) => {
139- console.log(`Found: ${rule.toString()}`);
140- return false; // Continue searching
141- });
142-
143- console.log(`Generated ${count} new facts`);
144- ```
145-
146146=== "C++"
147147
148148 ```cpp
@@ -169,36 +169,6 @@ The callback receives each newly inferred rule and should return:
169169
170170To search until a specific target is found:
171171
172- === "Python"
173-
174- ```python
175- import apyds
176-
177- search = apyds.Search(1000, 10000)
178-
179- # Set up propositional logic
180- search.add("(`P -> `Q) `P `Q") # Modus ponens
181- search.add("(`p -> (`q -> `p))") # Axiom 1
182- search.add("((`p -> (`q -> `r)) -> ((`p -> `q) -> (`p -> `r)))") # Axiom 2
183- search.add("(((! `p) -> (! `q)) -> (`q -> `p))") # Axiom 3
184- search.add("(! (! X))") # Premise
185-
186- target = apyds.Rule("X")
187-
188- while True:
189- found = False
190- def check(candidate):
191- nonlocal found
192- if candidate == target:
193- print(f"Found: {candidate}")
194- found = True
195- return True
196- return False
197- search.execute(check)
198- if found:
199- break
200- ```
201-
202172=== "TypeScript"
203173
204174 ```typescript
@@ -229,24 +199,54 @@ To search until a specific target is found:
229199 }
230200 ```
231201
232- ## Configuration Methods
202+ === "Python"
233203
234- ### Set Limit Size
204+ ```python
205+ import apyds
235206
236- Controls the maximum size for each stored rule/fact:
207+ search = apyds.Search(1000, 10000)
237208
238- === "Python"
209+ # Set up propositional logic
210+ search.add("(`P -> `Q) `P `Q") # Modus ponens
211+ search.add("(`p -> (`q -> `p))") # Axiom 1
212+ search.add("((`p -> (`q -> `r)) -> ((`p -> `q) -> (`p -> `r)))") # Axiom 2
213+ search.add("(((! `p) -> (! `q)) -> (`q -> `p))") # Axiom 3
214+ search.add("(! (! X))") # Premise
239215
240- ```python
241- search.set_limit_size(2000)
216+ target = apyds.Rule("X")
217+
218+ while True:
219+ found = False
220+ def check(candidate):
221+ global found
222+ if candidate == target:
223+ print(f"Found: {candidate}")
224+ found = True
225+ return True
226+ return False
227+ search.execute(check)
228+ if found:
229+ break
242230 ```
243231
232+ ## Configuration Methods
233+
234+ ### Set Limit Size
235+
236+ Controls the maximum size for each stored rule/fact:
237+
244238=== "TypeScript"
245239
246240 ```typescript
247241 search.set_limit_size(2000);
248242 ```
249243
244+ === "Python"
245+
246+ ```python
247+ search.set_limit_size(2000)
248+ ```
249+
250250=== "C++"
251251
252252 ```cpp
@@ -257,18 +257,18 @@ Controls the maximum size for each stored rule/fact:
257257
258258Controls the internal buffer size for operations:
259259
260- === "Python"
261-
262- ```python
263- search.set_buffer_size(20000)
264- ```
265-
266260=== "TypeScript"
267261
268262 ```typescript
269263 search.set_buffer_size(20000);
270264 ```
271265
266+ === "Python"
267+
268+ ```python
269+ search.set_buffer_size(20000)
270+ ```
271+
272272=== "C++"
273273
274274 ```cpp
@@ -279,18 +279,18 @@ Controls the internal buffer size for operations:
279279
280280Clears all rules and facts:
281281
282- === "Python"
283-
284- ```python
285- search.reset()
286- ```
287-
288282=== "TypeScript"
289283
290284 ```typescript
291285 search.reset();
292286 ```
293287
288+ === "Python"
289+
290+ ```python
291+ search.reset()
292+ ```
293+
294294=== "C++"
295295
296296 ```cpp
0 commit comments