I want to make a small command-line-run program that looks for a word or phrase in a target .txt. or .docx file, prints out a corresponding blurb about that phrase, and then replaces it with a different word/phrase. There are about 200 of these tuples. What is the best way to structure this? I'm thinking of putting this info into a text file and writing code to read it in. Or should I simply write it all into the program?I'm also thinking of making a class for each tuple w/ three fields that stores this information.Is this a good approach, or are there better ways?PS: I'm thinking of using Java for this unless someone can suggest Python for a particular reason.
Want Some Advice on Structuring My Text-Editing Program
java;design;design patterns;object oriented;object oriented design
The way I interpret your idea:You have about 200 strings that you want to search for in your target .txtFind any of these given stringsGive the user(?) som kind of feedbackReplace it with some other stringBoth strings returned in step 2 and 3 are mapped to the exact content of the string found in step 1, i.e:'a' found -> print 'a_feedback', put 'a_replace''b' found -> print 'b_feedback', put 'b_replace'Load these respective string-tuples from some kind of source .txt and store them , each in their own object of some custom tuple-class.Great!You've got a solution going! Java is probably a good way to go for this but I don't see why Python should be turned down either. Go with what you're most confident using.I also suggest you go on with your plan to separate your text-source from the code. Since you're going to have a large mass of distinct text-tuples there's really no sense in interspersing it into your source code, it will just be messy. You could come up with some kind of simple custom structure for storing your data in the .txt and then use regex to find and parse every tuple, however, I would suggest that you use some more conventional way of storing data. My suggestions:For simplicity: INIFor something simple but really useful: JSONFor broad usability and expandability: XMLFor storing your tuples when loaded into the main program, objects is the way to go. I think a custom class for this kind of tuple sounds like a good plan, but you could also play around with maps for mapping the key-string to it's feedback and replace values, respectively.