Skip to content

Latest commit

 

History

History
979 lines (758 loc) · 45.3 KB

NPL.md

File metadata and controls

979 lines (758 loc) · 45.3 KB
import spacy
nlp = spacy.load('en_core_web_sm')
with open ('data/wiki_us.txt', 'r') as f:
    text = f.read()
print(text)
The United States of America (U.S.A. or USA), commonly known as the United States (U.S. or US) or America, is a country primarily located in North America. It consists of 50 states, a federal district, five major unincorporated territories, 326 Indian reservations, and some minor possessions.[j] At 3.8 million square miles (9.8 million square kilometers), it is the world's third- or fourth-largest country by total area.[d] The United States shares significant land borders with Canada to the north and Mexico to the south, as well as limited maritime borders with the Bahamas, Cuba, and Russia.[22] With a population of more than 331 million people, it is the third most populous country in the world. The national capital is Washington, D.C., and the most populous city is New York.

Paleo-Indians migrated from Siberia to the North American mainland at least 12,000 years ago, and European colonization began in the 16th century. The United States emerged from the thirteen British colonies established along the East Coast. Disputes over taxation and political representation with Great Britain led to the American Revolutionary War (1775–1783), which established independence. In the late 18th century, the U.S. began expanding across North America, gradually obtaining new territories, sometimes through war, frequently displacing Native Americans, and admitting new states; by 1848, the United States spanned the continent. Slavery was legal in the southern United States until the second half of the 19th century when the American Civil War led to its abolition. The Spanish–American War and World War I established the U.S. as a world power, a status confirmed by the outcome of World War II.

During the Cold War, the United States fought the Korean War and the Vietnam War but avoided direct military conflict with the Soviet Union. The two superpowers competed in the Space Race, culminating in the 1969 spaceflight that first landed humans on the Moon. The Soviet Union's dissolution in 1991 ended the Cold War, leaving the United States as the world's sole superpower.

The United States is a federal republic and a representative democracy with three separate branches of government, including a bicameral legislature. It is a founding member of the United Nations, World Bank, International Monetary Fund, Organization of American States, NATO, and other international organizations. It is a permanent member of the United Nations Security Council. Considered a melting pot of cultures and ethnicities, its population has been profoundly shaped by centuries of immigration. The country ranks high in international measures of economic freedom, quality of life, education, and human rights, and has low levels of perceived corruption. However, the country has received criticism concerning inequality related to race, wealth and income, the use of capital punishment, high incarceration rates, and lack of universal health care.

The United States is a highly developed country, accounts for approximately a quarter of global GDP, and is the world's largest economy. By value, the United States is the world's largest importer and the second-largest exporter of goods. Although its population is only 4.2% of the world's total, it holds 29.4% of the total wealth in the world, the largest share held by any country. Making up more than a third of global military spending, it is the foremost military power in the world; and it is a leading political, cultural, and scientific force internationally.[23]
doc = nlp(text)
print(doc)
The United States of America (U.S.A. or USA), commonly known as the United States (U.S. or US) or America, is a country primarily located in North America. It consists of 50 states, a federal district, five major unincorporated territories, 326 Indian reservations, and some minor possessions.[j] At 3.8 million square miles (9.8 million square kilometers), it is the world's third- or fourth-largest country by total area.[d] The United States shares significant land borders with Canada to the north and Mexico to the south, as well as limited maritime borders with the Bahamas, Cuba, and Russia.[22] With a population of more than 331 million people, it is the third most populous country in the world. The national capital is Washington, D.C., and the most populous city is New York.

Paleo-Indians migrated from Siberia to the North American mainland at least 12,000 years ago, and European colonization began in the 16th century. The United States emerged from the thirteen British colonies established along the East Coast. Disputes over taxation and political representation with Great Britain led to the American Revolutionary War (1775–1783), which established independence. In the late 18th century, the U.S. began expanding across North America, gradually obtaining new territories, sometimes through war, frequently displacing Native Americans, and admitting new states; by 1848, the United States spanned the continent. Slavery was legal in the southern United States until the second half of the 19th century when the American Civil War led to its abolition. The Spanish–American War and World War I established the U.S. as a world power, a status confirmed by the outcome of World War II.

During the Cold War, the United States fought the Korean War and the Vietnam War but avoided direct military conflict with the Soviet Union. The two superpowers competed in the Space Race, culminating in the 1969 spaceflight that first landed humans on the Moon. The Soviet Union's dissolution in 1991 ended the Cold War, leaving the United States as the world's sole superpower.

The United States is a federal republic and a representative democracy with three separate branches of government, including a bicameral legislature. It is a founding member of the United Nations, World Bank, International Monetary Fund, Organization of American States, NATO, and other international organizations. It is a permanent member of the United Nations Security Council. Considered a melting pot of cultures and ethnicities, its population has been profoundly shaped by centuries of immigration. The country ranks high in international measures of economic freedom, quality of life, education, and human rights, and has low levels of perceived corruption. However, the country has received criticism concerning inequality related to race, wealth and income, the use of capital punishment, high incarceration rates, and lack of universal health care.

The United States is a highly developed country, accounts for approximately a quarter of global GDP, and is the world's largest economy. By value, the United States is the world's largest importer and the second-largest exporter of goods. Although its population is only 4.2% of the world's total, it holds 29.4% of the total wealth in the world, the largest share held by any country. Making up more than a third of global military spending, it is the foremost military power in the world; and it is a leading political, cultural, and scientific force internationally.[23]
print(len(text))
print(len(doc))
3521
654
for token in text[0:10]:
    print(token)
T
h
e
 
U
n
i
t
e
d
for token in doc[0:10]:
    print(token)
The
United
States
of
America
(
U.S.A.
or
USA
)
for token in text.split()[:10]:
    print(token)
The
United
States
of
America
(U.S.A.
or
USA),
commonly
known
for token in text.split(' ')[:10]:
    print(token)
The
United
States
of
America
(U.S.A.
or
USA),
commonly
known
for sent in doc.sents:
    print(sent)
The United States of America (U.S.A. or USA), commonly known as the United States (U.S. or US) or America, is a country primarily located in North America.
It consists of 50 states, a federal district, five major unincorporated territories, 326 Indian reservations, and some minor possessions.[j]
At 3.8 million square miles (9.8 million square kilometers), it is the world's third- or fourth-largest country by total area.[d] The United States shares significant land borders with Canada to the north and Mexico to the south, as well as limited maritime borders with the Bahamas, Cuba, and Russia.[22] With a population of more than 331 million people, it is the third most populous country in the world.
The national capital is Washington, D.C., and the most populous city is New York.


Paleo-Indians migrated from Siberia to the North American mainland at least 12,000 years ago, and European colonization began in the 16th century.
The United States emerged from the thirteen British colonies established along the East Coast.
Disputes over taxation and political representation with Great Britain led to the American Revolutionary War (1775–1783), which established independence.
In the late 18th century, the U.S. began expanding across North America, gradually obtaining new territories, sometimes through war, frequently displacing Native Americans, and admitting new states; by 1848, the United States spanned the continent.
Slavery was legal in the southern United States until the second half of the 19th century when the American Civil War led to its abolition.
The Spanish–American War and World War I established the U.S. as a world power, a status confirmed by the outcome of World War II.



During the Cold War, the United States fought the Korean War and the Vietnam War but avoided direct military conflict with the Soviet Union.
The two superpowers competed in the Space Race, culminating in the 1969 spaceflight that first landed humans on the Moon.
The Soviet Union's dissolution in 1991 ended the Cold War, leaving the United States as the world's sole superpower.



The United States is a federal republic and a representative democracy with three separate branches of government, including a bicameral legislature.
It is a founding member of the United Nations, World Bank, International Monetary Fund, Organization of American States, NATO, and other international organizations.
It is a permanent member of the United Nations Security Council.
Considered a melting pot of cultures and ethnicities, its population has been profoundly shaped by centuries of immigration.
The country ranks high in international measures of economic freedom, quality of life, education, and human rights, and has low levels of perceived corruption.
However, the country has received criticism concerning inequality related to race, wealth and income, the use of capital punishment, high incarceration rates, and lack of universal health care.



The United States is a highly developed country, accounts for approximately a quarter of global GDP, and is the world's largest economy.
By value, the United States is the world's largest importer and the second-largest exporter of goods.
Although its population is only 4.2% of the world's total, it holds 29.4% of the total wealth in the world, the largest share held by any country.
Making up more than a third of global military spending, it is the foremost military power in the world; and it is a leading political, cultural, and scientific force internationally.[23]
sentence1 = doc.sents[0]
print(sentence1)
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

/tmp/ipykernel_16522/2926092115.py in <module>
----> 1 sentence1 = doc.sents[0]
      2 print(sentence1)


TypeError: 'generator' object is not subscriptable
sentence1 = list(doc.sents)[0]
print(sentence1)
The United States of America (U.S.A. or USA), commonly known as the United States (U.S. or US) or America, is a country primarily located in North America.
for token in doc[:10]:
    print(token)
The
United
States
of
America
(
U.S.A.
or
USA
)
token2 = sentence1[2]
print(token2)
States
token2.text
'States'
token2.left_edge
The
token2.right_edge
America
token2.ent_type
384
token2.ent_type_
'GPE'
token2.ent_iob_
'I'
token2.lemma_
'States'
sentence1[12].lemma_
'know'
print(sentence1[12])
known
token2.morph
NounType=Prop|Number=Sing
sentence1[12].morph
Aspect=Perf|Tense=Past|VerbForm=Part
token2.pos_
'PROPN'
token2.dep_
'nsubj'
token2.lang_
'en'
text = "Mike enjoys playing football."
doc2 = nlp(text)
print(doc2)
Mike enjoys playing football.
for token in doc2:
    print(token.text, token.pos_, token.dep_)
Mike PROPN nsubj
enjoys VERB ROOT
playing VERB xcomp
football NOUN dobj
. PUNCT punct
from spacy import displacy
displacy.render(doc2, style='dep')

Mike PROPN

enjoys VERB playing VERB football. NOUN nsubj xcomp dobj
for ent in doc.ents:
    print(ent.text, ent.label_)
The United States of America GPE
U.S.A. GPE
USA GPE
the United States GPE
U.S. GPE
US GPE
America GPE
North America LOC
50 CARDINAL
five CARDINAL
326 CARDINAL
Indian NORP
3.8 million square miles QUANTITY
9.8 million square kilometers QUANTITY
fourth ORDINAL
The United States GPE
Canada GPE
Mexico GPE
Bahamas GPE
Cuba GPE
more than 331 million CARDINAL
third ORDINAL
Washington GPE
D.C. GPE
New York GPE
Paleo-Indians NORP
Siberia LOC
North American NORP
at least 12,000 years ago DATE
European NORP
the 16th century DATE
The United States GPE
thirteen CARDINAL
British NORP
the East Coast LOC
Great Britain GPE
the American Revolutionary War ORG
1775–1783 DATE
the late 18th century DATE
U.S. GPE
North America LOC
Native Americans NORP
1848 DATE
the United States GPE
United States GPE
the second half of the 19th century DATE
the American Civil War EVENT
Spanish NORP
American War and EVENT
World War EVENT
U.S. GPE
World War II EVENT
the Cold War EVENT
the United States GPE
the Korean War EVENT
the Vietnam War EVENT
the Soviet Union GPE
two CARDINAL
the Space Race FAC
1969 DATE
first ORDINAL
The Soviet Union's GPE
1991 DATE
the Cold War EVENT
the United States GPE
The United States GPE
three CARDINAL
the United Nations ORG
World Bank ORG
International Monetary Fund ORG
Organization of American States ORG
NATO ORG
the United Nations Security Council ORG
centuries DATE
The United States GPE
approximately a quarter DATE
the United States GPE
second ORDINAL
only 4.2% PERCENT
29.4% PERCENT
more than a third CARDINAL
displacy.render(doc, style='ent')

The United States of America GPE ( U.S.A. GPE or USA GPE ), commonly known as the United States GPE ( U.S. GPE or US GPE ) or America GPE , is a country primarily located in North America LOC . It consists of 50 CARDINAL states, a federal district, five CARDINAL major unincorporated territories, 326 CARDINAL

Indian NORP reservations, and some minor possessions.[j] At 3.8 million square miles QUANTITY ( 9.8 million square kilometers QUANTITY ), it is the world's third- or fourth ORDINAL -largest country by total area.[d] The United States GPE shares significant land borders with Canada GPE to the north and Mexico GPE to the south, as well as limited maritime borders with the Bahamas GPE , Cuba GPE , and Russia.[22] With a population of more than 331 million CARDINAL people, it is the third ORDINAL most populous country in the world. The national capital is Washington GPE , D.C. GPE , and the most populous city is New York GPE .

Paleo-Indians NORP migrated from Siberia LOC to the North American NORP mainland at least 12,000 years ago DATE , and European NORP colonization began in the 16th century DATE . The United States GPE emerged from the thirteen CARDINAL British NORP colonies established along the East Coast LOC . Disputes over taxation and political representation with Great Britain GPE led to the American Revolutionary War ORG ( 1775–1783 DATE ), which established independence. In the late 18th century DATE , the U.S. GPE began expanding across North America LOC , gradually obtaining new territories, sometimes through war, frequently displacing Native Americans NORP , and admitting new states; by 1848 DATE , the United States GPE spanned the continent. Slavery was legal in the southern United States GPE until the second half of the 19th century DATE when the American Civil War EVENT led to its abolition. The Spanish NORP American War and EVENT World War EVENT I established the U.S. GPE as a world power, a status confirmed by the outcome of World War II EVENT .

During the Cold War EVENT , the United States GPE fought the Korean War EVENT and the Vietnam War EVENT but avoided direct military conflict with the Soviet Union GPE . The two CARDINAL superpowers competed in the Space Race FAC , culminating in the 1969 DATE spaceflight that first ORDINAL landed humans on the Moon. The Soviet Union's GPE dissolution in 1991 DATE ended the Cold War EVENT , leaving the United States GPE as the world's sole superpower.

The United States GPE is a federal republic and a representative democracy with three CARDINAL separate branches of government, including a bicameral legislature. It is a founding member of the United Nations ORG , World Bank ORG , International Monetary Fund ORG , Organization of American States ORG , NATO ORG , and other international organizations. It is a permanent member of the United Nations Security Council ORG . Considered a melting pot of cultures and ethnicities, its population has been profoundly shaped by centuries DATE of immigration. The country ranks high in international measures of economic freedom, quality of life, education, and human rights, and has low levels of perceived corruption. However, the country has received criticism concerning inequality related to race, wealth and income, the use of capital punishment, high incarceration rates, and lack of universal health care.

The United States GPE is a highly developed country, accounts for approximately a quarter DATE of global GDP, and is the world's largest economy. By value, the United States GPE is the world's largest importer and the second ORDINAL -largest exporter of goods. Although its population is only 4.2% PERCENT of the world's total, it holds 29.4% PERCENT of the total wealth in the world, the largest share held by any country. Making up more than a third CARDINAL of global military spending, it is the foremost military power in the world; and it is a leading political, cultural, and scientific force internationally.[23]