-
-
Save CorellanStoma/f49f5ea8557e539f20a38a48e9f235e0 to your computer and use it in GitHub Desktop.
Revisions
-
Davr1 revised this gist
Jan 9, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def best_similarity(master, candidates, originalcandidates): # returns a map return max(candidate_scores, key=itemgetter(0))[1] # sorts a list alphabetically and adds padding (empty strings) so it can be used in the best_similarity function def list_sort(list, padding): return sorted(list) + [''] * (padding - len(list)) -
Davr1 revised this gist
Jan 9, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ def main(): else: try: # splits elements with multiple classes into multiple lines for substring in zip(element_map[element].split(' '), match[element].split(' ')): output.write(f"{substring[0]} = {substring[1]}\n") print(f"Found {element_map[element]}") except: -
Davr1 created this gist
Jan 9, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ import json import re from operator import itemgetter # finds the most similar list # master = [] with n items # candidates = [[],[],[],...] each nested list with n items # original_candidates = [{}, {}, {},...] def best_similarity(master, candidates, originalcandidates): counts = [0] * len(candidates) for i, masterval in enumerate(master): for ci, c in enumerate(candidates): counts[ci] += masterval == c[i] #True is numerically 1 candidate_scores = zip(counts, originalcandidates) # returns a map return max(candidate_scores, key=itemgetter(0))[1] # sorts a list alphabetically and adds padding so it can be used in the best_similarity function def list_sort(list, padding): return sorted(list) + [''] * (padding - len(list)) def main(): old = json.loads(open("old_classes.json").read()) new = json.loads(open("new_classes.json").read()) output = open("output.md", "w+") # turns the new element map into a nested list new_as_list = [list_sort(list(new_element_map), 100) for new_element_map in new] for element_map in old: element_list = list_sort(list(element_map.keys()), 100) match = best_similarity(element_list, new_as_list, new) for element in list(element_map.keys()): # checks if element contains a number as the first character, or a parenthesis # -> gets rid of elements such as "calc(...)" or "24px" if element in match and re.search(r"^\d|\(|\)", match[element]): print(f"Discarding {element}") else: try: # splits elements with multiple classes into multiple lines for substring in zip(match[element].split(' '), element_map[element].split(' ')): output.write(f"{substring[0]} = {substring[1]}\n") print(f"Found {element_map[element]}") except: print(f"Couldn't find {element}") print("Finished") output.close() main()