質問編集履歴

3

エラー画面の追加

2018/11/19 05:38

投稿

hiro329
hiro329

スコア19

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 例題でmakefileで実行してファイルを作成するものがあります。
1
+ ![イメージ説明](06e340c11f72b3d4f9aa2fd1ee10ab44.jpeg)例題でmakefileで実行してファイルを作成するものがあります。
2
2
 
3
3
  しかし、makefileの実行方法がわかりません。
4
4
 

2

ソースの追記

2018/11/19 05:38

投稿

hiro329
hiro329

スコア19

test CHANGED
File without changes
test CHANGED
@@ -22,7 +22,11 @@
22
22
 
23
23
 
24
24
 
25
- # download page: https://nknet.ninjal.ac.jp/nuc/templates/nuc.html
25
+ makefile
26
+
27
+
28
+
29
+ ```ここに言語を入力
26
30
 
27
31
  CORPUS_URL = http://mmsrv.ninjal.ac.jp/nucc/nucc.zip
28
32
 
@@ -82,6 +86,8 @@
82
86
 
83
87
  ```
84
88
 
89
+ ```
90
+
85
91
  -*- coding: utf-8 -*-
86
92
 
87
93
 

1

ソースの追加

2018/11/19 02:39

投稿

hiro329
hiro329

スコア19

test CHANGED
File without changes
test CHANGED
@@ -79,3 +79,141 @@
79
79
  $(UNZIP_DIR): nucc.zip
80
80
 
81
81
  $(UNZIP) -x $(ZIP_FILE)
82
+
83
+ ```
84
+
85
+ -*- coding: utf-8 -*-
86
+
87
+
88
+
89
+ import os, sys
90
+
91
+
92
+
93
+ try:
94
+
95
+ unicode
96
+
97
+ import codecs
98
+
99
+ sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
100
+
101
+ def copen(fname, mode):
102
+
103
+ return codecs.open(fname, mode, "utf-8")
104
+
105
+ except:
106
+
107
+ def copen(fname, mode):
108
+
109
+ return open(fname, mode, encoding='utf-8')
110
+
111
+
112
+
113
+ nuc_dir = "nucc"
114
+
115
+
116
+
117
+ def make_sequence_from_file(fname):
118
+
119
+ fname = os.path.join(nuc_dir, fname)
120
+
121
+ if not os.path.exists(fname):
122
+
123
+ raise Exception("no %s file." % fname)
124
+
125
+ last_line = None
126
+
127
+ sequence = []
128
+
129
+ with copen(fname, "r") as f:
130
+
131
+ try:
132
+
133
+ for line in f:
134
+
135
+ uline = line
136
+
137
+ if uline[0] == u'@':
138
+
139
+ continue
140
+
141
+ if uline[0] == u'F' or uline[0] == u'M':
142
+
143
+ if last_line is None:
144
+
145
+ last_line = uline
146
+
147
+ continue
148
+
149
+ else:
150
+
151
+ seq_input = last_line[5:-1]
152
+
153
+ seq_output = uline[5:-1]
154
+
155
+ last_line = uline
156
+
157
+ sequence.append((seq_input, seq_output))
158
+
159
+ else:
160
+
161
+ last_line = None
162
+
163
+ except:
164
+
165
+ sys.stderr.write("skip %s (not euc-jp)\n" % fname)
166
+
167
+ sys.stderr.flush()
168
+
169
+ return []
170
+
171
+ return sequence
172
+
173
+
174
+
175
+ def main():
176
+
177
+ if not os.path.exists(nuc_dir):
178
+
179
+ raise Exception("no extracted files.")
180
+
181
+
182
+
183
+ files = os.listdir(nuc_dir)
184
+
185
+ uniq_seq = {}
186
+
187
+ for f in files:
188
+
189
+ if not ".txt" in f:
190
+
191
+ continue
192
+
193
+ seq = make_sequence_from_file(f)
194
+
195
+ for inp, out in seq:
196
+
197
+ uniq_seq[inp] = out
198
+
199
+ for k, v in uniq_seq.items():
200
+
201
+ print("input: %s\noutput: %s" % (k, v))
202
+
203
+ return
204
+
205
+
206
+
207
+
208
+
209
+ if __name__ == "__main__":
210
+
211
+ main()
212
+
213
+ sys.exit(0)
214
+
215
+ #
216
+
217
+ コード
218
+
219
+ ```