def change_synset(wn): mode = None while mode != "a" and mode != "d": mode = input("(A)dd synset/(d)elete synset: ").lower() if mode == "d": synset = enter_synset(wn) reason = input("Reason for deletion with (#IssueNo): ") supersede_synset = enter_synset(wn, "superseding ") if mode == "a": definition = input("Definition: ") lexfile = input("Lexicographer file: ") pos = input( "Part of speech (n)oun/(v)erb/(a)djective/adve(r)b/(s)atellite: " ).lower() if mode == "a": new_id = change_manager.add_synset(wn, definition, lexfile, pos) while True: lemma = input("Add Lemma (blank to stop): ") if lemma: change_manager.add_entry(wn, wn.synset_by_id(new_id), lemma) else: break print("New synset created with ID %s. Add at least one relation:" % new_id) change_relation(wn, new_id) elif mode == "d": change_manager.delete_synset(wn, synset, supersede_synset, reason) return True
def split_synset(wn, change_list): synset = enter_synset(wn) definition = [] print("Enter definitions (empty line to finish)") while True: d1 = input("Definition: ") if d1: definition.append(d1) else: break reason = input("Reason for deletion (#IssueNo): ") new_ids = [] for definition in definition: new_ids.append( change_manager.add_synset(wn, definition, synset.lex_name, synset.part_of_speech.value, change_list=change_list)) change_manager.delete_synset( wn, synset, [wn.synset_by_id(new_id) for new_id in new_ids], reason, change_list=change_list) return True
def main(): parser = argparse.ArgumentParser( description= "Split a synset - delete the synset and add two (or more) new synsets") parser.add_argument('synset', metavar='SYNSET_ID', type=str, nargs="?", help="The ID of the synset to change") parser.add_argument( '--definition', type=str, action='append', help="The definition of the new synsets (repeat for each synset)") parser.add_argument( '--reason', type=str, nargs="?", help="The reason for this change including issue number") args = parser.parse_args() wn = change_manager.load_wordnet() if not args.synset: args.synset = "ewn-" + input("Enter synset ID: ewn-") synset = wn.synset_by_id(args.synset) if not synset: print("Cannot find synset") exit(-1) if not args.definition: args.definition = [] print("Enter definitions (empty line to finish)") while True: d1 = input("Definition: ") if d1: args.definition.append(d1) else: break if not args.definition: print("No new definitions") exit(-1) if not args.reason: args.reason = input("Reason for deletion (#IssueNo): ") new_ids = [] for definition in args.definition: new_ids.append( change_manager.add_synset(wn, definition, synset.lexfile, synset.pos)) change_manager.delete_synset( wn, synset, [wn.synset_for_id(new_id) for new_id in new_ids], args.reason) change_manager.save_all_xml(wn)
def change_synset(wn, change_list): mode = None while mode != "a" and mode != "d": mode = input("(A)dd synset/(d)elete synset: ").lower() if mode == "d": synset = enter_synset(wn) reason = input("Reason for deletion with (#IssueNo): ") while not re.match("\w+.*\(#\d+\)$", reason): print( "Bad reason please state at least one word with the issue number in parentheses, e.g., duplicate (#123)" ) reason = input("Reason for deletion with (#IssueNo): ") supersede_synset = enter_synset(wn, "superseding ") if mode == "a": definition = input("Definition: ") lexfile = input("Lexicographer file: ") pos = input( "Part of speech (n)oun/(v)erb/(a)djective/adve(r)b/(s)atellite: " ).lower() if mode == "a": new_id = change_manager.add_synset(wn, definition, lexfile, pos, change_list=change_list) while True: lemma = input("Add Lemma (blank to stop): ") if lemma: change_manager.add_entry(wn, wn.synset_by_id(new_id), lemma, change_list=change_list) else: break print("New synset created with ID %s. Add at least one relation:" % new_id) change_relation(wn, change_list, new_id) elif mode == "d": change_manager.delete_synset(wn, synset, supersede_synset, reason, change_list=change_list) return True
def main(): parser = argparse.ArgumentParser(description="Add or remove a synset") parser.add_argument('synset', metavar='SYNSET_ID', type=str, help="The ID of the synset to change") parser.add_argument('--add', action='store_true', help="Add this relation as a new relation") parser.add_argument('--delete', action='store_true', help="Remove this relation (do not replace or change)") parser.add_argument('--reason', type=str, help="The reason for a deletion or merge") args = parser.parse_args() wn = change_manager.load_wordnet() synset = wn.synset_by_id(args.synset) if not synset: print("Could not find synset") sys.exit(-1) if args.add: change_manager.add_synset(wn, synset, args.defintion) elif args.delete: if not args.reason: print("Please give a reason for deletion") sys.exit(-1) change_manager.delete_synset(wn, synset) with open("src/deprecations.csv", 'a') as f: writer = csv.writer(f) writer.writerow([synset.id, synset.ili, '', '', args.reason]) else: print("No action chosen") sys.exit(-1)
def main(): parser = argparse.ArgumentParser( description= "Merge a synset - delete one or more synset and merge all properties. This may create weird or contradictory results so should be used with care" ) parser.add_argument('synsets', metavar='SYNSET_ID', type=str, nargs="*", help="The ID of the synset to change") parser.add_argument( '--reason', type=str, nargs="?", help="The reason for this change including issue number") parser.add_argument('--lex_file', type=str, help="The lex file to write the new synset to") args = parser.parse_args() wn = change_manager.load_wordnet() if not args.synsets: args.synsets = [] print("Enter synsets (empty line to finish)") while True: id1 = input("Enter synset ID: ewn-") if id1: args.synsets.append("ewn-" + id1) else: break if not args.synsets: print("Need at least one synset to merge") exit(-1) synsets = [wn.synset_by_id(ss) for ss in args.synsets] if any(s == None for s in synsets): print("Cannot find synset") exit(-1) if any(s.part_of_speech != synsets[0].part_of_speech for s in synsets): print("Merging across parts of speech is not correct!") exit(-1) if not args.lex_file and any(s.lex_name != synsets[0].lex_name for s in synsets): print("Merging across lex files: " + ", ".join(s.lex_name for s in synsets)) args.lex_file = input("Lex file : ") elif not args.lex_file: args.lex_file = synsets[0].lex_name if not args.reason: args.reason = input("Reason for deletion (#IssueNo): ") new_id = change_manager.merge_synset(wn, synsets, args.reason, args.lex_file) for synset in synsets: change_manager.delete_synset(wn, synset, [new_id], args.reason)
def main(): parser = argparse.ArgumentParser(description="Add or remove a synset") parser.add_argument('synset', metavar='SYNSET_ID', type=str, nargs="?", help="The ID of the synset to change") parser.add_argument('--add', action='store_true', help="Add this synset") parser.add_argument('--delete', action='store_true', help="Remove this synset") parser.add_argument( '--reason', type=str, help="The reason for a deletion or merge (required for deletion)") parser.add_argument('--definition', type=str, help="The definition of the new synset") parser.add_argument('--lexfile', type=str, help="The lexicographer file to write the synset to") parser.add_argument('--pos', type=str, help="The part of speech (n|v|a|r|s)") parser.add_argument( '--supersededby', type=str, help="The ID of the superseding synset (required for deletion)") args = parser.parse_args() wn = change_manager.load_wordnet() if not args.delete and not args.add: mode = input("(A)dd synset/(d)elete synset: ").lower() if mode == "a": args.add = True elif mode == "d": args.delete = True else: print("Bad mode: " + mode) sys.exit(-1) if args.delete: if not args.synset: args.synset = "ewn-" + input("Enter synset ID: ewn-") synset = wn.synset_by_id(args.synset) if not synset: print("Could not find synset") sys.exit(-1) if not args.reason: args.reason = input("Reason for deletion with (#IssueNo): ") if not args.supersededby: args.supersededby = "ewn-" + \ input("Enter superseding synset ID: ewn-") supersede_synset = wn.synset_by_id(args.supersededby) if not supersede_synset: print("Could not find synset") sys.exit(-1) if args.add: if not args.definition: args.definition = input("Definition: ") if not args.lexfile: args.lexfile = input("Lexicographer file: ") if not args.pos: args.pos = input( "Part of speech (n)oun/(v)erb/(a)djective/adve(r)b/(s)atellite: ").lower() if args.add: new_id = change_manager.add_synset( wn, args.definition, args.lexfile, args.pos) print( "New synset created with ID %s. Please use change-entry and change-relation scripts to add entries and relations" % new_id) elif args.delete: if not args.reason: print("Please give a reason for deletion") sys.exit(-1) change_manager.delete_synset(wn, synset, supersede_synset, args.reason) else: print("No action chosen") sys.exit(-1) change_manager.save_all_xml(wn)