|
427 | 427 | "id": "7bf0d8c8-bd6c-47ef-b305-09ac61d07d4d",
|
428 | 428 | "metadata": {},
|
429 | 429 | "source": [
|
430 |
| - "### Remove Extra Whitespace Characters\n", |
| 430 | + "### Eliminar Caracteres de Espaciado Extra\n", |
431 | 431 | "\n",
|
432 |
| - "Sometimes we might come across texts with extraneous whitespace, such as spaces, tabs, and newline characters, which is particularly common when the text is scrapped from web pages. Before we dive into the details, let's briefly introduce Regular Expressions (regex) and the `re` package. \n", |
| 432 | + "A veces nos encontramos con textos que contienen espacios en blanco innecesarios, como espacios, tabulaciones y caracteres de nueva línea, lo cual es particularmente común cuando el texto proviene de páginas web. Antes de profundizar en los detalles, presentemos brevemente las Expresiones Regulares (regex) y el paquete `re`. \n", |
433 | 433 | "\n",
|
434 |
| - "Regular expressions are a powerful way of searching for specific string patterns in large corpora. They have an infamously steep learning curve, but they can be very efficient when we get a handle on them. Many NLP packages heavily rely on regex under the hood. Regex testers, such as [regex101](https://regex101.com), are useful tools in both understanding and creating regex expressions.\n", |
| 434 | + "Las expresiones regulares son una forma poderosa de buscar patrones específicos de cadenas en grandes corpus de texto. Tienen una curva de aprendizaje notoriamente empinada, pero pueden ser muy eficientes cuando logramos dominarlas. Muchos paquetes de procesamiento de lenguaje natural (NLP) dependen en gran medida de las expresiones regulares. Los probadores de regex, como [regex101](https://regex101.com), son herramientas útiles tanto para entender como para crear expresiones regulares.\n", |
435 | 435 | "\n",
|
436 |
| - "Our goal in this workshop is not to provide a deep (or even shallow) dive into regex; instead, we want to expose you to them so that you are better prepared to do deep dives in the future!\n", |
| 436 | + "Nuestro objetivo en este taller no es ofrecer una inmersión profunda (ni siquiera superficial) en regex; en su lugar, queremos exponerlos a ellas para que estén mejor preparados para hacer inmersiones más profundas en el futuro.\n", |
437 | 437 | "\n",
|
438 |
| - "The following example is a poem by William Wordsworth. Like many poems, the text may contain extra line breaks (i.e., newline characters, `\\n`) that we want to remove." |
| 438 | + "El siguiente ejemplo es un poema de William Wordsworth. Como muchos poemas, el texto puede contener saltos de línea extra (es decir, caracteres de nueva línea, `\\n`) que queremos eliminar." |
439 | 439 | ]
|
440 | 440 | },
|
441 | 441 | {
|
|
459 | 459 | "id": "7a693dd9-9706-40b3-863f-f568020245f7",
|
460 | 460 | "metadata": {},
|
461 | 461 | "source": [
|
462 |
| - "As you can see, the poem is formatted as a continuous string of text with line breaks placed at the end of each line, making it difficult to read. " |
| 462 | + "Como pueden ver, el poema está formateado como una cadena continua de texto con saltos de línea al final de cada línea, lo que lo hace difícil de leer." |
463 | 463 | ]
|
464 | 464 | },
|
465 | 465 | {
|
|
488 | 488 | "id": "47cce993-c315-4aaa-87fe-149de8607f65",
|
489 | 489 | "metadata": {},
|
490 | 490 | "source": [
|
491 |
| - "One handy function we can use to display the poem properly is `.splitlines()`. As the name suggests, it splits a long text sequence into a list of lines whenever there is a newline character. " |
| 491 | + "Una función útil que podemos usar para mostrar el poema correctamente es `.splitlines()`. Como su nombre indica, divide una secuencia de texto larga en una lista de líneas cada vez que encuentra un carácter de nueva línea." |
492 | 492 | ]
|
493 | 493 | },
|
494 | 494 | {
|
|
547 | 547 | "id": "44d3825b-0857-44e1-bf6a-d8c7a9032704",
|
548 | 548 | "metadata": {},
|
549 | 549 | "source": [
|
550 |
| - "Let's return to our tweet data for an example." |
| 550 | + "Volvamos a nuestros datos de tweets para un ejemplo.\n" |
551 | 551 | ]
|
552 | 552 | },
|
553 | 553 | {
|
|
578 | 578 | "id": "aef55865-36fd-4c06-a765-530cf3b53096",
|
579 | 579 | "metadata": {},
|
580 | 580 | "source": [
|
581 |
| - "In this case, we don't really want to split the tweet into a list of strings. We still expect a single string of text but would like to remove the line break completely from the string.\n", |
| 581 | + "En este caso, realmente no queremos dividir el tweet en una lista de cadenas. Aún esperamos una sola cadena de texto, pero nos gustaría eliminar el salto de línea completamente de la cadena.\n", |
582 | 582 | "\n",
|
583 |
| - "The string method `.strip()` effectively does the job of stripping away spaces at both ends of the text. However, it won't work in our example as the newline character is in the middle of the string." |
| 583 | + "El método de cadenas `.strip()` hace eficazmente el trabajo de eliminar los espacios al principio y al final del texto. Sin embargo, no funcionará en nuestro ejemplo, ya que el carácter de nueva línea está en el medio de la cadena." |
584 | 584 | ]
|
585 | 585 | },
|
586 | 586 | {
|
|
610 | 610 | "id": "b99b80b4-804f-460f-a2d5-adbd654902b3",
|
611 | 611 | "metadata": {},
|
612 | 612 | "source": [
|
613 |
| - "This is where regex could be really helpful." |
| 613 | + "Aquí es donde las expresiones regulares (regex) podrían ser realmente útiles." |
614 | 614 | ]
|
615 | 615 | },
|
616 | 616 | {
|
|
628 | 628 | "id": "d5f08d20-ba81-4e48-9e2a-5728148005b3",
|
629 | 629 | "metadata": {},
|
630 | 630 | "source": [
|
631 |
| - "Now, with regex, we are essentially calling it to match a pattern that we have identified in the text data, and we want to do some operations to the matched part—extract it, replace it with something else, or remove it completely. Therefore, the way regex works could be unpacked into the following steps:\n", |
| 631 | + "Ahora, con las expresiones regulares (regex), esencialmente la estamos llamando para que coincida con un patrón que hemos identificado en los datos de texto, y queremos realizar algunas operaciones sobre la parte coincidente: extraerla, reemplazarla por algo más o eliminarla por completo. Por lo tanto, el funcionamiento de regex podría desglosarse en los siguientes pasos:\n", |
632 | 632 | "\n",
|
633 |
| - "- Identify and write the pattern in regex (`r'PATTERN'`)\n", |
634 |
| - "- Write the replacement for the pattern (`'REPLACEMENT'`)\n", |
635 |
| - "- Call the specific regex function (e.g., `re.sub()`)\n", |
| 633 | + "- Identificar y escribir el patrón en regex (`r'PATTERN'`)\n", |
| 634 | + "- Escribir el reemplazo para el patrón (`'REPLACEMENT'`)\n", |
| 635 | + "- Llamar a la función específica de regex (por ejemplo, `re.sub()`)\n", |
636 | 636 | "\n",
|
637 |
| - "In our example, the pattern we are looking for is `\\s`, which is the regex short name for any whitespace character (`\\n` and `\\t` included). We also add a quantifier `+` to the end: `\\s+`. It means we'd like to capture one or more occurences of the whitespace character." |
| 637 | + "En nuestro ejemplo, el patrón que estamos buscando es `\\s`, que es el nombre corto de regex para cualquier carácter de espacio en blanco (incluidos `\\n` y `\\t`). También agregamos un cuantificador `+` al final: `\\s+`. Esto significa que nos gustaría capturar una o más ocurrencias del carácter de espacio en blanco." |
638 | 638 | ]
|
639 | 639 | },
|
640 | 640 | {
|
|
653 | 653 | "id": "cc075c2e-1a1d-4393-a3ea-8ad7c118364b",
|
654 | 654 | "metadata": {},
|
655 | 655 | "source": [
|
656 |
| - "The replacement for one or more whitespace characters is exactly one single whitespace, which is the canonical word boundary in English. Any additional whitespace will be reduced to a single whitespace. " |
| 656 | + "El reemplazo para uno o más caracteres de espacio en blanco es exactamente un solo espacio, que es el límite de palabra canónico en inglés. Cualquier espacio adicional se reducirá a un solo espacio." |
657 | 657 | ]
|
658 | 658 | },
|
659 | 659 | {
|
|
672 | 672 | "id": "bc12e3d1-728a-429b-9c83-4dcc88590bc4",
|
673 | 673 | "metadata": {},
|
674 | 674 | "source": [
|
675 |
| - "Lastly, let's put everything together using the function [`re.sub()`](https://docs.python.org/3.11/library/re.html#re.sub), which means we want to substitute a pattern with a replacement. The function takes in three arguments—the pattern, the replacement, and the string to which we want to apply the function." |
| 675 | + "Finalmente, pongamos todo junto usando la función [`re.sub()`](https://docs.python.org/3.11/library/re.html#re.sub), lo que significa que queremos sustituir un patrón por un reemplazo. La función recibe tres argumentos: el patrón, el reemplazo y la cadena a la que queremos aplicar la función." |
676 | 676 | ]
|
677 | 677 | },
|
678 | 678 | {
|
|
702 | 702 | "id": "a895fbe3-a034-4124-94af-72a528913c51",
|
703 | 703 | "metadata": {},
|
704 | 704 | "source": [
|
705 |
| - "Ta-da! The newline character is no longer there." |
| 705 | + "Ta-da! El carácter de nueva línea ya no está allí." |
706 | 706 | ]
|
707 | 707 | },
|
708 | 708 | {
|
|
0 commit comments