-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwild_combination.php
183 lines (146 loc) · 7.08 KB
/
wild_combination.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
require 'vendor/autoload.php';
use Seld\JsonLint\JsonParser;
$char = function($postionOrRange)
{
return "/".$postionOrRange;
};
$index = function($postionOrRange)
{
return "[".$postionOrRange."]";
};
$indicator = function($ind)
{
return "^".$ind;
};
$subfield = function($subfieldTagOrRange)
{
return "$".$subfieldTagOrRange;
};
$comparison = function($comp)
{
return "\\".$comp;
};
function get_and_decode($path,$callback)
{
$json = json_decode(file_get_contents($path));
if(!$callback) return $json->{'tests'};
array_walk(
$json->{'tests'},
function(&$v, $k) use ($callback,&$json)
{
if(!is_string($v->{'data'}))
{
unset($json->{'tests'}->{$k});
return;
}
$v->{'data'} = $callback($v->{'data'});
}
);
return $json->{'tests'};
}
function make_json($json,$valid,$desc,$name)
{
$validtext = ($valid) ? 'valid' : 'invalid';
$obj['description'] = $desc;
$obj['schema'] = ['type'=>'string'];
$obj['tests'] = [];
foreach($json as $jt)
{
$_t['description'] = $validtext.' wild combination: '.$jt->{'description'};
$_t['data'] = '...'.$jt->{'data'};
$_t['valid'] = $valid;
$obj['tests'][] = $_t;
}
$parser = new JsonParser();
$enc = json_encode($obj,JSON_PRETTY_PRINT);
if(is_null($e = $parser->lint($enc)))
{
write_json($name,$validtext,$enc);
}
else
{
print $e->getDetails();
}
}
function write_json($name,$validtext,$content)
{
$handle = fopen($validtext.'/wildCombination_'.$name.'.json', "w+");
fwrite($handle,$content);
fclose($handle);
}
function combine($_t1,$_t2)
{
$combination = [];
array_walk(
$_t1,
function($t1,$k) use ($_t2,&$combination)
{
foreach($_t2 as $t2)
{
if(!is_string($t1->{'data'}) || !is_string($t2->{'data'})) continue;
$_t = new stdClass();
$_t->{'data'} = $t1->{'data'}.$t2->{'data'};
$_t->{'description'} = $t1->{'description'}.' && '.$t2->{'description'};
$_t->{'valid'} = $t2->{'valid'};
$combination[] = $_t;
}
}
);
return $combination;
}
$_json['validComparisonString'] = get_and_decode('valid/validComparisonString.json',$comparison);
$_json['validIndicators'] = get_and_decode('valid/validIndicators.json',$indicator);
$_json['validChar'] = get_and_decode('valid/validPositionOrRange.json',$char);
$_json['validIndex'] = get_and_decode('valid/validPositionOrRange.json',$index);
$_json['validSubfieldRange'] = get_and_decode('valid/validSubfieldRange.json',$subfield);
$_json['validSubfieldTag'] = get_and_decode('valid/validSubfieldTag.json',$subfield);
$_json['validSubSpec'] = get_and_decode('valid/validSubSpec.json',false);
$_json['invalidComparisonString'] = get_and_decode('invalid/invalidComparisonString.json',$comparison);
$_json['invalidIndicators'] = get_and_decode('invalid/invalidIndicators.json',$indicator);
$_json['invalidChar'] = get_and_decode('invalid/invalidPositionOrRange.json',$char);
$_json['invalidIndex'] = get_and_decode('invalid/invalidPositionOrRange.json',$index);
$_json['invalidSubfieldRange'] = get_and_decode('invalid/invalidSubfieldRange.json',$subfield);
$_json['invalidSubfieldTag'] = get_and_decode('invalid/invalidSubfieldTag.json',$subfield);
/**
* Valid combinations
*/
make_json($_json['validIndex'],true,"wild combination of valid field tag and index",'validIndex');
make_json($_json['validChar'],true,"wild combination of valid field tag and charspec",'validChar');
make_json($_json['validIndicators'],true,"wild combination of valid field tag and indicator",'validIndicators');
make_json($_json['validSubfieldTag'],true,"wild combination of valid field tag and subfield tag",'validSubfieldTag');
make_json($_json['validSubfieldRange'],true,"wild combination of valid field tag and subfield range",'validSubfieldRange');
make_json($_json['validSubSpec'],true,"wild combination of valid field tag and subspec",'validSubSpec');
$combineIndexIndicator = combine($_json['validIndex'],$_json['validIndicators']);
make_json($combineIndexIndicator,true,"wild combination of valid field tag, index and indicators",'validIndexIndicator');
$combineIndexChar = combine($_json['validIndex'],$_json['validChar']);
make_json($combineIndexChar,true,"wild combination of valid field tag, index and charspec",'validIndexChar');
$combineIndexSubSpec = combine($_json['validIndex'],$_json['validSubSpec']);
make_json($combineIndexSubSpec,true,"wild combination of valid field tag, index and subspec",'validIndexSubSpec');
$combineSubfieldTagSubSpec = combine($_json['validSubfieldTag'],$_json['validSubSpec']);
make_json($combineSubfieldTagSubSpec,true,"wild combination of valid field tag, subfield tag and subspec",'validSubfieldTagSubSpec');
$combineSubfieldTagRange = combine($_json['validSubfieldTag'],$_json['validSubfieldRange']);
make_json($combineSubfieldTagRange,true,"wild combination of valid field tag, subfield tag and subfield range",'validSubfieldTagRange');
$combineSubfieldRangeSubSpec = combine($_json['validSubfieldRange'],$_json['validSubSpec']);
make_json($combineSubfieldRangeSubSpec,true,"wild combination of valid field tag, subfield range and subspec",'validSubfieldRangeSubSpec');
$combineSubfieldTagTag = combine($_json['validSubfieldTag'],$_json['validSubfieldTag']);
make_json($combineSubfieldTagTag,true,"wild combination of valid field tag and subfield tags",'validSubfieldTagTag');
$combineSubfieldRangeRange = combine($_json['validSubfieldRange'],$_json['validSubfieldRange']);
make_json($combineSubfieldRangeRange,true,"wild combination of valid field tag and subfield ranges",'validSubfieldRangeRange');
$combineSubSpecSubSpec = combine($_json['validSubSpec'],$_json['validSubSpec']);
make_json($combineSubSpecSubSpec,true,"wild combination of valid field tag and subspecs",'validSubSpecSubSpec');
/*
$combineSubSpecTag = combine($_json['validSubSpec'],$_json['validSubfieldTag']);
$combineSubSpecTagSubSpec = combine($combineSubSpecTag,$_json['validSubSpec']);
make_json($combineSubSpecTagSubSpec,true,"wild combination of valid field tag with subspec and subfield tag with subspec",'validSubSpecSubfieldTagSubSpec');
+/
/*
* Invalid combinations
*/
make_json($_json['invalidIndex'],false,"wild combination of valid field tag and invalid index",'invalidIndex');
make_json($_json['invalidChar'],false,"wild combination of valid field tag and invalid charspec",'invalidChar');
make_json($_json['invalidIndicators'],false,"wild combination of valid field tag and invalid indicator",'invalidIndicators');
make_json($_json['invalidSubfieldTag'],false,"wild combination of valid field tag and invalid subfield tag",'invalidSubfieldTag');
make_json($_json['invalidSubfieldRange'],false,"wild combination of valid field tag and invalid subfield range",'invalidSubfieldRange');
$invalidCombineCharIndicator = combine($_json['validChar'],$_json['validIndicators']);
make_json($invalidCombineCharIndicator,false,"wild combination of valid field tag and charspec",'invalidCharIndicator');