加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

操作文本发掘技能来找出收集中的“小鲜词”

发布时间:2021-01-18 05:51:30 所属栏目:大数据 来源:网络整理
导读:开始之前,先看一下从大家网中发明的90后用户爱用的词 是不是很好玩,哈哈。写这篇文章就是让你简朴的自动的从文本中找出新的词,这样就知道此刻的年青人喜好什么了(对付博主这种上了岁数的人来说,真的是很有效,呜呜) 项目布局 虽然,text.dat和common.d
副问题[/!--empirenews.page--]

开始之前,先看一下从大家网中发明的90后用户爱用的词

这里写图片描写

是不是很好玩,哈哈。写这篇文章就是让你简朴的自动的从文本中找出新的词,这样就知道此刻的年青人喜好什么了(对付博主这种上了岁数的人来说,真的是很有效,呜呜)

项目布局

操作文本发掘技能来找出收集中的“小鲜词”

虽然,text.dat和common.dic这两个文件你可以随意替代,留意text.dat中的数据必然要够份量,不然没啥结果

道理么,看下Matrix67大牛的文章你就懂了

互联网期间的社会说话学:基于SNS的文本数据发掘

实习数据下载

下边开始上代码

common

这个里边包括以下几个类,首要是界说数据布局

这里写图片描写

CountMap.java

界说一个计数Map来举办数据操纵和耐久化

package grid.common;

import java.io.Serializable;
import java.util.HashMap;


public class CountMap<T> extends HashMap<T,Integer> implements Serializable {

    private static final long serialVersionUID = 6097963798841161750L;

    public void increase(T t) {//添加元素
        Integer count = get(t);
        if (null == count) {
            put(t,1);
        } else {
            put(t,++count);
        }
    }

    public int count() {   //计数
        int count = 0;
        for (T t : keySet()) {
            count += get(t);
        }
        return count;
    }

    public int get(char c) {
        Integer count = super.get(c);
        return null == count ? 0 : count;
    }
}

Node.java

界说语法树的节点

package grid.common;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Node<T> {
    protected List<Node<T>> children;

    protected Node<T> parent;

    protected T value;

    Node(T value) {
        this.value = value;
    }

    public Node<T> add(T value) {
        if (null == children) {
            children = new ArrayList<Node<T>>();
        }
        Node<T> child = new Node<T>(value);
        child.setParent(this);
        children.add(child);
        return child;
    }

    public T getValue() {
        return value;
    }

    public Node<T> getParent() {
        return parent;
    }

    public void setParent(Node<T> parent) {
        this.parent = parent;
    }

    private void recurseChildren(List<Node<T>> list,Node<T> parent) {
        if (null == parent.children) {
            list.add(parent);
        } else {
            for (Node<T> node : parent.children) {
                recurseChildren(list,node);
            }
        }
    }

    public List<Node<T>> getLeaves() {
        List<Node<T>> list = new ArrayList<Node<T>>();
        recurseChildren(list,this);
        return list;

    }

    public List<T> getBranchPath() {
        List<T> list = new ArrayList<T>();
        Node<T> node = this;
        do {
            list.add(node.getValue());
            node = node.parent;
        } while (null != node && !(node instanceof Tree<?>));
        Collections.reverse(list);
        return list;
    }

    private void append(StringBuilder builder,int deep,Node<T> node) {
        for (int i = 0; i < deep; i++) {
            builder.append(" ");
        }
        builder.append("|--");
        builder.append(node.getValue());
        builder.append("n");
        if (null != node.children) {
            for (Node<T> child : node.children) {
                append(builder,deep + 1,child);
            }
        }
    }

    public String dump() {
        StringBuilder builder = new StringBuilder();
        append(builder,0,this);
        return builder.toString();
    }

    public String toString() {
        return value.toString();
    }
}

TextDatReader.java

读取实习数据

package grid.common;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;


public class TextDatReader {
    public static String read(String path) throws IOException {
        File file = new File(path);
        FileReader reader = new FileReader(file);
        char buffer[] = new char[(int) file.length()];
        reader.read(buffer);
        return new String(buffer);
    }
}

TextUtils.java

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读