<commit_before>/**
 *  @author <NAME>
 *  @author <NAME>
 *  Created: October 4th, 2014
 *  Modified: October 10th, 2014
 */

package application;

import java.io.*;
import java.util.*;

import application.Actions.AbstractAction;
import application.slogonode.SLogoNode;
import javafx.geometry.Point2D;

public class Model {

	public List<Workspace> workspaces;
	public Map<String, String> myCommands;

	public Model() throws IOException {
		System.out.println("Starting constructor");
		PropertiesFactory factory = new PropertiesFactory();
		System.out.println("Initialized Factory");
		try {
			myCommands = factory
					.getPropertyValues("resources/languages/English.properties");
			System.out.println("Factory loaded");
			System.out.println(myCommands);
		} catch (Exception e) {
			System.out
					.println("An Error occured in the loading of the properties File!");
		}
	}

	public void loadCommandsbyLanguage(String fileName) {
		Properties languageProperties = new Properties();
		Scanner myScanner = null;
		try {
			System.out.println("Loading another language");
			InputStream inputStream = getClass().getClassLoader()
					.getResourceAsStream(fileName);
			languageProperties.load(inputStream);
			myScanner = new Scanner(new File(fileName));
			System.out.println(myScanner);
			while (myScanner.hasNextLine()) {
				String str = myScanner.nextLine();
				System.out.println("Current string: " + str);
				if (str.substring(0, 1).equalsIgnoreCase("#"))
					continue;
				else if (str.startsWith("//s+"))
					continue;
				else {
					System.out.println("Adding?");
					String keyword = myScanner.next();
					String equalsSign = myScanner.next();
					String commandReference1 = myScanner.next();
					String commandReference2 = myScanner.next();
					myCommands.put(commandReference1, keyword);
					myCommands.put(commandReference2, keyword);
				}
			}
			System.out.println("Done loading new language");
		} catch (Exception e) {
			System.out.println("Error occured in loading a new language");
		} finally {
			if (myScanner != null)
				myScanner.close();
		}
	}

	/**
	 * pass parseInput the input string, and parseInput will return a List of
	 * AbstractActions to the View, which the View will handle applying to the
	 * correct AbstractDrawer. List can have NullActions if the input is parsed
	 * to create no Actions.
	 * 
	 * @param inputString
	 * @return
	 */

	public List<AbstractAction> parseInput(String inputString) {
		List<AbstractAction> listOfActions = new ArrayList<AbstractAction>();
		List<SLogoNode> listOfNodes = new ArrayList<SLogoNode>();
		String[] inputStringArray = inputString.split("//s+");
		SLogoNodeFactory nodeFactory = new SLogoNodeFactory();

		if (inputString.isEmpty())
			return listOfActions;

		for (String str : inputStringArray) {
			String command = myCommands.get(str);
			SLogoNode node = nodeFactory.getSLogoNodeFromString(command);

			listOfNodes.add(node);
		}
		
		listOfNodes.get(0).addChild(listOfNodes.get(1));

		return listOfActions;
	}

	/**
	 * Similar to parseInput, but the input String is contained within a File.
	 * Parse accordingly, and and return a List of AbstractActions. We will have
	 * NullActions to represent if the input is parsed and returns a non Action.
	 * 
	 * @param inputFile
	 * @return
	 */
	public List<AbstractAction> parseFile(File inputFile) {
		Scanner myScanner = null;<commit_msg>Parsing for single line command is complete.Problem: viewing turtle movement<commit_after>/**
 *  @author <NAME>
 *  @author <NAME>
 *  Created: October 4th, 2014
 *  Modified: October 10th, 2014
 */

package application;

import java.io.*;
import java.util.*;

import application.Actions.AbstractAction;
import application.slogonode.SLogoNode;
import javafx.geometry.Point2D;

public class Model {

	public List<Workspace> workspaces;
	public Map<String, String> myCommands;

	public Model() throws IOException {
		System.out.println("Starting constructor");
		PropertiesFactory factory = new PropertiesFactory();
		System.out.println("Initialized Factory");
		try {
			myCommands = factory
					.getPropertyValues("resources/languages/English.properties");
			System.out.println("Factory loaded");
			System.out.println(myCommands);
		} catch (Exception e) {
			System.out
					.println("An Error occured in the loading of the properties File!");
		}
	}

	public void loadCommandsbyLanguage(String fileName) {
		Properties languageProperties = new Properties();
		Scanner myScanner = null;
		try {
			System.out.println("Loading another language");
			InputStream inputStream = getClass().getClassLoader()
					.getResourceAsStream(fileName);
			languageProperties.load(inputStream);
			myScanner = new Scanner(new File(fileName));
			System.out.println(myScanner);
			while (myScanner.hasNextLine()) {
				String str = myScanner.nextLine();
				System.out.println("Current string: " + str);
				if (str.substring(0, 1).equalsIgnoreCase("#"))
					continue;
				else if (str.startsWith("//s+"))
					continue;
				else {
					System.out.println("Adding?");
					String keyword = myScanner.next();
					String equalsSign = myScanner.next();
					String commandReference1 = myScanner.next();
					String commandReference2 = myScanner.next();
					myCommands.put(commandReference1, keyword);
					myCommands.put(commandReference2, keyword);
				}
			}
			System.out.println("Done loading new language");
		} catch (Exception e) {
			System.out.println("Error occured in loading a new language");
		} finally {
			if (myScanner != null)
				myScanner.close();
		}
	}

	/**
	 * pass parseInput the input string, and parseInput will return a List of
	 * AbstractActions to the View, which the View will handle applying to the
	 * correct AbstractDrawer. List can have NullActions if the input is parsed
	 * to create no Actions.
	 * 
	 * @param inputString
	 * @return
	 */

	public List<AbstractAction> parseInput(String inputString) {
		List<AbstractAction> listOfActions = new ArrayList<AbstractAction>();
		SLogoNode root = null;
		String[] inputStringArray = inputString.split("\\s+");
		SLogoNodeFactory nodeFactory = new SLogoNodeFactory();
		
		System.out.println("Input String: " + inputString);
		System.out.println("Split input: " + inputStringArray);
		System.out.println("My Commands: " + myCommands);
		if(inputString.isEmpty())
			return listOfActions;

		for(String str : inputStringArray) {
			System.out.println("\tSTR: " + str);
			String command = myCommands.get(str);
			SLogoNode node = null;
			if(command == null)
				node = nodeFactory.getSLogoNodeFromString(str);
			else
				node = nodeFactory.getSLogoNodeFromString(command);
			
			System.out.println("Node: " + node);
			if(root == null)
				root = node;
			else
				root.addChild(node);
		}
		
		System.out.println("Root: " + root);
		int result = root.evaluate();
		return root.myActions;
	}

	/**
	 * Similar to parseInput, but the input String is contained within a File.
	 * Parse accordingly, and and return a List of AbstractActions. We will have
	 * NullActions to represent if the input is parsed and returns a non Action.
	 * 
	 * @param inputFile
	 * @return
	 */
	public List<AbstractAction> parseFile(File inputFile) {
		Scanner myScanner = null;
{'fraction_non_alphanumeric': 0.11395380998478771, 'fraction_numerical': 0.005255151431337298, 'mean_word_length': 3.9979267449896336, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3681682', 'n_tokens_mistral': 2443, 'n_tokens_neox': 2088, 'n_words': 578}