Skip to content
Snippets Groups Projects
Commit a86ca570 authored by erayosso's avatar erayosso
Browse files

Cleanup

parent 92678ca9
No related branches found
No related tags found
No related merge requests found
//
// Created by Eray düzenli on 13.04.23.
//
#pragma once #pragma once
#include <string> #include <string>
... ...
......
#include <iostream>
#include "aufgabe1.h" #include "aufgabe1.h"
//Helper function, calculate minimum of three values //Helper function, calculate minimum of three values
...@@ -12,7 +11,7 @@ int min(int x, int y, int z) { ...@@ -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) { int levenD(const std::string &s, const std::string &t) {
//Length of first string //Length of first string
int n = s.length(); int n = s.length();
... ...
......
//
// Created by erayd on 11.04.2023.
//
#pragma once #pragma once
#include <string> #include <string>
... ...
......
//
// Created by Eray düzenli on 13.04.23.
//
#include <iostream> #include <iostream>
#include "functions.h" #include "functions.h"
#include <fstream> #include <fstream>
...@@ -10,6 +7,7 @@ ...@@ -10,6 +7,7 @@
#include "aufgabe1.h" #include "aufgabe1.h"
// Aufgabe 3 // Aufgabe 3
//Given a file of cards, return a list consisting of card objects
std::list<Cards> getListOfCards(const std::string &filename) { std::list<Cards> getListOfCards(const std::string &filename) {
std::ifstream file(filename); std::ifstream file(filename);
if (!file) { if (!file) {
...@@ -63,7 +61,7 @@ std::list<Cards> getListOfCards(const std::string &filename) { ...@@ -63,7 +61,7 @@ std::list<Cards> getListOfCards(const std::string &filename) {
// Aufgabe 4 // 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) { void saveCardsToFile(const std::list<Cards> &cardsList, const std::string &filename) {
//Create new file //Create new file
std::ofstream file(filename); std::ofstream file(filename);
...@@ -106,12 +104,15 @@ std::list<std::string> referenceNames(const std::string &referenceFile) { ...@@ -106,12 +104,15 @@ std::list<std::string> referenceNames(const std::string &referenceFile) {
// Aufgabe 6 // 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) { void levenshteinDistance(const std::list<std::string> &intactNames, std::list<Cards> &brokenNames) {
for (auto &card: brokenNames) { for (auto &card: brokenNames) {
//reference value //reference value
double referenceV = 0.2675 * card.name.length(); double referenceV = 0.2675 * card.name.length();
//bool for iterating /* On macOS use this loop instead
for (const auto &intactName: intactNames) { for (const auto &intactName: intactNames) {
//Following two lines are to remove the /r at the end of the string //Following two lines are to remove the /r at the end of the string
std::string newIntact = intactName; std::string newIntact = intactName;
newIntact.erase(newIntact.size() - 1); newIntact.erase(newIntact.size() - 1);
...@@ -125,6 +126,18 @@ void levenshteinDistance(const std::list<std::string> &intactNames, std::list<Ca ...@@ -125,6 +126,18 @@ void levenshteinDistance(const std::list<std::string> &intactNames, std::list<Ca
//break and go on to next card //break and go on to next card
break; 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 //Aufgabe 7
... ...
......
#include <iostream>
#include "aufgabe1.h" #include "aufgabe1.h"
#include "Cards.h" #include "Cards.h"
#include "functions.h" #include "functions.h"
...@@ -9,12 +8,10 @@ int main() { ...@@ -9,12 +8,10 @@ int main() {
std::list<std::string> referenceCardNames; std::list<std::string> referenceCardNames;
//TODO relative path doesnt work
//Take scrambled cards and put them in a list //Take scrambled cards and put them in a list
scrambledCards = getListOfCards("/Users/erayduzenli/CLionProjects/magicCards/scrambled.txt"); scrambledCards = getListOfCards("../scrambled.txt");
//TODO why does it save the file in the debug folder
//take reference names and put them in a list //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) //calculate levenshteinDistance and create new file with intact names (if existing)
levenshteinDistance(referenceCardNames, scrambledCards); levenshteinDistance(referenceCardNames, scrambledCards);
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment