-
Notifications
You must be signed in to change notification settings - Fork 3
/
display.jl
93 lines (83 loc) · 3.05 KB
/
display.jl
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
display_matrix(M, rownames, colnames)
Display matrix with rownames and colnames.
"""
function display_matrix(M, rownames, colnames; nrow=6, ncol=6, return_matrix=false)
M_part = M[1:nrow, 1:ncol]
rownames_part = rownames[1:nrow]
colnames_part = colnames[1:ncol]
df = DataFrame()
df[!, :Data] = rownames_part
for (i,coln) in enumerate(colnames_part)
df[!, coln] = M_part[:,i]
end
display(df)
if return_matrix
return(df)
end
end
"""
display_matrix(data, target_col, cue_obj, M, M_type)
Display matrix with rownames and colnames.
# Obligatory Arguments
- `data::DataFrame`: the dataset
- `target_col::Union{String, Symbol}`: the target column name
- `cue_obj::Cue_Matrix_Struct`: the cue matrix structure
- `M::Union{SparseMatrixCSC, Matrix}`: the matrix
- `M_type::Union{String, Symbol}`: the type of the matrix, currently support :C, :S, :F, :G, :Chat, :Shat, :A and :R
# Optional Arguments
- `nrow::Int64 = 6`: the number of rows to display
- `ncol::Int64 = 6`: the number of columns to display
- `return_matrix::Bool = false`: whether the created dataframe should be returned (and not only displayed)
# Examples
```julia
JudiLing.display_matrix(latin, :Word, cue_obj, cue_obj.C, :C)
JudiLing.display_matrix(latin, :Word, cue_obj, S, :S)
JudiLing.display_matrix(latin, :Word, cue_obj, G, :G)
JudiLing.display_matrix(latin, :Word, cue_obj, Chat, :Chat)
JudiLing.display_matrix(latin, :Word, cue_obj, F, :F)
JudiLing.display_matrix(latin, :Word, cue_obj, Shat, :Shat)
JudiLing.display_matrix(latin, :Word, cue_obj, A, :A)
JudiLing.display_matrix(latin, :Word, cue_obj, R, :R)
```
"""
function display_matrix(
data,
target_col,
cue_obj,
M,
M_type;
nrow = 6,
ncol = 6,
return_matrix=false
)
if M_type == :C || M_type == "C"
rownames = data[:,target_col]
colnames = [cue_obj.i2f[i] for i in 1:size(M,2)]
elseif M_type == :Chat || M_type == "Chat"
rownames = data[:,target_col]
colnames = [cue_obj.i2f[i] for i in 1:size(M,2)]
elseif M_type == :S || M_type == "S"
rownames = data[:,target_col]
colnames = ["S$i" for i in 1:size(M,2)]
elseif M_type == :Shat || M_type == "Shat"
rownames = data[:,target_col]
colnames = ["S$i" for i in 1:size(M,2)]
elseif M_type == :F || M_type == "F"
rownames = [cue_obj.i2f[i] for i in 1:size(M,1)]
colnames = ["S$i" for i in 1:size(M,2)]
elseif M_type == :G || M_type == "G"
rownames = ["S$i" for i in 1:size(M,1)]
colnames = [cue_obj.i2f[i] for i in 1:size(M,2)]
elseif M_type == :A || M_type == "A"
rownames = [cue_obj.i2f[i] for i in 1:size(M,1)]
colnames = [cue_obj.i2f[i] for i in 1:size(M,2)]
elseif M_type == :R || M_type == "R"
rownames = data[:,target_col]
colnames = data[:,target_col]
else
throw(ArgumentError("type is incorrect, using :C," *
" :S, :Chat, :Shat, :F, :G, :A and :R"))
end
display_matrix(M, rownames, colnames, nrow=nrow, ncol=ncol, return_matrix=return_matrix)
end