forked from beatestermann/performing-arts
/
create_quick_statements.php
154 lines (142 loc) · 6.01 KB
/
create_quick_statements.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
<?php
$csvIn = $argv[1];
$res = [];
// Repertoire Schauspielhaus Zürich 1938-1968
$source = "Q39907533";
$existing = ["Der Hauptmann von Köpenick10/18/1947","Eine kleine Stadt03/09/1939",
"L'école des femmes (Die Schule der Frauen)02/11/1941","Frau Warrens Gewerbe09/03/1938"];
$csv = array_map('str_getcsv', file($csvIn));
$csv_head = $csv[0];
unset($csv[0]);
foreach($csv as $row){
if (sizeof($row) == 47) {
$row = array_combine($csv_head, $row);
$id = $row["Stück"].$row["Datum"];
if (!in_array($id,$existing)) {
if (!array_key_exists($id,$res)) {
if ($row["Typ"] == 'Q40249767') { // if Gastspiel
$res[$id][] = "CREATE\nLAST\tP31\tQ43100730\tS248\tQ39907533\n";
} else {
$res[$id][] = "CREATE\nLAST\tP31\tQ7777570\tS248\tQ39907533\n";
}
}
if ($row["Spielzeit"]) {
$res = addQuick($res,$row,[[["P2348",$row["Spielzeit"]]]],$source);
}
if ($row["Datum"]) {
$res = addQuick($res,$row,[[["P1191",$row["Datum"]]]],$source);
}
if ($row["Stück"]) {
$res = addQuick($res,$row,[[["Lde",$row["Stück"]]]],"");
$res = addQuick($res,$row,[[["P1705",$row["Stück"]]]],$source);
if ($row["Kommentar"]) {
$res = addQuick($res,$row,[[["Dde","Theaterproduktion des Schauspielhauses Zürich in der Spielzeit " . $row["SpielzeitJahre"] . ". " . $row["Kommentar"]]]],"");
} else {
$res = addQuick($res,$row,[[["Dde","Theaterproduktion des Schauspielhauses Zürich in der Spielzeit " . $row["SpielzeitJahre"]]]],"");
}
$res = addQuick($res,$row,[[["Den","theatrical production of Schauspielhaus Zurich during the season " . $row["SpielzeitJahre"]]]],"");
}
if ($row["Vorlage"]) {
$res = addQuick($res,$row,[[["P144",$row["Vorlage"]]]],$source);
}
if ($row["SpracheQ"]) {
$res = addQuick($res,$row,[[["P407",$row["SpracheQ"]]]],"");
}
if ($row["ProduzentQ"]) {
$res = addQuick($res,$row,[[["P272",$row["ProduzentQ"]]]],$source);
}
if ($row["Vorlage"]) {
$res = addQuick($res,$row,[[["P144",$row["Vorlage"]]]],$source);
}
/*if ($row["Autor1"] || $row["Autor2"] || $row["Autor3"]) {
$res = addQuick($res,$row,"P",[$row["Autor1"],$row["Autor2"],$row["Autor3"]]);
}*/
if ($row["Regie1"] && $row["Regie1String"] || $row["Regie2"] && $row["Regie2String"]) {
$res = addQuick($res,$row,[[["P57",$row["Regie1"]],["P1810",$row["Regie1String"]]],[["P57",$row["Regie2"]],["P1810",$row["Regie2String"]]]],$source);
}
if ($row["Musik1"] && $row["Musik1String"] || $row["Musik2"] && $row["Musik2String"] || $row["Musik3"] && $row["Musik3String"] || $row["Musik4"] && $row["Musik4String"]) {
$res = addQuick($res,$row,[[["P86",$row["Musik1"]],["P1810",$row["Musik1String"]]],[["P86",$row["Musik2"]],["P1810",$row["Musik2String"]]]
,[["P86",$row["Musik3"]],["P1810",$row["Musik3String"]]],[["P86",$row["Musik4"]],["P1810",$row["Musik4String"]]]],$source);
$res = addQuick($res,$row,[[["P136","Q39894018"]]],"");
} else {
$res = addQuick($res,$row,[[["P136","Q39892385"]]],"");
}
if ($row["Bühnenbild1"] && $row["Bühnenbild1String"] || $row["Bühnenbild2"] && $row["Bühnenbild2String"]) {
$res = addQuick($res,$row,[[["P4608",$row["Bühnenbild1"]],["P1810",$row["Bühnenbild1String"]]],[["P4608",$row["Bühnenbild2"]],["P1810",$row["Bühnenbild2String"]]]],$source);
}
if ($row["Kostüme1"] && $row["Kostüme1String"]|| $row["Kostüme2"]&& $row["Kostüme2String"]) {
$res = addQuick($res,$row,[[["P2515",$row["Kostüme1"]],["P1810",$row["Kostüme1String"]]],[["P2515",$row["Kostüme2"]],["P1810",$row["Kostüme2String"]]]],$source);
}
if ($row["Choreographie"] && $row["ChreographieString"]) {
$res = addQuick($res,$row,[[["P1809",$row["Choreographie"]],["P1810",$row["ChreographieString"]]]],$source);
}
if ($row["Ortsvermerk"]) {
if ($row["Typ"] == 'Q40249767') {
$prop = "P4647";
} else {
$prop = "P276";
}
if ($row["OrtQualifier1"] && $row["OrtQualifier2"]) {
$res = addQuick($res,$row,[[[$prop,$row["Ortsvermerk"]],[$row["OrtQualifier1"],$row["OrtQualifier2"]]]],$source);
} else {
$res = addQuick($res,$row,[[[$prop,$row["Ortsvermerk"]]]],$source);
}
}
if ($row["Typ"]) {
$res = addQuick($res,$row,[[["P4634",$row["Typ"]]]],$source);
}
if ($row["Person"] && $row["Rolle"] && $row["PersonString"]) {
$res = addQuick($res,$row,[[["P161",$row["Person"]],["P4633",$row["Rolle"]],["P1810",$row["PersonString"]]]],$source);
}
}
}
}
foreach ($res as $k => $prods) {
$res[$k] = implode($prods,'');
}
foreach ($res as $str) {
echo $str . "\n";
}
function addIfNotExists($resAtKey,$propWithItem) {
if (!in_array($propWithItem,$resAtKey)) {
$resAtKey[] = $propWithItem;
}
return $resAtKey;
}
function addQuotes($item) {
if (!preg_match("/(^Q[0-9]+)|(^P[0-9]+)|(^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$)|(^[0-9]{4}-[0-9]{2}-[0-9]{2})$/",$item)) {
$item = "\"" . $item . "\"";
}
if (preg_match("/(^[0-9]{4}-[0-9]{2}-[0-9]{2}$)/",$item)) {
$item = "+" . $item . "T00:00:00Z/11";
$item = "+" . substr($item,0,4) . "-" . substr($item,7,2) . "-" . substr($item,5,2) . "T00:00:00Z/11";
}
if (preg_match("/(^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$)/",$item)) {
$item = "+" . substr($item,6,4) . "-" . substr($item,0,2) . "-" . substr($item,3,2) . "T00:00:00Z/11";
}
return $item;
}
function addQuick($res,$row,$properties,$source) {
if ($source) {
$source = "\tS248\t" . $source;
}
foreach ($properties as $props) {
$propStr = "";
foreach ($props as list($prop,$item)) {
if ($item) {
$item = addQuotes($item);
if ($prop == "P1705") {
$propStr = $propStr . "\t" . $prop . "\tde:" . $item;
} else {
$propStr = $propStr . "\t" . $prop . "\t" . $item;
}
}
}
if ($propStr) {
$res[$row["Stück"].$row["Datum"]] =
addIfNotExists($res[$row["Stück"].$row["Datum"]],"LAST" . $propStr . $source . "\n");
}
}
return $res;
}
?>