Python uses spacy for NLP processing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.