@@ -2,7 +2,7 @@ import { clone } from '@antv/util';
2
2
import getAdjMatrix from './adjacent-matrix' ;
3
3
import { NodeConfig , ClusterData , GraphData , ClusterMap } from './types' ;
4
4
import Vector from './utils/vector' ;
5
- import { secondReg , dateReg } from './constants/time ' ;
5
+ import { getPropertyWeight } from './utils/node-properties ' ;
6
6
7
7
const getModularity = (
8
8
nodes : NodeConfig [ ] ,
@@ -28,59 +28,6 @@ const getModularity = (
28
28
return modularity ;
29
29
}
30
30
31
- // 获取所有属性并排序
32
- const getAllSortProperties = ( nodes : NodeConfig [ ] = [ ] ) => {
33
- const propertyKeyInfo = { } ;
34
- nodes . forEach ( node => {
35
- Object . keys ( node . properties ) . forEach ( propertyKey => {
36
- // 目前过滤只保留可以转成数值型的或日期型的, todo: 统一转成one-hot特征向量
37
- if ( ! `${ node . properties [ propertyKey ] } ` . match ( secondReg ) &&
38
- ! `${ node . properties [ propertyKey ] } ` . match ( dateReg ) &&
39
- isNaN ( Number ( node . properties [ propertyKey ] ) ) || propertyKey === 'id' ) {
40
- if ( propertyKeyInfo . hasOwnProperty ( propertyKey ) ) {
41
- delete propertyKeyInfo [ propertyKey ] ;
42
- }
43
- return ;
44
- }
45
- if ( propertyKeyInfo . hasOwnProperty ( propertyKey ) ) {
46
- propertyKeyInfo [ propertyKey ] += 1 ;
47
- } else {
48
- propertyKeyInfo [ propertyKey ] = 1 ;
49
- }
50
- } )
51
- } )
52
-
53
- // 取top50的属性
54
- const sortKeys = Object . keys ( propertyKeyInfo ) . sort ( ( a , b ) => {
55
- return propertyKeyInfo [ b ] - propertyKeyInfo [ a ] ;
56
- } ) ;
57
- return sortKeys . length < 100 ? sortKeys : sortKeys . slice ( 0 , 100 ) ;
58
- }
59
-
60
- const processProperty = ( properties , propertyKeys ) => propertyKeys . map ( key => {
61
- if ( properties . hasOwnProperty ( key ) ) {
62
- // 可以转成数值的直接转成数值
63
- if ( ! isNaN ( Number ( properties [ key ] ) ) ) {
64
- return Number ( properties [ key ] ) ;
65
- }
66
- // 时间型的转成时间戳
67
- if ( properties [ key ] . match ( secondReg ) || properties [ key ] . match ( dateReg ) ) {
68
- // @ts -ignore
69
- return Number ( Date . parse ( new Date ( properties [ key ] ) ) ) / 1000 ;
70
- }
71
- }
72
- return 0 ;
73
- } )
74
-
75
- // 获取属性特征权重
76
- const getPropertyWeight = ( propertyKeys , nodes ) => {
77
- let allPropertiesWeight = [ ] ;
78
- for ( let i = 0 ; i < nodes . length ; i ++ ) {
79
- allPropertiesWeight [ i ] = processProperty ( nodes [ i ] . properties , propertyKeys ) ;
80
- }
81
- return allPropertiesWeight ;
82
- }
83
-
84
31
// 模块惯性度,衡量属性相似度
85
32
const getInertialModularity = (
86
33
nodes : NodeConfig [ ] = [ ] ,
@@ -171,9 +118,8 @@ const louvain = (
171
118
node . properties . nodeType = nodeTypeInfo . findIndex ( nodeType => nodeType === node . nodeType ) ;
172
119
} )
173
120
}
174
- const propertyKeys = getAllSortProperties ( nodes ) ;
175
121
// 所有节点属性特征向量集合
176
- allPropertiesWeight = getPropertyWeight ( propertyKeys , nodes ) ;
122
+ allPropertiesWeight = getPropertyWeight ( nodes ) ;
177
123
}
178
124
179
125
let uniqueId = 1 ;
0 commit comments