Pseudocódigo se vería así:
create words, a list of words, by splitting the input by whitespace
for every word, strip out whitespace and punctuation on the left and the right
El código Python sería algo como esto:
words = input.split()
words = [word.strip(PUNCTUATION) for word in words]
donde
PUNCTUATION = ",. \n\t\\\"'][#*:"
o cualquier otro carácter que desea eliminar.
Creo que Java tiene funciones equivalentes en la clase String: String .split().
salida de ejecutar este código en el texto que ya ha proporcionado en su enlace:
>>> print words[:100]
['Project', "Gutenberg's", 'Manual', 'of', 'Surgery', 'by', 'Alexis',
'Thomson', 'and', 'Alexander', 'Miles', 'This', 'eBook', 'is', 'for',
'the', 'use', 'of', 'anyone', 'anywhere', 'at', 'no', 'cost', 'and',
'with', 'almost', 'no', 'restrictions', 'whatsoever', 'You', 'may',
'copy', 'it', 'give', 'it', 'away', 'or', 're-use', 'it', 'under',
... etc etc.
Tuve que cambiar ligeramente la expresión regular para no incluir números, guiones bajos y no tener palabras que comiencen con una comilla, pero de lo contrario, ¡bien! –
Tuve que escapar de la \ w, así que: 'Pattern.compile (" [\\ w '] + ");' – ScrollerBlaster
@ScrollerBlaster Eso es correcto. Lo arreglaré, gracias! – Tomalak