Added arn to the main repository
This commit is contained in:
arn
AMV.goAMVAPI.goAMVTitle.goAPIKeys.goActivity.goActivityConsumeAnime.goActivityConsumeAnimeAPI.goActivityCreate.goActivityCreateAPI.goAiringDate.goAnalytics.goAnalyticsAPI.goAniList.goAniListMatch.goAnime.goAnimeAPI.goAnimeCharacter.goAnimeCharacterAPI.goAnimeCharacters.goAnimeCharactersAPI.goAnimeEpisode.goAnimeEpisodes.goAnimeEpisodesAPI.goAnimeFinder.goAnimeImage.goAnimeList.goAnimeListAPI.goAnimeListItem.goAnimeListItemAPI.goAnimeListItemRating.goAnimeList_test.goAnimePopularity.goAnimeRating.goAnimeRelation.goAnimeRelations.goAnimeRelationsAPI.goAnimeSort.goAnimeSort_test.goAnimeTitle.goAnime_test.goAuthorizeHelper.goAvatar.goBot.goCharacter.goCharacterAPI.goCharacterAttribute.goCharacterFinder.goCharacterImage.goCharacterName.goClientErrorReport.goClientErrorReportAPI.goCollectionUtils.goCompany.goCompanyAPI.goCompanyName.goCompanySort.goDataLists.goDatabase.goDatabase_test.goDraftIndex.goDraftIndexAPI.goDraftable.goEditLogEntry.goEditLogEntryAPI.goEmailToUser.goExternalMedia.goExternalMediaAPI.goFacebookToUser.goForumIcons.goGenres.goGoogleToUser.goGroup.goGroupAPI.goGroupImage.goGroupMember.goHSLColor.goHasCreator.goHasDraft.goHasEditing.goHasEditor.goHasID.goHasLikes.goHasLocked.goHasMappings.goHasPosts.goHasText.goIDCollection.goIDList.goIgnoreAnimeDifference.goIgnoreAnimeDifferenceAPI.goInventory.goInventoryAPI.goInventorySlot.goInventory_test.goJapaneseTokenizer.goJoinable.goKitsuAnime.goKitsuMappings.goKitsuMatch.goLICENSELikeable.goLink.goLinkable.goListOfMappedIDs.goLocation.goLockable.goLoggable.goMapping.goMyAnimeListMatch.goName.goNickToUser.goNotification.goNotificationAPI.goNotificationType.goNyaa.goOpenGraph.goPayPal.goPayPalPayment.goPerson.goPersonAPI.goPersonImage.goPersonName.goPost.goPostAPI.goPostParent.goPostable.goProduction.goPublishable.goPurchase.goPurchaseAPI.goPushNotification.goPushSubscription.goPushSubscriptions.goPushSubscriptionsAPI.goQuote.goQuoteAPI.goQuoteText.goREADME.mdREADME.src.mdSession.goSettings.goSettingsAPI.goShopItem.goShopItemAPI.goSoundTrack.goSoundTrackAPI.goSoundTrackLyrics.goSoundTrackTitle.goSoundTrackUtils.goSpoiler.goStatisticsCategory.goStatisticsItem.goThread.goThreadAPI.goTwitterToUser.goUpcomingEpisode.goUser.goUserAPI.goUserAccounts.goUserAvatar.goUserConnectAccounts.goUserCover.goUserEvents.goUserFollows.goUserFollowsAPI.goUserHelper.goUserJoins.goUserNotifications.goUserNotificationsAPI.goUserSubTypes.goUser_test.goUtils.go
autocorrect
autodocs
mailer
osutils
search
stringutils
validate
video
assets
auth
benchmarks
bots/discord
go.modgo.sumgraphql
jobs
anime-characters
anime-ratings
download-character-images
jobs.gokitsu-characters-parse
kitsu-import-anime
kitsu-import-mappings
mal-download
mal-parse
mal-sync
refresh-episodes
refresh-games
soundtrack-download
sync-media-relations
sync-shoboi
test
twist
middleware
pages
activity
admin
amv
amvs
anime
animeimport
animelist
animelistitem
apiview
calendar
character
characters
companies
company
compare
editlog
editor
diffs.goeditor.go
filteranime
all.goanilist.gocharacters.goduplicatemappings.goepisodelength.gogenres.golicensors.golowresimages.gomal.goproducers.gorelations.goshoboi.gosource.gostartdate.gostudios.gosynopsis.gotrailers.goutils.go
filtercompanies
filtersoundtracks
jobs
kitsu.gomal.goepisode
explore
forum
frontpage
genre
genres
group
groups
index
inventory
listimport
notifications
paypal
popular
post
profile
quote
quotes
recommended
search
settings
shop
soundtrack
soundtracks
statistics
thread
upload
user
users
patches
activity-recreate-from-log
add-character-created-date
add-item
add-shop-items
add-user-notify-email
anime-episodes-sort
anime-status
animelist-remove-duplicates
change-role
character-split-spoilers
character-unescape-name
christmas-notification
clear-anime-ratings
clear-sessions
delete-amv-tags
delete-balance
delete-old-sessions
delete-private-data
delete-pro
delete-unused-characters
email-notification
fix-airing-dates
fix-anime-list-item-status
fix-broken-relations
fix-genres
fix-theme
fix-tvdb-duplicates
fix-user-websites
fix-wrong-ids-in-animelists
import-kitsu-mappings
import-mal-companies
kitsu-anilist
kitsu-download-anime-images
mark-month-as-current
merge-duplicate-characters
notification-delete-old
notification-emails
optimize-all-webm-files
post-sort-date
post-texts
refresh-anime-average-color
refresh-anime-thumbnails
remove-character-borders
reset-animelist-ratings
reset-inventories
reset-notification-settings
show-kitsu-mappings
show-season
show-user-languages
thread-posts
update-amv-info
user-privacy-location
user-references
user-set-social-id
user-show-intros
utils
111
arn/stringutils/StringUtils.go
Normal file
111
arn/stringutils/StringUtils.go
Normal file
@ -0,0 +1,111 @@
|
||||
package stringutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/xrash/smetrics"
|
||||
)
|
||||
|
||||
var whitespace = rune(' ')
|
||||
|
||||
// RemoveSpecialCharacters ...
|
||||
func RemoveSpecialCharacters(s string) string {
|
||||
return strings.Map(
|
||||
func(r rune) rune {
|
||||
if r == '-' {
|
||||
return -1
|
||||
}
|
||||
|
||||
if !unicode.IsLetter(r) && !unicode.IsDigit(r) {
|
||||
return whitespace
|
||||
}
|
||||
|
||||
return r
|
||||
},
|
||||
s,
|
||||
)
|
||||
}
|
||||
|
||||
// AdvancedStringSimilarity is like StringSimilarity but boosts the value if a appears directly in b.
|
||||
func AdvancedStringSimilarity(a string, b string) float64 {
|
||||
if a == b {
|
||||
return 10000000
|
||||
}
|
||||
|
||||
normalizedA := strings.Map(keepLettersAndDigits, a)
|
||||
normalizedB := strings.Map(keepLettersAndDigits, b)
|
||||
|
||||
if normalizedA == normalizedB {
|
||||
return 100000
|
||||
}
|
||||
|
||||
s := StringSimilarity(a, b)
|
||||
|
||||
if strings.Contains(normalizedB, normalizedA) {
|
||||
s += 0.6
|
||||
|
||||
if strings.HasPrefix(b, a) {
|
||||
s += 5.0
|
||||
}
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// StringSimilarity returns 1.0 if the strings are equal and goes closer to 0 when they are different.
|
||||
func StringSimilarity(a string, b string) float64 {
|
||||
return smetrics.JaroWinkler(a, b, 0.7, 4)
|
||||
}
|
||||
|
||||
// Capitalize returns the string with the first letter capitalized.
|
||||
func Capitalize(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
r, n := utf8.DecodeRuneInString(s)
|
||||
return string(unicode.ToUpper(r)) + s[n:]
|
||||
}
|
||||
|
||||
// Plural returns the number concatenated to the proper pluralization of the word.
|
||||
func Plural(count int, singular string) string {
|
||||
if count == 1 || count == -1 {
|
||||
return fmt.Sprintf("%d %s", count, singular)
|
||||
}
|
||||
|
||||
switch singular {
|
||||
case "activity":
|
||||
singular = "activitie"
|
||||
case "company":
|
||||
singular = "companie"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d %ss", count, singular)
|
||||
}
|
||||
|
||||
// ContainsUnicodeLetters tells you if unicode characters are inside the string.
|
||||
func ContainsUnicodeLetters(s string) bool {
|
||||
return len(s) != len([]rune(s))
|
||||
}
|
||||
|
||||
// PrettyPrint prints the object as indented JSON data on the console.
|
||||
func PrettyPrint(obj interface{}) {
|
||||
// Currently, MarshalIndent doesn't support tabs.
|
||||
// Change this back to using \t when it's implemented.
|
||||
// See: https://github.com/json-iterator/go/pull/273
|
||||
pretty, _ := jsoniter.MarshalIndent(obj, "", " ")
|
||||
fmt.Println(string(pretty))
|
||||
}
|
||||
|
||||
// keepLettersAndDigits removes everything but letters and digits when used in strings.Map.
|
||||
func keepLettersAndDigits(r rune) rune {
|
||||
if !unicode.IsLetter(r) && !unicode.IsDigit(r) {
|
||||
return -1
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
Reference in New Issue
Block a user