質問編集履歴

1

内容を変更

2018/10/17 09:46

投稿

syen2501
syen2501

スコア38

test CHANGED
File without changes
test CHANGED
@@ -1,16 +1,48 @@
1
1
  vscodeの拡張機能として、
2
2
 
3
- 値域を表現する語の係り受け先の語をハイライトするというプログラムを作成していて、
3
+ 値域を表現する語の係り受け先の語をハイライトするというプログラムを作成しています。
4
-
4
+
5
- execをいて特定の語の検出を行っているめ、値域表現する語係り受け関係のない
5
+ プログラムとしては、あらかじめ意しjsonファイル読み込みそ情報を元
6
-
6
+
7
- 部分もハイライトしてしまます
7
+ 特定の語をハイライトするようにしてい
8
+
9
+
10
+
8
-
11
+ <parent_dict.json>
12
+
13
+ 強時間:[現在=>設置している,
14
+
15
+     (現在=>設置している
16
+
17
+ ]
18
+
9
- これを値域を表現する語が記載されている文章内だけに反映させるようなことは
19
+ というように左辺に値域を表現する語、右辺に係り受け先の語を保存している
10
-
20
+
21
+
22
+
23
+
24
+
11
- 出来なょうか?
25
+ 困ってることと
26
+
12
-
27
+ 例えば、
28
+
13
-
29
+ ・ある場所に現在設置しているものを使用する。
30
+
31
+ ・(現在設置しているものの仕様)
32
+
33
+ のような2つの文章があった時に、本当であれば
34
+
35
+ 1行目の「現在」と「設置している」、2行目の「(現在」と「設置している」を
36
+
37
+ ハイライトで表示して欲しいのですが、なぜか、
38
+
39
+ 1行目の「現在」と2行目の「設置している」がハイライトで表示されないというバグが発生しています。
40
+
41
+
42
+
43
+ indexOfで探しているからなのか、それとも取得した情報が何かしらで更新されてしまっているのか
44
+
45
+ 原因が分からなくて困っています。
14
46
 
15
47
  初心者なので、助言を頂けると幸いです。よろしくお願いします。
16
48
 
@@ -66,64 +98,46 @@
66
98
 
67
99
 
68
100
 
69
- //時間
101
+ //時間
70
-
71
- let timeWord = timeWordList[0].split('=>');
102
+
72
-
73
- let rangeWordreg = timeWord[0];
74
-
75
- let relationWordreg = timeWord[1];
76
-
77
- for(let i = 1; i < timeWordList.length; i++) {
103
+ for (let i = 0; i < strengthTimeWordList.length; i++){
78
-
104
+
79
- const word = timeWordList[i].split('=>');
105
+ let word = strengthTimeWordList[i].split('=>');
106
+
80
-
107
+ if(text.indexOf(word[0]) !== -1 && text.indexOf(word[1],text.indexOf(word[0])) !== -1){
108
+
109
+
110
+
111
+ //値域、状態値を表現する語を抽出
112
+
81
- rangeWordreg = rangeWordreg + "|" + word[0];
113
+ const startPos = activeEditor.document.positionAt(text.indexOf(word[0]));
114
+
82
-
115
+ const endPos = activeEditor.document.positionAt(text.indexOf(word[0]) + word[0].length);
116
+
117
+ const strengthtime_decoration = { range: new vscode.Range(startPos, endPos)};
118
+
119
+ strengthTimeWords.push(strengthtime_decoration);
120
+
121
+
122
+
123
+ // 値域、状態値に係る語を抽出
124
+
83
- relationWordreg = relationWordreg + "|" + word[1];
125
+ const relation_startPos = activeEditor.document.positionAt(text.indexOf(word[1]));
126
+
127
+ const relation_endPos = activeEditor.document.positionAt(text.indexOf(word[1]) + word[1].length);
128
+
129
+ const strengthtime_related_decoration = {range:new vscode.Range(relation_startPos,relation_endPos)};
130
+
131
+ dependencyRelationWords.push(strengthtime_related_decoration);
132
+
133
+
134
+
135
+ strengthtimeCount++;
136
+
137
+ }
84
138
 
85
139
  }
86
140
 
87
- const rangeWord = eval("/" + rangeWordreg + "/g;");
88
-
89
- const relationWord = eval("/" + relationWordreg + "/g;");
90
-
91
-
92
-
93
- //値域、状態値を表現する語を抽出
94
-
95
- let time_result;
96
-
97
- let time_relation_result;
98
-
99
- while(time_result = rangeWord.exec(text)){
100
-
101
- const startPos = activeEditor.document.positionAt(time_result.index);
102
-
103
- const endPos = activeEditor.document.positionAt(time_result.index + time_result[0].length);
104
-
105
- const time_decoration = { range: new vscode.Range(startPos, endPos)};
106
-
107
- timeWords.push(time_decoration);
108
-
109
- timeCount++;
110
-
111
- }
112
-
113
- //値域、状態値に係る語を抽出
114
-
115
- while(time_relation_result = relationWord.exec(text)){
116
-
117
- const relation_startPos = activeEditor.document.positionAt(time_relation_result.index);
118
-
119
- const relation_endPos = activeEditor.document.positionAt(time_relation_result.index + time_relation_result[0].length);
120
-
121
- const time_related_decoration = {range:new vscode.Range(relation_startPos,relation_endPos)};
122
-
123
- dependencyRelationWords.push(time_related_decoration);
124
-
125
- }
126
-
127
141
 
128
142
 
129
143
 
@@ -134,7 +148,7 @@
134
148
 
135
149
 
136
150
 
137
- console.log("時間:" + timeCount);
151
+ console.log("時間:" + strengthtimeCount);
138
152
 
139
153
  }
140
154
 
@@ -144,9 +158,9 @@
144
158
 
145
159
 
146
160
 
147
- //時間に色付け
161
+ //時間に色付け
148
-
162
+
149
- const timeMarkerDecoration = vscode.window.createTextEditorDecorationType({
163
+ const strengthTimeMarkerDecoration = vscode.window.createTextEditorDecorationType({
150
164
 
151
165
  'borderWidth': '1px',
152
166
 
@@ -154,11 +168,11 @@
154
168
 
155
169
  'borderStyle': 'solid',
156
170
 
157
- // 'backgroundColor': 'rgba(255, 0, 0, 0.3)',
171
+ // 'backgroundColor': 'rgba(0, 0, 255, 0.3)',
158
172
 
159
173
  'backgroundColor': 'rgba(128, 128, 0, 0.3)',
160
174
 
161
- // 'color':'red'
175
+ // 'color':'blue'
162
176
 
163
177
  'color':'orange'
164
178
 
@@ -187,21 +201,3 @@
187
201
 
188
202
 
189
203
  ```
190
-
191
- <parent_dict.json>
192
-
193
- 日単位で=>こと。
194
-
195
- ※左辺が値域を表現する語、右辺がそれに係る語
196
-
197
-
198
-
199
- <出力結果>
200
-
201
- 今日の献立を見ることができる**こと。**
202
-
203
- **日単位**でスケジュールの編集ができる**こと。**
204
-
205
- ※太字がハイライトされる部分(現状)
206
-
207
- 理想は「日単位で~こと。」の部分だけハイライトすること