1 / 11

LINGUISTICA GENERALE E COMPUTAZIONALE, PARTE 2

LINGUISTICA GENERALE E COMPUTAZIONALE, PARTE 2. Lezione 3: cap. 2 Ancora Python NLTK: operazioni su corpora. Per rinfrescarsi la memoria …. Lezione passata : Python: variabili , assegnamento , liste import nltk from nltk.book import * operazioni su testi :

bjorn
Télécharger la présentation

LINGUISTICA GENERALE E COMPUTAZIONALE, PARTE 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LINGUISTICA GENERALE E COMPUTAZIONALE, PARTE 2 Lezione 3: cap. 2Ancora Python NLTK: operazionisu corpora

  2. Per rinfrescarsi la memoria … • Lezionepassata: • Python: variabili, assegnamento, liste • import nltk • from nltk.book import * • operazionisutesti: • text1.concordance(‘whale’) • operazionisustringhe: • s1.endswith(‘s’) • controllo in Python

  3. Python come un linguaggio ad oggetti • Anche se non sidirebbe, in Python ognidato ha un TIPO, come in Java o C++ • Per esempio, l’istruzionex = [1,2,3] automaticamenteassegna a xiltipo LISTA • La notazionetext1.concordance(‘whale’) significa: ‘applicailmetodo concordance del tipodioggetti a cui text1 appartiene (iltipo text in questocaso) a text1, passando la stringa ‘whale’ come argomenti • Vantaggi: e’ possibileusare la stessanotazione per operazionisimilisuoggettidiversi • Per esempio, x[0] sipuo’ applicaresiaquandoxe’ unalistachequandoxe’ unastringa

  4. Due tipi didatiimportanti in linguisticacomputazionale • Testi (lezionepassata) • Corpora (questalezione)

  5. Cos’e’ un corpus? • Unaraccoltadidocumenti • ANNOTATI omeno

  6. Operazionisu corpora in NLTK • x.fileids() (ritorna la listadituttii files nel corpus) • x.raw(fileids=[‘austen-sense.txt’]) • x.words(fileids=[‘austen-emma.txt’])

  7. Esempi: Gutenberg • nltk.corpus.gutenberg.fileids() • emma=nltk.corpus.gutenberg.words(fileids=[‘austen-emma.txt’]) • (p. 40)

  8. Corpora in NLTK • Non annotati: • Gutenberg • Annotati: • Brown (POS tags) • Reuters (generedidocumenti) • Movie reviews (sentiment) • Etc (vedip. 46-47)

  9. Crearsinuovioggettiditipo corpus • Usando le librerienltke’ possibiletrasformarequalsiasiraccoltaditesti in un oggetto ‘corpus’ dentro Python

  10. Crearenuovioggettiditipo corpus • from nltk.corpus import PlaintextCorpusReader • corpus_root=‘/Corpora/LiberLiber’ • ll=PlaintextCorpusReader(corpus_root,’.*txt’) • ll.fileids() • ll.words(‘i_promes.txt’)

  11. Ancora Python: riusodicodice • Caricaremodulidatesti • Funzioni

More Related