{"id":936,"date":"2023-05-22T10:35:04","date_gmt":"2023-05-22T08:35:04","guid":{"rendered":"https:\/\/inseri.swiss\/?p=936"},"modified":"2024-11-11T10:35:04","modified_gmt":"2024-11-11T10:35:04","slug":"word-count","status":"publish","type":"post","link":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/2023\/05\/word-count\/","title":{"rendered":"Word Count"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Next we will show how to build a Word Count where we will allow the usage of local files. This will allow the visitors to import their local text file and explore the most used 10 words.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We use the <strong>Local File Import<\/strong> block to allow the visitors to import a local file.<\/p>\n\n\n\n<div class=\"wp-block-inseri-core-file-drop\" data-attributes=\"{&quot;accepts&quot;:[],&quot;blockId&quot;:&quot;C11DC0rUdCsN780vuMNUX&quot;,&quot;height&quot;:150,&quot;mainText&quot;:&quot;Drag and drop a text file or click here&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;File Drop&quot;},&quot;multiple&quot;:false,&quot;subText&quot;:&quot;provide your text file to process...&quot;}\">is loading &#8230;<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Below we display the content of the file using the <strong>Text Viewer<\/strong> block.<\/p>\n\n\n\n<div class=\"wp-block-inseri-core-text-viewer\" data-attributes=\"{&quot;blockId&quot;:&quot;VR7yBfW0Waaj9kVocNaCn&quot;,&quot;content&quot;:&quot;&quot;,&quot;height&quot;:150,&quot;inputKey&quot;:&quot;C11DC0rUdCsN780vuMNUX\/data&quot;,&quot;label&quot;:&quot;The content of the imported text file&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;Text Viewer&quot;}}\">is loading &#8230;<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">We use the <strong>Python Code<\/strong> block to find the most used 10 words that we prepare as an html using the <a rel=\"noreferrer noopener\" href=\"https:\/\/pandas.pydata.org\/\" target=\"_blank\"><strong>pandas<\/strong><\/a> Python package. <\/p>\n\n\n\n<div class=\"wp-block-inseri-core-python\" data-attributes=\"{&quot;autoTrigger&quot;:false,&quot;blockId&quot;:&quot;YdFQOEeVrl7LUzUNcL0UI&quot;,&quot;content&quot;:&quot;from%20collections%20import%20Counter%0A%0A%23%20text%20is%20the%20content%20of%20the%20imported%20local%20file%20%0Awords%20%3D%20text.split()%0Awords%20%3D%20%5Bel.lower()%20for%20el%20in%20words%5D%0Aword_counter%20%3D%20Counter(words)%0Atop_10%20%3D%20word_counter.most_common(10)%0A%0Aimport%20pandas%20as%20pd%0A%0Adf%20%3D%20pd.DataFrame(top_10%2C%20columns%3D%5B%22Word%22%2C%20%22Count%22%5D)%0Adf_as_records%20%3D%20df.to_dict(orient%3D%22records%22)&quot;,&quot;editable&quot;:false,&quot;height&quot;:150,&quot;inputCode&quot;:&quot;&quot;,&quot;inputs&quot;:{&quot;text&quot;:&quot;C11DC0rUdCsN780vuMNUX\/data&quot;},&quot;isVisible&quot;:true,&quot;label&quot;:&quot;&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;Python&quot;},&quot;mode&quot;:&quot;editor&quot;,&quot;outputs&quot;:[[&quot;df_as_records&quot;,&quot;application\/json&quot;]]}\">is loading &#8230;<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">And in the last step we display the table using the <strong>Data Table<\/strong> block.<\/p>\n\n\n\n<div class=\"wp-block-inseri-core-data-table\" data-attributes=\"{&quot;blockId&quot;:&quot;GVcfASxxD7gHYAyi0hTZk&quot;,&quot;extraOptions&quot;:{&quot;enableCellClick&quot;:true,&quot;enableEditing&quot;:false,&quot;enableRowClick&quot;:true},&quot;inputColumns&quot;:&quot;&quot;,&quot;inputData&quot;:&quot;YdFQOEeVrl7LUzUNcL0UI\/df_as_records&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;Data Table&quot;},&quot;options&quot;:{&quot;enableBottomToolbar&quot;:true,&quot;enableColumnActions&quot;:true,&quot;enableColumnFilters&quot;:false,&quot;enableColumnOrdering&quot;:false,&quot;enableDensityToggle&quot;:true,&quot;enableFullScreenToggle&quot;:true,&quot;enableGlobalFilter&quot;:true,&quot;enableHiding&quot;:true,&quot;enablePagination&quot;:true,&quot;enableRowVirtualization&quot;:false,&quot;enableSorting&quot;:true,&quot;enableTopToolbar&quot;:true}}\">is loading &#8230;<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">We can easily visualise the <a href=\"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/2023\/05\/word-count\/\" target=\"_blank\" rel=\"noreferrer noopener\">Data Flow<\/a> using the Cytoscape block.<\/p>\n\n\n\n<div class=\"wp-block-inseri-core-cytoscape\" data-attributes=\"{&quot;blockId&quot;:&quot;pnolTrkIr6IdaEAsvxhOm&quot;,&quot;height&quot;:274,&quot;inputKey&quot;:&quot;__root\/data-flow&quot;,&quot;layout&quot;:&quot;dagre&quot;,&quot;layoutKey&quot;:&quot;&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;DataFlow&quot;},&quot;styleKey&quot;:&quot;&quot;}\">is loading &#8230;<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-f56f613f wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-inseri-core-export alignright\" data-attributes=\"{&quot;align&quot;:&quot;right&quot;,&quot;blockId&quot;:&quot;vaxQQCzmrnvQCf4meQgfk&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;export&quot;},&quot;postId&quot;:936}\">is loading &#8230;<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-inseri-core-share alignright\" data-attributes=\"{&quot;align&quot;:&quot;right&quot;,&quot;blockId&quot;:&quot;KTETwIissQyi0jL3ZpuwV&quot;,&quot;copiedText&quot;:&quot;Copied&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;share&quot;},&quot;showIcon&quot;:true,&quot;text&quot;:&quot;Share&quot;}\">is loading &#8230;<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Next we will show how to build a Word Count where we will allow the usage of local files. This will allow the visitors to import their local text file and explore the most used 10 words. We use the Local File Import block to allow the visitors to import a local file. Below we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[36,37,40,45,48,50,53],"class_list":["post-936","post","type-post","status-publish","format-standard","hentry","category-basic-example","tag-cytoscape","tag-data-table","tag-export","tag-local-file-import","tag-python-code","tag-share","tag-text-viewer"],"_links":{"self":[{"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/comments?post=936"}],"version-history":[{"count":1,"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"predecessor-version":[{"id":2120,"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/936\/revisions\/2120"}],"wp:attachment":[{"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}