From a86ca570f6feba328b3a4d57e2bbfb35e296e29b Mon Sep 17 00:00:00 2001
From: erayosso <erayduezenli@googlemail.com>
Date: Sat, 15 Apr 2023 13:14:28 +0200
Subject: [PATCH] Cleanup

---
 Cards.h       |  3 ---
 aufgabe1.cpp  |  3 +--
 aufgabe1.h    |  3 ---
 functions.cpp | 23 ++++++++++++++++++-----
 main.cpp      |  7 ++-----
 5 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/Cards.h b/Cards.h
index 50b4631..5302c9a 100644
--- a/Cards.h
+++ b/Cards.h
@@ -1,6 +1,3 @@
-//
-// Created by Eray düzenli on 13.04.23.
-//
 #pragma once
 
 #include <string>
diff --git a/aufgabe1.cpp b/aufgabe1.cpp
index ce8b962..cc76307 100644
--- a/aufgabe1.cpp
+++ b/aufgabe1.cpp
@@ -1,4 +1,3 @@
-#include <iostream>
 #include "aufgabe1.h"
 
 //Helper function, calculate minimum of three values
@@ -12,7 +11,7 @@ int min(int x, int y, int z) {
     }
 }
 
-
+//Given two strings,calculate the levenshtein distance between them and return it as an integer
 int levenD(const std::string &s, const std::string &t) {
     //Length of first string
     int n = s.length();
diff --git a/aufgabe1.h b/aufgabe1.h
index d01fa9f..106a710 100644
--- a/aufgabe1.h
+++ b/aufgabe1.h
@@ -1,6 +1,3 @@
-//
-// Created by erayd on 11.04.2023.
-//
 #pragma once
 #include <string>
 
diff --git a/functions.cpp b/functions.cpp
index 0472e74..a949a2e 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -1,6 +1,3 @@
-//
-// Created by Eray düzenli on 13.04.23.
-//
 #include <iostream>
 #include "functions.h"
 #include <fstream>
@@ -10,6 +7,7 @@
 #include "aufgabe1.h"
 
 // Aufgabe 3
+//Given a file of cards, return a list consisting of card objects
 std::list<Cards> getListOfCards(const std::string &filename) {
     std::ifstream file(filename);
     if (!file) {
@@ -63,7 +61,7 @@ std::list<Cards> getListOfCards(const std::string &filename) {
 
 
 // Aufgabe 4
-
+//Given a list of cards, save the card objects back into a file
 void saveCardsToFile(const std::list<Cards> &cardsList, const std::string &filename) {
     //Create new file
     std::ofstream file(filename);
@@ -106,12 +104,15 @@ std::list<std::string> referenceNames(const std::string &referenceFile) {
 
 
 // Aufgabe 6
+//Calculate the levenshtein distance for two lists, replace the broken names with the intact names if possible and save
+// in a new .txt file
 void levenshteinDistance(const std::list<std::string> &intactNames, std::list<Cards> &brokenNames) {
     for (auto &card: brokenNames) {
         //reference value
         double referenceV = 0.2675 * card.name.length();
-        //bool for iterating
+        /* On macOS use this loop instead
         for (const auto &intactName: intactNames) {
+
             //Following two lines are to remove the /r at the end of the string
             std::string newIntact = intactName;
             newIntact.erase(newIntact.size() - 1);
@@ -125,6 +126,18 @@ void levenshteinDistance(const std::list<std::string> &intactNames, std::list<Ca
                 //break and go on to next card
                 break;
             }
+        } */
+        for (const auto &intactName: intactNames) {
+            //calculate levenD of card for every intactName
+            int levenDist = levenD(card.name, intactName);
+
+            //if distance smaller than 26.75% of the card name length...
+            if (levenDist < referenceV) {
+                //replace broken name with intact name
+                card.name = intactName;
+                //break and go on to next card
+                break;
+            }
         }
     }
     //Aufgabe 7
diff --git a/main.cpp b/main.cpp
index d0e1ee3..0295d31 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,3 @@
-#include <iostream>
 #include "aufgabe1.h"
 #include "Cards.h"
 #include "functions.h"
@@ -9,12 +8,10 @@ int main() {
     std::list<std::string> referenceCardNames;
 
 
-    //TODO relative path doesnt work
     //Take scrambled cards and put them in a list
-    scrambledCards = getListOfCards("/Users/erayduzenli/CLionProjects/magicCards/scrambled.txt");
-    //TODO why does it save the file in the debug folder
+    scrambledCards = getListOfCards("../scrambled.txt");
     //take reference names and put them in a list
-    referenceCardNames = referenceNames("/Users/erayduzenli/CLionProjects/magicCards/reference.txt");
+    referenceCardNames = referenceNames("../reference.txt");
 
     //calculate levenshteinDistance and create new file with intact names (if existing)
     levenshteinDistance(referenceCardNames, scrambledCards);
-- 
GitLab