Last active
December 24, 2022 12:02
-
-
Save dabodamjan/5d494001a5bc57f6b9d662278fbd8774 to your computer and use it in GitHub Desktop.
KeywordsMinifier used for Minify ASO app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// KeywordsMinifier.swift | |
// MinifyASO | |
// | |
// Created by Damjan Dabo on 19.12.22. | |
// | |
import Foundation | |
/// Used for Minify ASO app https://apps.apple.com/us/app/minify-aso-duplicate-keywords/id1660632226 | |
struct KeywordsMinifier { | |
// MARK: - Private properties | |
private static let charsToSeparateBy: CharacterSet = [".", ",", "!", "?", " ", "\n"] | |
// MARK: - Public funcs | |
static func minifyKeywords( | |
fromInput input: String, | |
keywordsToExclude: String | |
) -> String { | |
let minifiedKeywordsList = minifiedKeywordsList( | |
input: input, | |
keywordsToExclude: keywordsToExclude) | |
return (minifiedKeywordsList ?? []).joined(separator: ",") | |
} | |
// MARK: - Private funcs | |
private static func minifiedKeywordsList(input: String, keywordsToExclude: String) -> [String]? { | |
let words = input | |
.lowercased() | |
.components(separatedBy: charsToSeparateBy) | |
.filter({!$0.isEmpty}) | |
print("With duplicates:\n\(words)") | |
let removedPlurals = words | |
.map { word in | |
guard !("ios").contains(word) else { return word } | |
if word.last == "s" { | |
let removedSWord = word.dropLast() | |
if removedSWord.last == "e" { | |
return String(removedSWord.dropLast()) | |
} else { | |
return String(removedSWord) | |
} | |
} else { | |
return word | |
} | |
} | |
guard let uniqueOrdered = Array(NSOrderedSet(array: removedPlurals)) as? Array<String> else { | |
print("Error") | |
return nil | |
} | |
let keywordsToExcludeWords = keywordsToExclude | |
.lowercased() | |
.components(separatedBy: charsToSeparateBy) | |
.filter({!$0.isEmpty}) | |
let removedStopWords = uniqueOrdered | |
.filter { !stopWords.contains($0) } | |
.filter { !keywordsToExcludeWords.contains($0) } | |
return removedStopWords | |
} | |
private static var stopWords: [String] { | |
/// from https://appfigures.com/resources/guides/keyword-optimization-app-store-connect#4-eliminate-stop-words | |
let stopWordsInput = """ | |
a, about, above, after, again, against, all, am, an, and, any, app, are, aren't, as, at, be, because, been, before, being, below, between, both, but, by, can't, cannot, could, couldn't, did, didn't, do, does, doesn't, doing, don't, down, during, each, few, for, from, further, had, hadn't, has, hasn't, have, haven't, having, he, he'd, he'll, he's, her, here, here's, hers, herself, him, himself, his, how, how's, i, i'd, i'll, i'm, i've, if, in, into, is, isn't, it, it's, its, itself, let's, me, more, most, mustn't, my, myself, no, nor, not, of, off, on, once, only, or, other, ought, our, ours, ourselves, out, over, own, same, shan't, she, she'd, she'll, she's, should, shouldn't, so, some, such, than, that, that's, the, their, theirs, them, themselves, then, there, there's, these, they, they'd, they'll, they're, they've, this, those, through, to, too, under, until, up, very, was, wasn't, we, we'd, we'll, we're, we've, were, weren't, what, what's, when, when's, where, where's, which, while, who, who's, whom, why, why's, with, won't, would, wouldn't, you, you'd, you'll, you're, you've, your, yours, yourself, yourselves | |
""" | |
return stopWordsInput | |
.lowercased() | |
.components(separatedBy: charsToSeparateBy) | |
.filter({!$0.isEmpty}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment