Python‎ > ‎

spaCy NLP


(written at version 3.03)

pip install spacy

python -m spacy download en_core_web_sm

If this fails due to school restrictions, then the following is a workaround...

1. Download the zip file

download/en_core_web_sm-2.2.5/en_core_web_sm-2.2.5.tar.gz

2. Decompress the folders
7zip unzip the .zip file, this reveals a .tar file
7zip to decompress the .tar file

3. Copy folders to Python site-packages

Copy 2 folders:
en_core_web_sm
en_core_web_sm.egg-info

to C:\Users\<username>\AppData\Local\Programs\Python\Python38\Lib\site-packages


Sample Code

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

def getName(speech):
        name = []
        doc = nlp(speech.title()+" And")

        # Parts of Speech (POS) Tagging
        for token in doc:
            #print(token.text, token.lemma_, token.pos_, token.tag_, token.dep_, token.shape_, token.is_alpha, token.is_stop)
            if token.pos_ in ["PROPN"]:
                #print("found one")
                name.append(token.text)

        name = " ".join(name)
        #print(f" 2: {name}")
        return name

name = getName('Hello my name is john')
print(name)

Comments