forked from hankcs/HanLP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoWordDistance.java
More file actions
59 lines (57 loc) · 1.91 KB
/
DemoWordDistance.java
File metadata and controls
59 lines (57 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* <summary></summary>
* <author>He Han</author>
* <email>hankcs.cn@gmail.com</email>
* <create-date>2014/12/9 13:49</create-date>
*
* <copyright file="DemoWordDistance.java" company="上海林原信息科技有限公司">
* Copyright (c) 2003-2014, 上海林原信息科技有限公司. All Right Reserved, http://www.linrunsoft.com/
* This source is subject to the LinrunSpace License. Please contact 上海林原信息科技有限公司 to get more information.
* </copyright>
*/
package com.hankcs.demo;
import com.hankcs.hanlp.dictionary.CoreSynonymDictionary;
/**
* 语义距离
* @author hankcs
* @deprecated 请使用word2vec
*/
public class DemoWordDistance
{
public static void main(String[] args)
{
String[] wordArray = new String[]
{
"香蕉",
"苹果",
"白菜",
"水果",
"蔬菜",
"自行车",
"公交车",
"飞机",
"买",
"卖",
"购入",
"新年",
"春节",
"丢失",
"补办",
"办理",
"送给",
"寻找",
"孩子",
"教室",
"教师",
"会计",
};
System.out.printf("%-5s\t%-5s\t%-10s\t%-5s\n", "词A", "词B", "语义距离", "语义相似度");
for (String a : wordArray)
{
for (String b : wordArray)
{
System.out.printf("%-5s\t%-5s\t%-15d\t%-5.10f\n", a, b, CoreSynonymDictionary.distance(a, b), CoreSynonymDictionary.similarity(a, b));
}
}
}
}