質問編集履歴
3
エラーコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,3 +23,163 @@
|
|
23
23
|
Django 2.2.dev20180610131139
|
24
24
|
|
25
25
|
(必要なモジュールはインストールし,基本的に最新版です。)
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
エラーコードおよび動作している周辺のコードは以下の通りです。
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
/Users/Usename/webapp/app/views.py in sample
|
34
|
+
|
35
|
+
triplet_freqs = chain.make_triplet_freqs() ...
|
36
|
+
|
37
|
+
▼ Local vars
|
38
|
+
|
39
|
+
Variable Value
|
40
|
+
|
41
|
+
chain
|
42
|
+
|
43
|
+
<app.models.PrepareChain object at 0x10dcfc978>
|
44
|
+
|
45
|
+
request
|
46
|
+
|
47
|
+
<WSGIRequest: GET '/sample?your_name=%E6%96%87%E7%AB%A0%E3%82%92%E5%85%A5%E5%8A%9B%E3%81%97%E3%81%A6%E3%81%8F%E3%81%A0%E3%81%95%E3%81%84'>
|
48
|
+
|
49
|
+
text
|
50
|
+
|
51
|
+
(b'\xe6\x96\x87\xe7\xab\xa0\xe3\x82\x92\xe5\x85\xa5\xe5\x8a\x9b\xe3'
|
52
|
+
|
53
|
+
b'\x81\x97\xe3\x81\xa6\xe3\x81\x8f\xe3\x81\xa0\xe3\x81\x95\xe3\x81\x84')
|
54
|
+
|
55
|
+
------------------------------------
|
56
|
+
|
57
|
+
/Users/Usename/webapp/app/models.py in make_triplet_freqs
|
58
|
+
|
59
|
+
def make_triplet_freqs(self):
|
60
|
+
|
61
|
+
u"""
|
62
|
+
|
63
|
+
形態素解析から3つ組の出現回数まで
|
64
|
+
|
65
|
+
@return 3つ組とその出現回数の辞書 key: 3つ組(タプル) val: 出現回数
|
66
|
+
|
67
|
+
"""
|
68
|
+
|
69
|
+
# 長い文章をセンテンス毎に分割
|
70
|
+
|
71
|
+
sentences = self._divide(self.text) ...
|
72
|
+
|
73
|
+
# 3つ組の出現回数
|
74
|
+
|
75
|
+
triplet_freqs = defaultdict(int)
|
76
|
+
|
77
|
+
# センテンス毎に3つ組にする
|
78
|
+
|
79
|
+
for sentence in sentences:
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
▼ Local vars
|
84
|
+
|
85
|
+
Variable Value
|
86
|
+
|
87
|
+
self
|
88
|
+
|
89
|
+
<app.models.PrepareChain object at 0x10dcfc978>
|
90
|
+
|
91
|
+
------------------------------------
|
92
|
+
|
93
|
+
/Users/Usename/webapp/app/models.py in _divide
|
94
|
+
|
95
|
+
@param text 分割前の文章
|
96
|
+
|
97
|
+
@return 一文ずつの配列
|
98
|
+
|
99
|
+
"""
|
100
|
+
|
101
|
+
# 改行文字以外の分割文字(正規表現表記)
|
102
|
+
|
103
|
+
delimiter = u"。|.|."
|
104
|
+
|
105
|
+
# 全ての分割文字を改行文字に置換(splitしたときに「。」などの情報を無くさないため)
|
106
|
+
|
107
|
+
text = re.sub(u"({0})".format(delimiter), r"\1\n", text) ...
|
108
|
+
|
109
|
+
# 改行文字で分割
|
110
|
+
|
111
|
+
sentences = text.splitlines()
|
112
|
+
|
113
|
+
# 前後の空白文字を削除
|
114
|
+
|
115
|
+
sentences = [sentence.strip() for sentence in sentences]
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
▼ Local vars
|
120
|
+
|
121
|
+
Variable Value
|
122
|
+
|
123
|
+
delimiter
|
124
|
+
|
125
|
+
'。|.|\.'
|
126
|
+
|
127
|
+
self
|
128
|
+
|
129
|
+
<app.models.PrepareChain object at 0x10dcfc978>
|
130
|
+
|
131
|
+
text
|
132
|
+
|
133
|
+
(b'\xe6\x96\x87\xe7\xab\xa0\xe3\x82\x92\xe5\x85\xa5\xe5\x8a\x9b\xe3'
|
134
|
+
|
135
|
+
b'\x81\x97\xe3\x81\xa6\xe3\x81\x8f\xe3\x81\xa0\xe3\x81\x95\xe3\x81\x84')
|
136
|
+
|
137
|
+
--------------------------------------
|
138
|
+
|
139
|
+
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py in sub
|
140
|
+
|
141
|
+
def sub(pattern, repl, string, count=0, flags=0):
|
142
|
+
|
143
|
+
"""Return the string obtained by replacing the leftmost
|
144
|
+
|
145
|
+
non-overlapping occurrences of the pattern in string by the
|
146
|
+
|
147
|
+
replacement repl. repl can be either a string or a callable;
|
148
|
+
|
149
|
+
if a string, backslash escapes in it are processed. If it is
|
150
|
+
|
151
|
+
a callable, it's passed the match object and must return
|
152
|
+
|
153
|
+
a replacement string to be used."""
|
154
|
+
|
155
|
+
return _compile(pattern, flags).sub(repl, string, count)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
▼ Local vars
|
160
|
+
|
161
|
+
Variable Value
|
162
|
+
|
163
|
+
count
|
164
|
+
|
165
|
+
0
|
166
|
+
|
167
|
+
flags
|
168
|
+
|
169
|
+
0
|
170
|
+
|
171
|
+
pattern
|
172
|
+
|
173
|
+
'(。|.|\.)'
|
174
|
+
|
175
|
+
repl
|
176
|
+
|
177
|
+
'\1\n'
|
178
|
+
|
179
|
+
string
|
180
|
+
|
181
|
+
(b'\xe6\x96\x87\xe7\xab\xa0\xe3\x82\x92\xe5\x85\xa5\xe5\x8a\x9b\xe3'
|
182
|
+
|
183
|
+
b'\x81\x97\xe3\x81\xa6\xe3\x81\x8f\xe3\x81\xa0\xe3\x81\x95\xe3\x81\x84')
|
184
|
+
|
185
|
+
```
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[https://github.com/o-tomox/TextGenerator](https://github.com/o-tomox/TextGenerator)
|
2
2
|
|
3
|
-
のコードをDjangoアプリ内で動かそうとすと,以下のようなエラーがました。
|
3
|
+
のコードをPython3で使えるようにし,Djangoアプリ内で動かそうとすと,以下のようなエラーがました。
|
4
4
|
|
5
5
|
```
|
6
6
|
|
1
明確化
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,13 @@
|
|
2
2
|
|
3
3
|
のコードをDjangoアプリ内で動かそうとすと,以下のようなエラーがました。
|
4
4
|
|
5
|
+
```
|
6
|
+
|
5
7
|
cannot use a string pattern on a bytes-like object
|
8
|
+
|
9
|
+
```
|
10
|
+
|
11
|
+
|
6
12
|
|
7
13
|
|
8
14
|
|