Skip to content

Commit 95e80e7

Browse files
committed
Add pS option to display matrix
1 parent ac9b6d6 commit 95e80e7

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/display.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ function display_matrix(M, rownames, colnames; nrow=6, ncol=6, return_matrix=fal
2121
end
2222

2323
"""
24-
display_matrix(data, target_col, cue_obj, M, M_type)
24+
display_matrix(data, target_col, cue_pS_obj, M, M_type)
2525
2626
Display matrix with rownames and colnames.
2727
2828
# Obligatory Arguments
2929
- `data::DataFrame`: the dataset
3030
- `target_col::Union{String, Symbol}`: the target column name
31-
- `cue_obj::Cue_Matrix_Struct`: the cue matrix structure
31+
- `cue_pS_obj::Union{Cue_Matrix_Struct,PS_Matrix_Struct}`: the cue matrix or pS matrix structure
3232
- `M::Union{SparseMatrixCSC, Matrix}`: the matrix
33-
- `M_type::Union{String, Symbol}`: the type of the matrix, currently support :C, :S, :F, :G, :Chat, :Shat, :A and :R
33+
- `M_type::Union{String, Symbol}`: the type of the matrix, currently support :C, :S, :F, :G, :Chat, :Shat, :A, :R and :pS
3434
3535
# Optional Arguments
3636
- `nrow::Int64 = 6`: the number of rows to display
@@ -47,12 +47,13 @@ JudiLing.display_matrix(latin, :Word, cue_obj, F, :F)
4747
JudiLing.display_matrix(latin, :Word, cue_obj, Shat, :Shat)
4848
JudiLing.display_matrix(latin, :Word, cue_obj, A, :A)
4949
JudiLing.display_matrix(latin, :Word, cue_obj, R, :R)
50+
JudiLing.display_matrix(latin, :Word, pS_obj, pS_obj.pS, :pS)
5051
```
5152
"""
5253
function display_matrix(
5354
data,
5455
target_col,
55-
cue_obj,
56+
cue_pS_obj,
5657
M,
5758
M_type;
5859
nrow = 6,
@@ -62,31 +63,34 @@ function display_matrix(
6263

6364
if M_type == :C || M_type == "C"
6465
rownames = data[:,target_col]
65-
colnames = [cue_obj.i2f[i] for i in 1:size(M,2)]
66+
colnames = [cue_pS_obj.i2f[i] for i in 1:size(M,2)]
67+
elseif M_type == :pS || M_type == "pS"
68+
rownames = data[:,target_col]
69+
colnames = [cue_pS_obj.i2f[i] for i in 1:size(M,2)]
6670
elseif M_type == :Chat || M_type == "Chat"
6771
rownames = data[:,target_col]
68-
colnames = [cue_obj.i2f[i] for i in 1:size(M,2)]
72+
colnames = [cue_pS_obj.i2f[i] for i in 1:size(M,2)]
6973
elseif M_type == :S || M_type == "S"
7074
rownames = data[:,target_col]
7175
colnames = ["S$i" for i in 1:size(M,2)]
7276
elseif M_type == :Shat || M_type == "Shat"
7377
rownames = data[:,target_col]
7478
colnames = ["S$i" for i in 1:size(M,2)]
7579
elseif M_type == :F || M_type == "F"
76-
rownames = [cue_obj.i2f[i] for i in 1:size(M,1)]
80+
rownames = [cue_pS_obj.i2f[i] for i in 1:size(M,1)]
7781
colnames = ["S$i" for i in 1:size(M,2)]
7882
elseif M_type == :G || M_type == "G"
7983
rownames = ["S$i" for i in 1:size(M,1)]
80-
colnames = [cue_obj.i2f[i] for i in 1:size(M,2)]
84+
colnames = [cue_pS_obj.i2f[i] for i in 1:size(M,2)]
8185
elseif M_type == :A || M_type == "A"
82-
rownames = [cue_obj.i2f[i] for i in 1:size(M,1)]
83-
colnames = [cue_obj.i2f[i] for i in 1:size(M,2)]
86+
rownames = [cue_pS_obj.i2f[i] for i in 1:size(M,1)]
87+
colnames = [cue_pS_obj.i2f[i] for i in 1:size(M,2)]
8488
elseif M_type == :R || M_type == "R"
8589
rownames = data[:,target_col]
8690
colnames = data[:,target_col]
8791
else
8892
throw(ArgumentError("type is incorrect, using :C," *
89-
" :S, :Chat, :Shat, :F, :G, :A and :R"))
93+
" :S, :Chat, :Shat, :F, :G, :A, :R and :pS"))
9094
end
9195

9296
display_matrix(M, rownames, colnames, nrow=nrow, ncol=ncol, return_matrix=return_matrix)

test/display_tests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ using DataFrames
4141

4242
acc, R = JudiLing.eval_SC(Chat, cue_obj.C, R = true)
4343
JudiLing.display_matrix(latin, :Word, cue_obj, R, :R)
44-
end
44+
45+
pS_obj = JudiLing.make_pS_matrix(latin, features_col="Word")
46+
JudiLing.display_matrix(latin, :Word, pS_obj, pS_obj.pS, :pS)
47+
end

0 commit comments

Comments
 (0)