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
#include <string>
......
#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();
......
//
// Created by erayd on 11.04.2023.
//
#pragma once
#include <string>
......
//
// 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
......
#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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment