-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogicalRuleConvert.m
More file actions
48 lines (41 loc) · 1.69 KB
/
Copy pathlogicalRuleConvert.m
File metadata and controls
48 lines (41 loc) · 1.69 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
clear;
% WARNING: Does not work when there are more than 9 layers in the network
opts = detectImportOptions("rawRules1.csv");
[opts.VariableTypes{1:size(opts.VariableTypes, 2)}] = deal('string');
T = readtable("rawRules1.csv",opts);
fileID = fopen('convertedRules1.txt','w');
row = 2;
T = erase(regexprep(T{:,:}, '^0$', 'z'), "'");
newT = T;
while(row <= size(T, 1))
name = cell2mat(T(row,1))
layer = str2num(name(1));
subset_T = T(strcmp(T(:,1), T(row, 1)), :);
subset_T(:, 1) = repmat("h"+name+" :- ",size(subset_T,1),1);
col = 2;
if(layer < 2)
ascii = double('a');
while(col <= size(T, 2))
subset_T(:,col) = strrep(subset_T(:,col),"-1","not "+string(char(ascii))+", ");
subset_T(:,col) = strrep(subset_T(:,col),"1",string(char(ascii))+", ");
col = col + 1;
ascii = ascii + 1;
end
else
while(col <= size(T, 2))
%subset_T(:,col) = strrep(subset_T(:,col),"-1","not h"+string(layer-1)+"_"+string(col-1)+", ");
%ubset_T(:,col) = strrep(subset_T(:,col),"1","h"+string(layer-1)+"_"+string(col-1)+", ");
subset_T(:,col) = regexprep(subset_T(:,col),"^-1$","not h"+string(layer-1)+"_"+string(col-1)+", ");
subset_T(:,col) = regexprep(subset_T(:,col),"^1$","h"+string(layer-1)+"_"+string(col-1)+", ");
col = col+1;
end
end
row = row + size(subset_T, 1);
ruleArr = join(erase(subset_T(:, :), 'z'), '', 2);
for i = 1:size(ruleArr, 1)
ruleArr(i) = replaceBetween(ruleArr(i),strlength(ruleArr(i))-1, strlength(ruleArr(i)), '.\n');
end
finalString = join(ruleArr, '', 1);
fprintf(fileID,finalString);
end
fclose(fileID);