text parse
in
Programming Questions
•
1 year ago
I am trying to break apart a text into individual words, change them to alternatives, and then rewrite to a new file. I have no trouble breaking the text up using splitTokens() with delimiters to accomplish this.
The difficulty is in rewriting the text with those same delimiters in the appropriate locations (puntuation, whites spaces...).
Is there an example or function that will help me remap all of the appropriate formatting back into a txt file once I've made the changes?
Here is a basic example from 'Learning processing' (The code I'm using is bit long, and runs through other things not necessary here):
essentially, I'd like to change individual words (unaware of what they are, so I can't search for particular strings) and retain the formatting.
Thank You!
The difficulty is in rewriting the text with those same delimiters in the appropriate locations (puntuation, whites spaces...).
Is there an example or function that will help me remap all of the appropriate formatting back into a txt file once I've made the changes?
Here is a basic example from 'Learning processing' (The code I'm using is bit long, and runs through other things not necessary here):
- String[] lines = loadStrings("test.txt");
int totalCount = 0; // Total word count for entire book
// Ignore lines until the *** START line
for (int i = 0; i < lines.length; i++) {
// List of characters and punctuation to ignore between // letters. WHITESPACE is all the whitespace characters
String separators = WHITESPACE + ",;.:?()\"-"; // Split the line anywhere that we see one or more of
// these separators
String[] words = splitTokens(lines[i], separators);
// Add this number to the total
totalCount += words.length;
// Go through the list of words on the line
for (int j = 0; j < words.length; j++) {
String word = words[j].toLowerCase();
if (word.length() > 10) {
println(word); // Print word if longer
}
}
}
"Well, Prince, so Genoa and Lucca are now just family estates of the
Buonapartes. But I warn you, if you don't tell me that this means war,
if you still try to defend the infamies and horrors perpetrated by that
Antichrist--I really believe he is Antichrist--I will have nothing more
to do with you and you are no longer my friend, no longer my 'faithful
slave,' as you call yourself! But how do you do? I see I have frightened
you--sit down and tell me all the news."
essentially, I'd like to change individual words (unaware of what they are, so I can't search for particular strings) and retain the formatting.
Thank You!
1