Skip to content

Commit

Permalink
✨ Chapter 2 exercises + solutions + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacamilagl committed Jun 4, 2020
1 parent 1ac5809 commit b54b602
Show file tree
Hide file tree
Showing 41 changed files with 641 additions and 644 deletions.
497 changes: 247 additions & 250 deletions exercises/es/capitals.json

Large diffs are not rendered by default.

499 changes: 248 additions & 251 deletions exercises/es/countries.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion exercises/es/country_text.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
After the Cold War, the UN saw a radical expansion in its peacekeeping duties, taking on more missions in ten years than it had in the previous four decades.Between 1988 and 2000, the number of adopted Security Council resolutions more than doubled, and the peacekeeping budget increased more than tenfold. The UN negotiated an end to the Salvadoran Civil War, launched a successful peacekeeping mission in Namibia, and oversaw democratic elections in post-apartheid South Africa and post-Khmer Rouge Cambodia. In 1991, the UN authorized a US-led coalition that repulsed the Iraqi invasion of Kuwait. Brian Urquhart, Under-Secretary-General from 1971 to 1985, later described the hopes raised by these successes as a "false renaissance" for the organization, given the more troubled missions that followed. Though the UN Charter had been written primarily to prevent aggression by one nation against another, in the early 1990s the UN faced a number of simultaneous, serious crises within nations such as Somalia, Haiti, Mozambique, and the former Yugoslavia. The UN mission in Somalia was widely viewed as a failure after the US withdrawal following casualties in the Battle of Mogadishu, and the UN mission to Bosnia faced "worldwide ridicule" for its indecisive and confused mission in the face of ethnic cleansing. In 1994, the UN Assistance Mission for Rwanda failed to intervene in the Rwandan genocide amid indecision in the Security Council. Beginning in the last decades of the Cold War, American and European critics of the UN condemned the organization for perceived mismanagement and corruption. In 1984, the US President, Ronald Reagan, withdrew his nation's funding from UNESCO (the United Nations Educational, Scientific and Cultural Organization, founded 1946) over allegations of mismanagement, followed by Britain and Singapore. Boutros Boutros-Ghali, Secretary-General from 1992 to 1996, initiated a reform of the Secretariat, reducing the size of the organization somewhat. His successor, Kofi Annan (1997–2006), initiated further management reforms in the face of threats from the United States to withhold its UN dues. In the late 1990s and 2000s, international interventions authorized by the UN took a wider variety of forms. The UN mission in the Sierra Leone Civil War of 1991–2002 was supplemented by British Royal Marines, and the invasion of Afghanistan in 2001 was overseen by NATO. In 2003, the United States invaded Iraq despite failing to pass a UN Security Council resolution for authorization, prompting a new round of questioning of the organization's effectiveness. Under the eighth Secretary-General, Ban Ki-moon, the UN has intervened with peacekeepers in crises including the War in Darfur in Sudan and the Kivu conflict in the Democratic Republic of Congo and sent observers and chemical weapons inspectors to the Syrian Civil War. In 2013, an internal review of UN actions in the final battles of the Sri Lankan Civil War in 2009 concluded that the organization had suffered "systemic failure". One hundred and one UN personnel died in the 2010 Haiti earthquake, the worst loss of life in the organization's history. The Millennium Summit was held in 2000 to discuss the UN's role in the 21st century. The three day meeting was the largest gathering of world leaders in history, and culminated in the adoption by all member states of the Millennium Development Goals (MDGs), a commitment to achieve international development in areas such as poverty reduction, gender equality, and public health. Progress towards these goals, which were to be met by 2015, was ultimately uneven. The 2005 World Summit reaffirmed the UN's focus on promoting development, peacekeeping, human rights, and global security. The Sustainable Development Goals were launched in 2015 to succeed the Millennium Development Goals. In addition to addressing global challenges, the UN has sought to improve its accountability and democratic legitimacy by engaging more with civil society and fostering a global constituency. In an effort to enhance transparency, in 2016 the organization held its first public debate between candidates for Secretary-General. On 1 January 2017, Portuguese diplomat António Guterres, who previously served as UN High Commissioner for Refugees, became the ninth Secretary-General. Guterres has highlighted several key goals for his administration, including an emphasis on diplomacy for preventing conflicts, more effective peacekeeping efforts, and streamlining the organization to be more responsive and versatile to global needs.
Las propuestas de reforma del Consejo empezaron con la conferencia que escribió la Carta de la ONU y han continuado hasta el presente. Como el historiador británico Paul Kennedy escribió "todo el mundo acepta que la presente estructura es defectuosa. Pero el consenso de cómo arreglarla permanece fuera de alcance". Ha habido conversaciones para incrementar el número permanente de miembros. Los países que han hecho demandas más fuertes para los asientos permanentes son Brasil, Alemania, India y Japón. Japón y Alemania, los principales poderes derrotados en la II Guerra Mundial, son ahora los segundos y terceros mayores financiadores de la ONU respectivamente, mientras que Brasil e India son dos de los mayores contribuidores de tropas para las misiones de la paz de la ONU. Esta propuesta ha encontrado oposición en un grupo de países llamado Unidos por Consenso. El anterior secretario de la ONU, Kofi Annan, pidió a un equipo de asesores que realizaran recomendaciones para reformar la ONU para el año 2004. Una medida propuesta es incrementar el número permanente de miembros de cinco, que, en muchas propuestas, podría incluir Brasil, Alemania, India y Japón (conocidas como las naciones del G4), un asiento para África (más habitualmente entre Egipto, Nigeria o Sudáfrica) y/o un asiento de la Liga Árabe. El 21 de septiembre de 2004 las naciones del G4 publicaron una declaración conjunta para respaldar mutuamente el sí a la condición de permanente, junto con dos países africanos. La propuesta tendría que ser aceptada por dos tercios de la Asamblea General (128 votos). Los miembros permanentes, cada uno sosteniendo el derecho de veto, anunciaron sus posiciones sobre la reforma del Consejo de Seguridad de forma reacia. Los Estados Unidos han apoyado inequívocamente la membresía de Japón y han prestado su apoyo a India y a un pequeño número de miembros no permanentes. El Reino Unido y Francia esencialmente apoyan la posición del G4, con la expansión del número de miembros permanente y no permanente y el acceso de Alemania, Brasil, India y Japón al estatus de miembro permanente, así como un incremento en la presencia de países africanos en el Consejo. China ha apoyado el fortalecimiento de la representación de los países en desarrollo y se ha opuesto firmemente a la membresía de Japón. A la puja de India por ser miembro permanente del Consejo de Seguridad han mostrado su apoyo Francia, Rusia, Reino Unido, y Estados Unidos aunque los Estados unidos inicialmente se opusieron a la candidatura india en materia de proliferación nuclear, al haber adquirido India armas nucleares y no haber firmado el Tratado de No Proliferación. El 15 de abril de 2011, China oficialmente expresó su apoyo para un incremento del rol indio en las Naciones unidas, sin especificar ambiciones de endorsar el Consejo de Seguridad. En cualquier caso, recientemente China ha expresado su apoyo para la candidatura de India como un miembro permanente si India revoca su apoyo a la candidatura japonesa.
16 changes: 8 additions & 8 deletions exercises/es/exc_02_02_01.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("I have a cat")
nlp = spacy.load("es_core_news_sm")
doc = nlp("Yo tengo un gato")

# Busca el hash para la palabra "cat"
cat_hash = ____.____.____[____]
print(cat_hash)
# Busca el hash para la palabra "gato"
gato_hash = ____.____.____[____]
print(gato_hash)

# Busca el cat_hash para obtener el string
cat_string = ____.____.____[____]
print(cat_string)
# Busca el gato_hash para obtener el string
gato_string = ____.____.____[____]
print(gato_string)
4 changes: 2 additions & 2 deletions exercises/es/exc_02_02_02.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("David Bowie is a PERSON")
nlp = spacy.load("es_core_news_sm")
doc = nlp("David Bowie tiene el label PERSON")

# Busca el hash para el label del string "PERSON"
person_hash = ____.____.____[____]
Expand Down
4 changes: 2 additions & 2 deletions exercises/es/exc_02_05_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Importa la clase Doc
from ____ import ____

# El texto deseado: "spaCy is cool!"
words = ["spaCy", "is", "cool", "!"]
# El texto deseado: "spaCy es divertido!"
words = ["spaCy", "es", "divertido", "!"]
spaces = [True, True, False, False]

# Crea un Doc a partir de las palabras y los espacios
Expand Down
6 changes: 3 additions & 3 deletions exercises/es/exc_02_05_02.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import spacy

nlp = spacy.load("en_core_web_sm")
nlp = spacy.load("es_core_news_sm")

# Importa la clase Doc
from ____ import ____

# El texto deseado: "Go, get started!"
words = ["Go", ",", "get", "started", "!"]
# El texto deseado: "¡Vamos, empieza!"
words = ["¡", "Vamos", ",", "empieza", "!"]
spaces = [____, ____, ____, ____, ____]

# Crea un Doc a partir de las palabras y los espacios
Expand Down
8 changes: 4 additions & 4 deletions exercises/es/exc_02_05_03.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import spacy

nlp = spacy.load("en_core_web_sm")
nlp = spacy.load("es_core_news_sm")

# Importa la clase Doc
from ____ import ____

# El texto deseado: "Oh, really?!"
words = [____, ____, ____, ____, ____]
spaces = [____, ____, ____, ____, ____]
# El texto deseado: "¡¿En serio?!"
words = [____, ____, ____, ____, ____, ____]
spaces = [____, ____, ____, ____, ____, ____]

# Crea un Doc a partir de las palabras y los espacios
doc = ____(____, ____=____, ____=____)
Expand Down
6 changes: 3 additions & 3 deletions exercises/es/exc_02_06.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from spacy.lang.en import English
from spacy.lang.es import Spanish

nlp = English()
nlp = Spanish()

# Importa las clases Doc y Span
from spacy.____ import ____, ____

words = ["I", "like", "David", "Bowie"]
words = ["Me", "gusta", "David", "Bowie"]
spaces = [True, True, True, False]

# Crea un doc a partir de las palabras y los espacios
Expand Down
4 changes: 2 additions & 2 deletions exercises/es/exc_02_07.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("Berlin is a nice city")
doc = nlp("Por Berlín fluye el río Esprea.")

# Obtén todos los tokens y los part-of-speech tags
token_texts = [token.text for token in doc]
Expand All @@ -13,4 +13,4 @@
# Revisa si el siguiente token es un verbo
if pos_tags[index + 1] == "VERB":
result = token_texts[index]
print("Found proper noun before a verb:", result)
print("Encontré un nombre propio antes de un verbo:", result)
10 changes: 5 additions & 5 deletions exercises/es/exc_02_09.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import spacy

# Carga el modelo en_core_web_md
# Carga el modelo es_core_news_md
nlp = ____

# Procesa un texto
doc = nlp("Two bananas in pyjamas")
doc = nlp("Hoy hice pan de banano")

# Obtén el vector para el token "bananas"
bananas_vector = ____.____
print(bananas_vector)
# Obtén el vector para el token "banano"
banano_vector = ____.____
print(banano_vector)
6 changes: 3 additions & 3 deletions exercises/es/exc_02_10_01.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import spacy

nlp = spacy.load("en_core_web_md")
nlp = spacy.load("es_core_news_md")

doc1 = nlp("It's a warm summer day")
doc2 = nlp("It's sunny outside")
doc1 = nlp("Es un cálido día de verano")
doc2 = nlp("Hace sol afuera")

# Obtén la similitud entre el doc1 y el doc2
similarity = ____.____(____)
Expand Down
6 changes: 3 additions & 3 deletions exercises/es/exc_02_10_02.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import spacy

nlp = spacy.load("en_core_web_md")
nlp = spacy.load("es_core_news_md")

doc = nlp("TV and books")
doc = nlp("TV y libros")
token1, token2 = doc[0], doc[2]

# Obtén la similitud entre los tokens "TV" y "books"
# Obtén la similitud entre los tokens "TV" y "libros"
similarity = ____.____(____)
print(similarity)
6 changes: 3 additions & 3 deletions exercises/es/exc_02_10_03.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import spacy

nlp = spacy.load("en_core_web_md")
nlp = spacy.load("es_core_news_md")

doc = nlp("This was a great restaurant. Afterwards, we went to a really nice bar.")
doc = nlp("Estuvimos en un restaurante genial. Luego, fuimos a un bar muy divertido.")

# Crea los spans para "great restaurant" y "really nice bar"
# Crea los spans para "restaurante genial" y "bar muy divertido"
span1 = ____
span2 = ____

Expand Down
22 changes: 11 additions & 11 deletions exercises/es/exc_02_13.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import spacy
from spacy.matcher import Matcher

nlp = spacy.load("en_core_web_sm")
nlp = spacy.load("es_core_news_sm")
doc = nlp(
"Twitch Prime, the perks program for Amazon Prime members offering free "
"loot, games and other benefits, is ditching one of its best features: "
"ad-free viewing. According to an email sent out to Amazon Prime members "
"today, ad-free viewing will no longer be included as a part of Twitch "
"Prime for new members, beginning on September 14. However, members with "
"existing annual subscriptions will be able to continue to enjoy ad-free "
"viewing until their subscription comes up for renewal. Those with "
"monthly subscriptions will have access to ad-free viewing until October 15."
"Cuando Pac-Man debutó en Tokio, en 1980, nadie podría haber predicho "
"que se convertiría en el videojuego más exitoso de todos los tiempos. Hoy, "
"40 años después, aun sigue sorprendiendo. Su desarrolladora, Bandai Namco, "
"ha anunciado novedades en el marco del aniversario del juego. La celebración "
"del 40 aniversario de Pac-man en 2020 incluirá el début de una nueva canción "
"temática, compuesta por el famoso artista japonés de Techno Ken Ishii. "
"Además de estas novedades, Bandai Namco publicará nuevas versiones del videojuego."
"La primera será Pac-Man Live Studio, en Twitch, en colaboración con Amazon Games."
)

# Crea los patrones
pattern1 = [{"LOWER": "Amazon"}, {"IS_TITLE": True, "POS": "PROPN"}]
pattern2 = [{"LOWER": "ad-free"}, {"POS": "NOUN"}]
pattern1 = [{"LOWER": "Bandai"}, {"IS_TITLE": True, "POS": "PROPN"}]
pattern2 = [{"LOWER": "Pac-Man"}, {"POS": "NOUN"}]

# Inicializa el Matcher y añade los patrones
matcher = Matcher(nlp.vocab)
Expand Down
8 changes: 4 additions & 4 deletions exercises/es/exc_02_14.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
from spacy.lang.en import English
from spacy.lang.es import Spanish

with open("exercises/en/countries.json") as f:
with open("exercises/es/countries.json", encoding="utf8") as f:
COUNTRIES = json.loads(f.read())

nlp = English()
doc = nlp("Czech Republic may help Slovakia protect its airspace")
nlp = Spanish()
doc = nlp("La Unión Europea fue fundada por seis países de Europa occidental (Francia, Alemania, Italia, Bélgica, Países Bajos, y Luxemburgo) y se amplió en seis ocasiones.")

# Importa el PhraseMatcher e inicialízalo
from spacy.____ import ____
Expand Down
6 changes: 3 additions & 3 deletions exercises/es/exc_02_15.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from spacy.tokens import Span
import json

with open("exercises/en/countries.json") as f:
with open("exercises/es/countries.json", encoding="utf8") as f:
COUNTRIES = json.loads(f.read())
with open("exercises/en/country_text.txt") as f:
with open("exercises/es/country_text.txt", encoding="utf8") as f:
TEXT = f.read()

nlp = spacy.load("en_core_web_sm")
nlp = spacy.load("es_core_news_sm")
matcher = PhraseMatcher(nlp.vocab)
patterns = list(nlp.pipe(COUNTRIES))
matcher.add("COUNTRY", None, *patterns)
Expand Down
16 changes: 8 additions & 8 deletions exercises/es/solution_02_02_01.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("I have a cat")
nlp = spacy.load("es_core_news_sm")
doc = nlp("Yo tengo un gato")

# Busca el hash para la palabra "cat"
cat_hash = nlp.vocab.strings["cat"]
print(cat_hash)
# Busca el hash para la palabra "gato"
gato_hash = nlp.vocab.strings["gato"]
print(gato_hash)

# Busca el cat_hash para obtener el string
cat_string = nlp.vocab.strings[cat_hash]
print(cat_string)
# Busca el gato_hash para obtener el string
gato_string = nlp.vocab.strings[gato_hash]
print(gato_string)
4 changes: 2 additions & 2 deletions exercises/es/solution_02_02_02.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("David Bowie is a PERSON")
nlp = spacy.load("es_core_news_sm")
doc = nlp("David Bowie tiene el label PERSON")

# Busca el hash para el label del string "PERSON"
person_hash = nlp.vocab.strings["PERSON"]
Expand Down
6 changes: 3 additions & 3 deletions exercises/es/solution_02_05_01.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import spacy

nlp = spacy.load("en_core_web_sm")
nlp = spacy.load("es_core_news_sm")

# Importa la clase Doc
from spacy.tokens import Doc

# El texto deseado: "spaCy is cool!"
words = ["spaCy", "is", "cool", "!"]
# El texto deseado: "spaCy es divertido!"
words = ["spaCy", "es", "divertido", "!"]
spaces = [True, True, False, False]

# Crea un Doc a partir de las palabras y los espacios
Expand Down
8 changes: 4 additions & 4 deletions exercises/es/solution_02_05_02.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import spacy

nlp = spacy.load("en_core_web_sm")
nlp = spacy.load("es_core_news_sm")

# Importa la clase Doc
from spacy.tokens import Doc

# El texto deseado: "Go, get started!"
words = ["Go", ",", "get", "started", "!"]
spaces = [False, True, True, False, False]
# El texto deseado: "¡Vamos, empieza!"
words = ["¡", "Vamos", ",", "empieza", "!"]
spaces = [False, False, True, False, False]

# Crea un Doc a partir de las palabras y los espacios
doc = Doc(nlp.vocab, words=words, spaces=spaces)
Expand Down
8 changes: 4 additions & 4 deletions exercises/es/solution_02_05_03.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import spacy

nlp = spacy.load("en_core_web_sm")
nlp = spacy.load("es_core_news_sm")

# Importa la clase Doc
from spacy.tokens import Doc

# El texto deseado: "Oh, really?!"
words = ["Oh", ",", "really", "?", "!"]
spaces = [False, True, False, False, False]
# El texto deseado: "¡¿En serio?!"
words = ["¡", "¿", "En", "serio", "?", "!"]
spaces = [False, False, True, False, False, False]

# Crea un Doc a partir de las palabras y los espacios
doc = Doc(nlp.vocab, words=words, spaces=spaces)
Expand Down
6 changes: 3 additions & 3 deletions exercises/es/solution_02_06.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from spacy.lang.en import English
from spacy.lang.es import Spanish

nlp = English()
nlp = Spanish()

# Importa las clases Doc y Span
from spacy.tokens import Doc, Span

words = ["I", "like", "David", "Bowie"]
words = ["Me", "gusta", "David", "Bowie"]
spaces = [True, True, True, False]

# Crea un Doc a partir de las palabras y los espacios
Expand Down
6 changes: 3 additions & 3 deletions exercises/es/solution_02_07.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("Berlin is a nice city")
nlp = spacy.load("es_core_news_sm")
doc = nlp("Por Berlín fluye el río Esprea.")

# Itera sobre los tokens
for token in doc:
# Revisa si el token actual es un nombre propio
if token.pos_ == "PROPN":
# Revisa si el siguiente token es un verbo
if doc[token.i + 1].pos_ == "VERB":
print("Found proper noun before a verb:", token.text)
print("Encontré un nombre propio antes de un verbo:", token.text)
12 changes: 6 additions & 6 deletions exercises/es/solution_02_09.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import spacy

# Carga el modelo en_core_web_md
nlp = spacy.load("en_core_web_md")
# Carga el modelo es_core_news_md
nlp = spacy.load("es_core_news_md")

# Procesa un texto
doc = nlp("Two bananas in pyjamas")
doc = nlp("Hoy hice pan de banano")

# Obtén el vector para el token "bananas"
bananas_vector = doc[1].vector
print(bananas_vector)
# Obtén el vector para el token "banano"
banano_vector = doc[4].vector
print(banano_vector)
6 changes: 3 additions & 3 deletions exercises/es/solution_02_10_01.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import spacy

nlp = spacy.load("en_core_web_md")
nlp = spacy.load("es_core_news_md")

doc1 = nlp("It's a warm summer day")
doc2 = nlp("It's sunny outside")
doc1 = nlp("Es un cálido día de verano")
doc2 = nlp("Hace sol afuera")

# Obtén la similitud entre el doc1 y el doc2
similarity = doc1.similarity(doc2)
Expand Down
6 changes: 3 additions & 3 deletions exercises/es/solution_02_10_02.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import spacy

nlp = spacy.load("en_core_web_md")
nlp = spacy.load("es_core_news_md")

doc = nlp("TV and books")
doc = nlp("TV y libros")
token1, token2 = doc[0], doc[2]

# Obtén la similitud entre los tokens "TV" y "books"
# Obtén la similitud entre los tokens "TV" y "libros"
similarity = token1.similarity(token2)
print(similarity)
Loading

0 comments on commit b54b602

Please sign in to comment.