diff --git a/.idea/misc.xml b/.idea/misc.xml
index 07115cd..f3f4fc6 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/Icing-On-Graph.iml b/Icing-On-Graph.iml
index 1bb3d1a..b88e7c6 100644
--- a/Icing-On-Graph.iml
+++ b/Icing-On-Graph.iml
@@ -23,5 +23,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/RecipeInstructions.java b/src/RecipeInstructions.java
new file mode 100644
index 0000000..79ebb35
--- /dev/null
+++ b/src/RecipeInstructions.java
@@ -0,0 +1,107 @@
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Scanner;
+import java.util.regex.Pattern;
+
+public class RecipeInstructions
+{
+ public static void main(String[] args)
+ {
+ String userInstruction;
+
+ ArrayList ingredients = new ArrayList<>();
+ RecipeTree fullInstructions = new RecipeTree();
+ Scanner userInput = new Scanner(System.in);
+
+ do
+ {
+ System.out.println("Enter instruction: ");
+ userInstruction = userInput.nextLine();
+
+ RecipeCreation(userInstruction,fullInstructions);
+ fullInstructions.printTree();
+ System.out.println(fullInstructions.sortTopology());
+
+ } while(!userInstruction.equalsIgnoreCase("done"));
+ }
+
+ //Magical Regex
+ public static boolean patternMatch(String pattern, String input)
+ {
+ Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
+ return p.matcher(input).find();
+ }
+
+ // This creates an action + children
+ public static void RecipeCreation(String instructionIn, RecipeTree fullInstructions)
+ {
+ //Need to not hardcode verbs maybe a global variable for it? etc etc
+ String[] verbs = {"add", "mix", "stir", "wait", "bake", "heat", "sift", "boil", "melt", "fry", "cool",
+ "remove", "eat", "cut"};
+ //this is where it gets juicy
+ //FIRST WE FIND A VERB FOR THE ACTION
+ for (String verb : verbs)
+ {
+ //we regex the input for the thing
+ if (patternMatch(verb, instructionIn))
+ {
+ //get Action
+ RecipeNode newAction = new RecipeNode(verb, 0);
+ //Split after verb
+ //this is where we split the string
+ String[] split = instructionIn.split(verb);
+ //We get the words only POG
+ String[] words = split[1].split(" ");
+ construct_children(newAction, words);
+ //we add the thing to the tree (this also needs to be checked for WHERE it gets added)
+ fullInstructions.actionAdd(newAction);
+ }
+ }
+
+ }
+
+ //MMMMM children yes??
+ //Seriously this takes the action node and the rest of the words in sentence and adds them as children
+ public static void construct_children(RecipeNode node, String[] words)
+ {
+ int Number = 0;
+ String Ingredient = null;
+ for (String word : words)
+ {
+ if (word.matches("\\d+"))
+ {
+ Number = Integer.parseInt(word);
+ } else if (word.matches("[a-zA-Z]+") && !word.equals("and"))
+ {
+ Ingredient = word;
+ }
+ if (Number != 0 && Ingredient != null)
+ {
+ RecipeNode newIngredient = new RecipeNode(Ingredient, Number);
+ node.addChild(newIngredient);
+ newIngredient.parent = node;
+ Number = 0;
+ Ingredient = null;
+ }
+ }
+
+ }
+
+
+ //Tests duh they work :DDDDDD
+ @Test
+ void testRecipeCreation()
+ {
+ }
+ @Test
+ void testconstruct_children()
+ {
+ RecipeNode node = new RecipeNode("", 0);
+ String[] words = {"1", "eggs", "and", "2", "milk"};
+ construct_children(node, words);
+ System.out.println(node.getChildren());
+ }
+
+
+}
diff --git a/src/RecipeNode.java b/src/RecipeNode.java
index 36624d5..9f049c5 100644
--- a/src/RecipeNode.java
+++ b/src/RecipeNode.java
@@ -11,6 +11,10 @@ public class RecipeNode {
this.ingredient = ingredient;
this.portion = portion;
}
+ public RecipeNode(String name)
+ {
+ this.ingredient = name;
+ }
public void setIngredient(String ingredient) {
this.ingredient = ingredient;
diff --git a/src/RecipeTree.java b/src/RecipeTree.java
index e961aa9..f9037bd 100644
--- a/src/RecipeTree.java
+++ b/src/RecipeTree.java
@@ -130,5 +130,37 @@ public class RecipeTree
}
}
+// public void actionAdd(RecipeNode root,RecipeNode actionNchild) {
+// if(root == null) {
+// this.root = actionNchild;
+// } else {
+// for(RecipeNode node : root.getChildren()) {
+// if(node.getPortion() != 0 || !actionNchild.getIngredient().equals(node.getIngredient())) {
+// actionAdd(node,actionNchild);
+// } else if(node.getPortion() == 0 && actionNchild.getIngredient().equals(node.getIngredient())) {
+// addNode(node, actionNchild);
+// }
+// }
+// }
+// }
+ public void actionAdd(RecipeNode root,RecipeNode actionNchild) {
+ if(root == null) {
+ this.root = actionNchild;
+ } else {
+ for(RecipeNode node : root.getChildren()) {
+ if(node.getPortion() == 0 && node.getChildren() != null)
+ actionAdd(node,actionNchild);
+ else
+ addNode(node,actionNchild);
+
+
+ }
+ }
+ }
+ public void actionAdd(RecipeNode actionNchild)
+ {
+ actionAdd(root, actionNchild);
+ }
+
}