Skip to content

Commit 9ed36c8

Browse files
committed
fix(PrologService): avoid redefinition warnings
1 parent 5c63443 commit 9ed36c8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/services/PrologService.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
import java.nio.charset.StandardCharsets;
2323

2424
/**
25-
* PrologService class provides functionality to generate Prolog facts
26-
* and rules from Java objects representing items, recipes, and inventory, and
27-
* to query which items are craftable given the current inventory using Prolog
28-
* logic.
29-
*
25+
* PrologService class provides functionality to generate Prolog facts and rules
26+
* from Java objects representing items, recipes, and inventory, and to query
27+
* which items are craftable given the current inventory using Prolog logic.
28+
*
3029
* <p>
3130
* This service is responsible for:
32-
*
31+
*
3332
* <ul>
3433
* <li>Serializing items and inventory into Prolog facts.</li>
3534
* <li>Writing utility rules for crafting logic in Prolog.</li>
@@ -84,6 +83,14 @@ public HashMap<Item, Integer> craftableItems() throws IOException {
8483
this.toFile(tempFileWriter);
8584
tempFileWriter.close();
8685

86+
// Clear previous Prolog definitions to avoid redefinition warnings
87+
new Query(String.format("abolish(%s/1)", this.baseItemFactName)).hasSolution();
88+
new Query(String.format("abolish(%s/4)", this.ingredientFactName)).hasSolution();
89+
new Query(String.format("abolish(%s/2)", this.itemInInventoryFactName)).hasSolution();
90+
new Query("abolish(craftable_items/2)").hasSolution();
91+
new Query("abolish(maximum_craftable_items/2)").hasSolution();
92+
new Query("abolish(maximum_craftable_items/3)").hasSolution();
93+
8794
// Build query
8895
String consultQuery = String.format("consult(\"%s\")", tempFilePath);
8996
Query consult = new Query(consultQuery);

0 commit comments

Comments
 (0)