Original: Http://mp.weixin.qq.com/s/sqa-Ca2oXhvcPHJKg9PuVg
ImportSPACYNLP= Spacy.load ("EN_CORE_WEB_SM") Doc= NLP ("The big grey dog ate all of the chocalate,but fortunately he wasn ' t sick!")#use spaces to separatePrint(Doc.text.split ())#use token's. Orth_ method to identify punctuationPrint([Token.orth_ forTokeninchDoc])#An underlined method returns a character, without an underlined method, to return a numberPrint(token, token.orth_, Token.orth) forTokeninchDoc])#participle, remove punctuation and spacesPrint([Token.orth_ forTokeninchDocif nottoken.is_punct |Token.is_space])#standardization to the basic formPractice ="practice practiced practicing"Nlp_practice=NLP (Practice)Print([Word.lemma_ forWordinchNlp_practice])#POS tagging can use the. Pos_ and. Tag_ methods to access coarse-grained pos tags and fine-grained pos tagsDOC2 = NLP ("Conor's dog's toy was hidden under the man's sofa in the woman's house") Pos_tags= [(I, I.tag_) forIinchDOC2]Print(pos_tags)#the label of ' s is marked as POS. You can use this tag to extract the owner and what they have .Owners_possessions = [] forIinchPos_tags:ifI[1] = ="POS": Owner= I[0].nbor (-1) Possession= I[0].nbor (1) Owners_possessions.append ((owner, possession) )Print(owners_possessions)#Simplifying CodePrint([(I[0].nbor ( -1), I[0].nbor (1)) forIinchPos_tagsifI[1] = ="POS"])#entity Identification person is self-evident; Norp is a nationality or religious group; GGPE identifies the location (city, country, and so on); date identifies a specific date or date range, ordinal identifies a word or number that represents the order of some kind. Wiki_obama ="""Barack Obama is a American politician who served as the 44th President of the all States from 2017. He is the first African American to has served as president, as well as the first born outside the contiguous Es."""Nlp_obama=NLP (Wiki_obama)Print([(I, I.label_, I.label) forIinchnlp_obama.ents])#divide the article into sentences forIX, SentinchEnumerate (nlp_obama.sents,1): Print("sentence number {}:{}". Format (ix,sent))
Python uses spacy for NLP processing