質問編集履歴

2

追記

2021/09/07 00:56

投稿

ShinyaYAMAGUCHI
ShinyaYAMAGUCHI

スコア7

test CHANGED
File without changes
test CHANGED
@@ -143,3 +143,11 @@
143
143
  print("system covers"+str(100*counter2/counter1)+"%")
144
144
 
145
145
  ```
146
+
147
+ 追記2
148
+
149
+ 実はパソコンを初期化してから試したのですが、違うエラーになりました
150
+
151
+ ![イメージ説明](aa93c78c6a45c24f645be78568f0c737.png)
152
+
153
+ ![イメージ説明](e22c781503e913b17e129a9a1c6fa8e3.png)

1

追記

2021/09/07 00:55

投稿

ShinyaYAMAGUCHI
ShinyaYAMAGUCHI

スコア7

test CHANGED
File without changes
test CHANGED
@@ -7,3 +7,139 @@
7
7
  前は使えていたのですが、vscodeを使おうとあれこれいじっていたら使えなくなってしまいました
8
8
 
9
9
  解決法を教えてください、、
10
+
11
+
12
+
13
+ 追記
14
+
15
+ 前はpythonコマンドだけで動いていたのですが、今はpython3コマンドでないと動きません、、
16
+
17
+ python3コマンドでも長いコードだと下の謎のエラーが発生します
18
+
19
+ shinya@shinyanoMacBook-Air Colab Notebooks % python3 probability.py
20
+
21
+ Traceback (most recent call last):
22
+
23
+ File "/Volumes/GoogleDrive/マイドライブ/Colab Notebooks/probability.py", line 1, in <module>
24
+
25
+ from nltk.stem import WordNetLemmatizer
26
+
27
+ File "/opt/homebrew/lib/python3.9/site-packages/nltk/__init__.py", line 133, in <module>
28
+
29
+ from nltk.text import *
30
+
31
+ File "/opt/homebrew/lib/python3.9/site-packages/nltk/text.py", line 30, in <module>
32
+
33
+ from nltk.tokenize import sent_tokenize
34
+
35
+ File "/opt/homebrew/lib/python3.9/site-packages/nltk/tokenize/__init__.py", line 66, in <module>
36
+
37
+ from nltk.tokenize.casual import TweetTokenizer, casual_tokenize
38
+
39
+ File "/opt/homebrew/lib/python3.9/site-packages/nltk/tokenize/casual.py", line 38, in <module>
40
+
41
+ import regex # https://github.com/nltk/nltk/issues/2409
42
+
43
+ File "/opt/homebrew/lib/python3.9/site-packages/regex/__init__.py", line 1, in <module>
44
+
45
+ from .regex import *
46
+
47
+ File "/opt/homebrew/lib/python3.9/site-packages/regex/regex.py", line 419, in <module>
48
+
49
+ import regex._regex_core as _regex_core
50
+
51
+ File "/opt/homebrew/lib/python3.9/site-packages/regex/_regex_core.py", line 21, in <module>
52
+
53
+ import regex._regex as _regex
54
+
55
+ ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found. Did find:
56
+
57
+ /opt/homebrew/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture
58
+
59
+ /opt/homebrew/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture
60
+
61
+ ```python3
62
+
63
+ from nltk.stem import WordNetLemmatizer
64
+
65
+ lemmatizer=WordNetLemmatizer()
66
+
67
+ qlist=["単語2047個"]
68
+
69
+ ty=input("which type?")
70
+
71
+ import os,pytesseract,enchant,nltk
72
+
73
+ from PIL import Image
74
+
75
+ counter1=0
76
+
77
+ counter2=0
78
+
79
+ os.chdir(f"/Volumes/GoogleDrive/マイドライブ/Colab Notebooks/{ty}")
80
+
81
+ for im in os.listdir(".")[1:]:
82
+
83
+ img=Image.open(im)
84
+
85
+ text=pytesseract.image_to_string(img,lang="eng")
86
+
87
+ text=text.replace("\n","")
88
+
89
+ text=nltk.word_tokenize(text)
90
+
91
+ text=nltk.pos_tag(text)
92
+
93
+ for word,type in list(set(text)):
94
+
95
+ if type in ["JJ","JJR","JJS"]:
96
+
97
+ counter1+=1
98
+
99
+ if lemmatizer.lemmatize(word,pos="a") in qlist:
100
+
101
+ counter2+=1
102
+
103
+ else:
104
+
105
+ print(word+" leaked")
106
+
107
+ elif type in ["NN","NNS","NNP","NNPS"]:
108
+
109
+ counter1+=1
110
+
111
+ if lemmatizer.lemmatize(word,pos="n"):
112
+
113
+ counter2+=1
114
+
115
+ else:
116
+
117
+ print(word+" leaked")
118
+
119
+ elif type in ["RB","RBS","RBR"]:
120
+
121
+ counter1+=1
122
+
123
+ if lemmatizer.lemmatize(word,pos="r") in qlist:
124
+
125
+ counter2+=1
126
+
127
+ else:
128
+
129
+ print(word+" leaked")
130
+
131
+ elif type in ["VB","VBD","VBG","VBN","VBP","VBZ"]:
132
+
133
+ counter1+=1
134
+
135
+ if lemmatizer.lemmatize(word,pos="v") in qlist:
136
+
137
+ counter2+=1
138
+
139
+ else:
140
+
141
+ print(word+" leaked")
142
+
143
+ print("system covers"+str(100*counter2/counter1)+"%")
144
+
145
+ ```