Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
magicCards
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Letzgus
magicCards
Commits
a86ca570
Commit
a86ca570
authored
2 years ago
by
erayosso
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup
parent
92678ca9
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Cards.h
+0
-3
0 additions, 3 deletions
Cards.h
aufgabe1.cpp
+1
-2
1 addition, 2 deletions
aufgabe1.cpp
aufgabe1.h
+0
-3
0 additions, 3 deletions
aufgabe1.h
functions.cpp
+18
-5
18 additions, 5 deletions
functions.cpp
main.cpp
+2
-5
2 additions, 5 deletions
main.cpp
with
21 additions
and
18 deletions
Cards.h
+
0
−
3
View file @
a86ca570
//
// Created by Eray düzenli on 13.04.23.
//
#pragma once
#include
<string>
...
...
This diff is collapsed.
Click to expand it.
aufgabe1.cpp
+
1
−
2
View file @
a86ca570
#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
();
...
...
This diff is collapsed.
Click to expand it.
aufgabe1.h
+
0
−
3
View file @
a86ca570
//
// Created by erayd on 11.04.2023.
//
#pragma once
#include
<string>
...
...
This diff is collapsed.
Click to expand it.
functions.cpp
+
18
−
5
View file @
a86ca570
//
// 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
...
...
This diff is collapsed.
Click to expand it.
main.cpp
+
2
−
5
View file @
a86ca570
#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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment