Perpustakaan Python untuk menghitung berbagai macam metrik dari teks menggunakan komponen dan ekstensi pipa spacy v.3.
pip install textdescriptives
textdescriptives/{metric_name} . Komponen coherence baru untuk menghitung koherensi semantik antara kalimat. Lihat dokumentasi untuk tutorial dan informasi lebih lanjut! Gunakan extract_metrics untuk dengan cepat mengekstrak metrik yang Anda inginkan. Untuk melihat metode yang tersedia, Anda cukup menjalankan:
import textdescriptives as td
td . get_valid_metrics ()
# {'quality', 'readability', 'all', 'descriptive_stats', 'dependency_distance', 'pos_proportions', 'information_theory', 'coherence'} Atur parameter spacy_model untuk menentukan model spacy mana yang akan digunakan, jika tidak, TextDescriptives akan menurunkan muatan yang sesuai berdasarkan lang . Jika lang diatur, spacy_model tidak diperlukan dan sebaliknya.
Tentukan metrik mana yang akan diekstraksi dalam argumen metrics . None yang mengekstrak semua metrik.
import textdescriptives as td
text = "The world is changed. I feel it in the water. I feel it in the earth. I smell it in the air. Much that once was is lost, for none now live who remember it."
# will automatically download the relevant model (´en_core_web_lg´) and extract all metrics
df = td . extract_metrics ( text = text , lang = "en" , metrics = None )
# specify spaCy model and which metrics to extract
df = td . extract_metrics ( text = text , spacy_model = "en_core_web_lg" , metrics = [ "readability" , "coherence" ]) Untuk mengintegrasikan dengan pipa spacy lainnya, impor pustaka dan tambahkan komponen ke dalam pipa Anda menggunakan sintaks spacy standar. Komponen yang tersedia adalah deskriptif_stats , keterbacaan , ketergantungan_distance , pos_proportions , koherensi , dan kualitas diawali dengan textdescriptives/ .
Jika Anda ingin menambahkan semua komponen, Anda dapat menggunakan textdescriptives/all .
import spacy
import textdescriptives as td
# load your favourite spacy model (remember to install it first using e.g. `python -m spacy download en_core_web_sm`)
nlp = spacy . load ( "en_core_web_sm" )
nlp . add_pipe ( "textdescriptives/all" )
doc = nlp ( "The world is changed. I feel it in the water. I feel it in the earth. I smell it in the air. Much that once was is lost, for none now live who remember it." )
# access some of the values
doc . _ . readability
doc . _ . token_length TextDescriptives mencakup fungsi kenyamanan untuk mengekstraksi metrik dari Doc ke dataframe panda atau kamus.
td . extract_dict ( doc )
td . extract_df ( doc )| teks | first_order_koherence | Second_order_koherence | POS_PROP_DET | pos_prop_noun | pos_prop_aux | POS_PROP_VERB | pos_prop_punct | POS_PROP_PRON | pos_prop_adp | pos_prop_adv | POS_PROP_SCONJ | flesch_reading_ease | flesch_kincaid_grade | asbut | Gunning_fog | otomatis_readability_index | coleman_liau_index | lix | RIX | n_stop_words | alpha_ratio | rata -rata_word_length | doc_length | proporsi_ellipsis | proporsi_bullet_points | duplicate_line_chr_fraction | duplicate_paragraph_chr_fraction | duplicate_5-gram_chr_fraction | duplicate_6-gram_chr_fraction | duplicate_7-gram_chr_fraction | duplicate_8-gram_chr_fraction | duplicate_9-gram_chr_fraction | duplicate_10-gram_chr_fraction | top_2-gram_chr_fraction | top_3-gram_chr_fraction | top_4-gram_chr_fraction | Simbol _#_ to_word_ratio | mengandung ipsum | lulus_quality_check | dependency_distance_mean | Dependency_distance_std | prop_adjacent_dependency_relation_mean | prop_adjacent_dependency_relation_std | token_length_mean | token_length_median | token_length_std | SENTENCE_LENGTH_MEAN | kalimat_length_median | SENTENCE_LENGTH_STD | sillable_per_token_mean | sillable_per_token_median | sillable_per_token_std | n_tokens | n_unique_tokens | proporsi_unique_tokens | n_characters | n_sentences | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Dunia diubah (...) | 0.633002 | 0.573323 | 0.097561 | 0.121951 | 0.0731707 | 0.170732 | 0.146341 | 0.195122 | 0.0731707 | 0.0731707 | 0.0487805 | 107.879 | -0.0485714 | 5.68392 | 3.94286 | -2.45429 | -0.708571 | 12.7143 | 0.4 | 24 | 0.853659 | 2.95122 | 41 | 0 | 0 | 0 | 0 | 0.232258 | 0.232258 | 0 | 0 | 0 | 0 | 0.0580645 | 0.174194 | 0 | 0 | PALSU | PALSU | 1.77524 | 0.553188 | 0.457143 | 0.0722806 | 3.28571 | 3 | 1.54127 | 7 | 6 | 3.09839 | 1.08571 | 1 | 0.368117 | 35 | 23 | 0.657143 | 121 | 5 |
TextDescriptives memiliki dokumentasi terperinci serta serangkaian tutorial notebook Jupyter. Semua tutorial terletak di folder docs/tutorials dan juga dapat ditemukan di situs web dokumentasi.
| Dokumentasi | |
|---|---|
| Memulai | Panduan dan instruksi tentang cara menggunakan TextDescriptives dan fitur -fiturnya. |
| ? demo | Demo langsung dari TextDescriptives. |
| ? Tutorial | Tutorial terperinci tentang cara memanfaatkan skrip teks sebaik -baiknya |
| ? Berita dan Changelog | Penambahan baru, perubahan dan riwayat versi. |
| ? Referensi API | Referensi terperinci untuk API TextDescriptive. Termasuk dokumentasi fungsi |
| ? Kertas | Pracetak kertas TextDescriptives. |