java 怎么样统计一篇文章有几个java段落注释

Java实现的词频统计 - 终不悔 - 博客园
1.读取文件;
2.记录出现的词汇及出现频率;
3.按照频率降序排列;
4.输出结果。
1.读取的文件路径是默认的,为了方便调试,将要统计的文章、段落复制到文本中即可;2.只支持英文;3.会按照词汇出现的频率降序排列。
1.使用FileReader、BufferedReader读取文件;
2.采用StringTokenizer进行字符分割;
3.用hashmap保存统计数据;
4.自定义一个类用来实现按value排序;
5.输出结果。
默认路径文件:
String filename = "E:/Test.txt";
FileReader fk = new FileReader(filename);
BufferedReader br = new BufferedReader(fk);
统计词频:
while((s = br.readLine()) != null) {
file += //读出整篇文章,存入String类的file中。
StringTokenizer st = new StringTokenizer(file," ,.!?\"'"); //用于切分字符串
while(st.hasMoreTokens()) {
String word = st.nextToken();
if(hm.get(word) != null) {
int value = ((Integer)hm.get(word)).intValue();
hm.put(word, new Integer(value));
hm.put(word, new Integer(1));
1 import java.util.C
2 import java.util.TreeM
4 public class ByValueComparator implements Comparator&String& {
TreeMap&String, Integer&
public ByValueComparator(TreeMap&String, Integer& tm) {
this.treemap =
public int compare(String o1, String o2) {
// TODO Auto-generated method stub
if(!treemap.containsKey(o1) || !treemap.containsKey(o2)) {
if(treemap.get(o1) & treemap.get(o2)) {
} else if(treemap.get(o1) == treemap.get(o2)) {
return -1;
输出结果:
TreeMap tm = new TreeMap(hm);
ByValueComparator bvc = new ByValueComparator(tm);
List&String& ll = new ArrayList&String&(tm.keySet());
Collections.sort(ll, bvc);
for(String str:ll){
System.out.println(str+"&&"+tm.get(str));
实例验证:
There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! Dream whgo be what you want to be,because you have only one life and one chance to do all the things you want to do.
May you have enough happiness to make you sweet,enough trials to make you strong,enough sorrow to keep you human,enough hope to make you happy? Always put yourself in others&shoes.If you feel that it hurts you,it probably hurts the other person, too.
The happiest of people don&t necessarily have ththey just make the most of everything that comes along their way.Happiness lies for those who cry,those who hurt, those who have searched,and those who have tried,for only they can appreciate the importance of people
who have touched their lives.Love begins with a smile,grows with a kiss and ends with a tear.The brightest future will always be based on a forgotten past, you can&t go on well in lifeuntil you let go of your past failures and heartaches.
When you were born,you were crying and everyone around you was smiling.Live your life so that when you die,you're the one who is smiling and everyone around you is crying.
Please send this message to those people who mean something to you,to those who have touched your life in one way or another,to those who make you smile when you really need it,to those that make you see the brighter side of things when you are really down,to those who you want to let them know that you appreciate their friendship.And if you don&t, don&t worry,nothing bad will happen to you,you will just miss out on the opportunity to brighten someone&s day with this message.
  结果:
touched&&2
smiling&&2
message&&2
everyone&&2
appreciate&&2
another&&1
Happiness&&1
brightest&&1
brighter&&1
brighten&&1
because&&1
friendship&&1
forgotten&&1
failures&&1
everything&&1
importance&&1
heartaches&&1
happiness&&1
happiest&&1
opportunity&&1
nothing&&1
necessarily&&1
moments&&1
lifeuntil&&1
searched&&1
probably&&1
peoplewho&&1
others&shoes&&1
something&&1
someone&s&&1
someone&&1
yourself&&1
代码地址:https://coding.net/u/regretless/p/WordFrequencyCount/gitJAVA统计一篇文章中所有单词出现的次数,并按字典序将单词及频数输出到文件中
JAVA统计一篇文章中所有单词出现的次数,并按字典序将单词及频数输出到文件中
首先实现做一个SortedMap,这个Map的Comparator是根据字母顺序排列的一个规则.(参考java编程思想11章9节.1)把这个map实现出来以后就简单了.把整个文章用space做分割,然后放到Map中,key就是这个单词,值就是他出现的次数,最后一输出就可以了.
与《JAVA统计一篇文章中所有单词出现的次数,并按字典序将单词及频数输出到文件中》相关的作业问题
你把你那篇文章弄到word里面按CTRL+H键就可以找到了,不过是一个一个的,快的没有.
你把你的代码发到我的邮箱 我帮你设计排序,以及后面的需求,具体的细节我们可以QQ聊. 不过一般我只能下班或者周末在线,如果不方便 你把你的需求写详细点 发到我的邮箱里面也行.
只能统计字的,要统计单词的话要做数据库的,不然随便输入几个数字字母的不好统计.这个程序不好做.
告诉你思路吧!判断空格就可以了,然后在判断下标点.如果空格后的第一个是字母,到空格结尾.就是一个单词!
把TXT 文件 拷到 word里,用“^p”代替“空格”,然后把word里的内容拷到Excel里,然后排序,再分类汇总(选计数)即可. 再问: 大哥,要用spss弄啊,我后期还要算分布什么的 再答: 你的问题出在把txt文章直接导入了,你必须把TXT文件的格式做成“一个字段”,“多条记录”的形式,再导入到spss中去,
var ch: i: a:array[1..255]begin read(ch); while not eof do begin if(ch>='a') and (ch='A') and (ch
ctrl+f,查找功能就可以.
简单你用替换命令,输入你要统计的字,再输入要替换的字(随便什么字),然后按“全部替换”,那么WORD会弹出1个对话筐告诉你替换了多少处,那就知道这个字出现了多少次啦,然后再用退后还原原来的更改就好啦!
推荐用Replace Pioneer的Pattern Counter 来统计,然后可以把结果拷贝到剪贴板里.详细步骤:首先需要把该文章保存为txt文本文件,然后:1.安装并打开Replace Pioneer,选择Tools->Pattern Counter菜单2.在上面的Source选择 File/http,然后在右边
推荐用Replace Pioneer的Pattern Counter 来统计,然后可以拷贝到剪贴板里.详细步骤:首先需要把该文章保存为txt文本文件,然后:1. 安装并打开Replace Pioneer, 选择Tools->Pattern Counter菜单2. 在上面的Source选择 File/http,然后在右边
我以前做过类似的预料分析,但是是手算的.中文目前似乎没有这样的软件. 再问: 可是10万字的语料岂不是算死?请问有没有什么合适的标注词性的软件推荐? 再答: 这我就不熟悉了,你可以问问看你的老师,据我的经验,一般是雇佣劳动力来做预料分析的。
一句话,由英文字母,数字及常用标点符号组成.统计句子中各单词出现的次数,并按(&单词的个数为:%d&,(n_num+c
1,可以利用组公式的方式来实现,组公式“{=SUM(LEN(单元格区域范围))}”,具体方法,在需要统计字数的单元格的后面一个单元格输入公式“{=SUM(LEN(A1:D1))}”,最后按“Ctrl+Shift+Enter”组合键,就能看到该区域的字数.2,复制到word,里面有专门的工具 再问: 十分抱歉,能够写的详
时光重新回到现在,上帝说现在该口服心服了吧?约翰哀求道:“主啊,请您再给出我一次机会吧~!”上帝摇摇头说:“不用了.现在,你应该明白了吧,苹果砸在每个人有关当局上的机会都是相同的,关键的是每个人把握机会是能力不同啊!”主要人物:上帝,约翰
I think a sentence is the basis of an article to improve writing ability,usually to accumulate more than words,only good can form a good sentence article.
The giant panda is not only a rare animal in China but also one of the rarest animals on the earth. It is loved by people all over the world. The home of the gi
单词是一定要记得的,我建议你看一句翻译一句,多看英语,多翻译,就可以了
import java.io.Fimport java.io.FileNotFoundEimport java.io.PrintWimport java.util.Rpublic class Main {/** * @param args * @throws Fi
选中你需要复制的值--复制--右键(选择性粘贴)--数值---在你想放数值的位置粘贴. 再问: 3Q文章的阅读量怎么统计 - Java Web开发当前位置:& &&&文章的阅读量怎么统计文章的阅读量怎么统计www.MyException.Cn&&网友分享于:&&浏览:35次文章的阅读量如何统计?如题。在数据库里建了个Click字段,是int类型。代码如下:
& String condition=&UPDATE User_News_Site SET Click = Click+ 1 where id='&+request.getParameter(&News_Id&)+&'&;stmt11.executeUpdate(condition);运行时阅读量不变。是什么错误呢?高手帮忙,谢了!------解决方案--------------------
先将字段select出来,加1后再update,是否可行?
------解决方案--------------------引用楼主 haomeina 的帖子:如题。 在数据库里建了个Click字段,是int类型。代码如下:
String condition=&UPDATE User_News_Site SET Click = Click+ 1 where id='&+request.getParameter(&News_Id&)+&'&; stmt11.executeUpdate(condition); 运行时阅读量不变。 是什么错误呢?高手帮忙,谢了!
------解决方案--------------------
可以在做一个标识放到session中,例如session.setAttribute(&Flag&,&true&)页面部分String flag = (String)session.getAttribue(&Flag&);if(null!=flag&&&true&.equals(flag)){}else{//你更新的操作session.setAttribute(&Flag&,&true&)}
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有* 需求:统计字符串中每个字母:
* 说明:编写程序,提示用户输入一个字符串,
* 然后统计字符串中每个字母出现的个数,忽略字母的大小写。
* 1.使用...
C程序设计(第四版) 谭浩强 习题6.10 个人设计习题 6.10 有一篇文章,共有3行文字,每行有80个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数。代码块:#inc...
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
该程序打开一篇英文文章的文本文件,将其内容读入缓冲区中,之后累加字母数,数字数和空格数即可。
#define MAX 1024
int main()
思路:每次从文件中读取一行放到缓存数组中,遍历该数组,单词个数等于空格个数加1,句子个数等于?、!、。个数之和, 用isalpha()统计非字母字符个数,, 要去掉空格, 头文件可统计时间, 处理"....
这是CC视频的最后一道面试题,当时纯手写写的还不错,不过在匹配英文单词的时候大小写的情况没有统一([a-zA-Z]和toLowerCase()),回来之后重新写了。...
package com.test.
import java.io.BufferedR
import java.io.BufferedW
import java....
从文件中读取一篇英语文章,统计每个单词出现的频率,输出十个最长出现的单词及次数图像。
import turtle
count = 10
xscale = 30
yscale = 6
A - Hardwood Species(7.1.1)(利用STL中自带的排序功能编程的实验范例)
Crawling in process...
Crawling fai...
# -*- coding: utf-8 -*-
def findPart(regex,text,name):
res=re.finda...
他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 java 读取 word 段落 的文章

 

随机推荐