CHNOSProjectのすべてのプロジェクトのソースのルート
修订版 | b9a126d23ac72b9f6cf365b584ba1bce3031997b (tree) |
---|---|
时间 | 2013-05-20 02:17:36 |
作者 | hikarupsp <hikarupsp@user...> |
Commiter | hikarupsp |
データ保存関連を整備。
@@ -7,6 +7,9 @@ | ||
7 | 7 | objects = { |
8 | 8 | |
9 | 9 | /* Begin PBXBuildFile section */ |
10 | + 170FE1E717493EFA0049FBBB /* memory.c in Sources */ = {isa = PBXBuildFile; fileRef = 170FE1E617493EFA0049FBBB /* memory.c */; }; | |
11 | + 170FE1EA17493FB10049FBBB /* wlfilter.c in Sources */ = {isa = PBXBuildFile; fileRef = 170FE1E917493FB10049FBBB /* wlfilter.c */; }; | |
12 | + 171C8B33174912D600E95F41 /* memory.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 171C8B3117490BAE00E95F41 /* memory.txt */; }; | |
10 | 13 | 17289436174406B600071834 /* AITestData_en.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 172894331744069100071834 /* AITestData_en.txt */; }; |
11 | 14 | 17289437174406BB00071834 /* AITestData_ja.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 172894351744069800071834 /* AITestData_ja.txt */; }; |
12 | 15 | 173BB42616C6600100126A00 /* config.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 173BB42316C65FBB00126A00 /* config.txt */; }; |
@@ -33,6 +36,7 @@ | ||
33 | 36 | dstPath = ""; |
34 | 37 | dstSubfolderSpec = 16; |
35 | 38 | files = ( |
39 | + 171C8B33174912D600E95F41 /* memory.txt in CopyFiles */, | |
36 | 40 | 17289437174406BB00071834 /* AITestData_ja.txt in CopyFiles */, |
37 | 41 | 17289436174406B600071834 /* AITestData_en.txt in CopyFiles */, |
38 | 42 | 173BB42816C6618500126A00 /* words.txt in CopyFiles */, |
@@ -53,6 +57,9 @@ | ||
53 | 57 | /* End PBXCopyFilesBuildPhase section */ |
54 | 58 | |
55 | 59 | /* Begin PBXFileReference section */ |
60 | + 170FE1E617493EFA0049FBBB /* memory.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = memory.c; sourceTree = "<group>"; }; | |
61 | + 170FE1E917493FB10049FBBB /* wlfilter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = wlfilter.c; sourceTree = "<group>"; }; | |
62 | + 171C8B3117490BAE00E95F41 /* memory.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = memory.txt; path = ../memory.txt; sourceTree = "<group>"; }; | |
56 | 63 | 172894331744069100071834 /* AITestData_en.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = AITestData_en.txt; sourceTree = "<group>"; }; |
57 | 64 | 172894351744069800071834 /* AITestData_ja.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = AITestData_ja.txt; sourceTree = "<group>"; }; |
58 | 65 | 173BB42316C65FBB00126A00 /* config.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; lineEnding = 2; path = config.txt; sourceTree = "<group>"; }; |
@@ -98,6 +105,7 @@ | ||
98 | 105 | 175A87A316B5827800F5166E /* AI003 */ = { |
99 | 106 | isa = PBXGroup; |
100 | 107 | children = ( |
108 | + 171C8B3117490BAE00E95F41 /* memory.txt */, | |
101 | 109 | 175A87A616B5827800F5166E /* AI003.1 */, |
102 | 110 | 173BB42316C65FBB00126A00 /* config.txt */, |
103 | 111 | 175A87AF16B5833500F5166E /* core.h */, |
@@ -105,6 +113,8 @@ | ||
105 | 113 | 173BB42716C660E000126A00 /* words.txt */, |
106 | 114 | 172894331744069100071834 /* AITestData_en.txt */, |
107 | 115 | 172894351744069800071834 /* AITestData_ja.txt */, |
116 | + 170FE1E617493EFA0049FBBB /* memory.c */, | |
117 | + 170FE1E917493FB10049FBBB /* wlfilter.c */, | |
108 | 118 | ); |
109 | 119 | path = AI003; |
110 | 120 | sourceTree = "<group>"; |
@@ -186,6 +196,8 @@ | ||
186 | 196 | buildActionMask = 2147483647; |
187 | 197 | files = ( |
188 | 198 | 175A87A516B5827800F5166E /* main.c in Sources */, |
199 | + 170FE1E717493EFA0049FBBB /* memory.c in Sources */, | |
200 | + 170FE1EA17493FB10049FBBB /* wlfilter.c in Sources */, | |
189 | 201 | ); |
190 | 202 | runOnlyForDeploymentPostprocessing = 0; |
191 | 203 | }; |
@@ -85,19 +85,6 @@ | ||
85 | 85 | shouldBeEnabled = "No" |
86 | 86 | ignoreCount = "0" |
87 | 87 | continueAfterRunningActions = "No" |
88 | - filePath = "AI003/main.c" | |
89 | - timestampString = "390602565.100723" | |
90 | - startingColumnNumber = "9223372036854775807" | |
91 | - endingColumnNumber = "9223372036854775807" | |
92 | - startingLineNumber = "280" | |
93 | - endingLineNumber = "280" | |
94 | - landmarkName = "AI_Memory_AddRootWordData()" | |
95 | - landmarkType = "7"> | |
96 | - </FileBreakpoint> | |
97 | - <FileBreakpoint | |
98 | - shouldBeEnabled = "No" | |
99 | - ignoreCount = "0" | |
100 | - continueAfterRunningActions = "No" | |
101 | 88 | filePath = "AI003/chnlib.h" |
102 | 89 | timestampString = "382105653.921843" |
103 | 90 | startingColumnNumber = "9223372036854775807" |
@@ -136,11 +123,11 @@ | ||
136 | 123 | ignoreCount = "0" |
137 | 124 | continueAfterRunningActions = "No" |
138 | 125 | filePath = "AI003/main.c" |
139 | - timestampString = "390336991.21306" | |
126 | + timestampString = "390676538.932936" | |
140 | 127 | startingColumnNumber = "9223372036854775807" |
141 | 128 | endingColumnNumber = "9223372036854775807" |
142 | - startingLineNumber = "58" | |
143 | - endingLineNumber = "58" | |
129 | + startingLineNumber = "57" | |
130 | + endingLineNumber = "57" | |
144 | 131 | landmarkName = "main()" |
145 | 132 | landmarkType = "7"> |
146 | 133 | </FileBreakpoint> |
@@ -175,11 +162,11 @@ | ||
175 | 162 | ignoreCount = "0" |
176 | 163 | continueAfterRunningActions = "No" |
177 | 164 | filePath = "AI003/main.c" |
178 | - timestampString = "390602565.100723" | |
165 | + timestampString = "390676538.932936" | |
179 | 166 | startingColumnNumber = "9223372036854775807" |
180 | 167 | endingColumnNumber = "9223372036854775807" |
181 | - startingLineNumber = "119" | |
182 | - endingLineNumber = "119" | |
168 | + startingLineNumber = "145" | |
169 | + endingLineNumber = "145" | |
183 | 170 | landmarkName = "AI_Think_LearnWordFromInputString()" |
184 | 171 | landmarkType = "7"> |
185 | 172 | </FileBreakpoint> |
@@ -188,11 +175,11 @@ | ||
188 | 175 | ignoreCount = "0" |
189 | 176 | continueAfterRunningActions = "No" |
190 | 177 | filePath = "AI003/main.c" |
191 | - timestampString = "390602565.100723" | |
178 | + timestampString = "390676538.932936" | |
192 | 179 | startingColumnNumber = "9223372036854775807" |
193 | 180 | endingColumnNumber = "9223372036854775807" |
194 | - startingLineNumber = "136" | |
195 | - endingLineNumber = "136" | |
181 | + startingLineNumber = "161" | |
182 | + endingLineNumber = "161" | |
196 | 183 | landmarkName = "AI_Think_LearnWordFromInputString()" |
197 | 184 | landmarkType = "7"> |
198 | 185 | </FileBreakpoint> |
@@ -201,11 +188,11 @@ | ||
201 | 188 | ignoreCount = "0" |
202 | 189 | continueAfterRunningActions = "No" |
203 | 190 | filePath = "AI003/main.c" |
204 | - timestampString = "390602565.100723" | |
191 | + timestampString = "390676538.932936" | |
205 | 192 | startingColumnNumber = "9223372036854775807" |
206 | 193 | endingColumnNumber = "9223372036854775807" |
207 | - startingLineNumber = "129" | |
208 | - endingLineNumber = "129" | |
194 | + startingLineNumber = "154" | |
195 | + endingLineNumber = "154" | |
209 | 196 | landmarkName = "AI_Think_LearnWordFromInputString()" |
210 | 197 | landmarkType = "7"> |
211 | 198 | </FileBreakpoint> |
@@ -214,11 +201,11 @@ | ||
214 | 201 | ignoreCount = "0" |
215 | 202 | continueAfterRunningActions = "No" |
216 | 203 | filePath = "AI003/main.c" |
217 | - timestampString = "390602565.100723" | |
204 | + timestampString = "390676538.932936" | |
218 | 205 | startingColumnNumber = "9223372036854775807" |
219 | 206 | endingColumnNumber = "9223372036854775807" |
220 | - startingLineNumber = "120" | |
221 | - endingLineNumber = "120" | |
207 | + startingLineNumber = "146" | |
208 | + endingLineNumber = "146" | |
222 | 209 | landmarkName = "AI_Think_LearnWordFromInputString()" |
223 | 210 | landmarkType = "7"> |
224 | 211 | </FileBreakpoint> |
@@ -227,11 +214,11 @@ | ||
227 | 214 | ignoreCount = "0" |
228 | 215 | continueAfterRunningActions = "No" |
229 | 216 | filePath = "AI003/main.c" |
230 | - timestampString = "390602565.100723" | |
217 | + timestampString = "390676538.932936" | |
231 | 218 | startingColumnNumber = "9223372036854775807" |
232 | 219 | endingColumnNumber = "9223372036854775807" |
233 | - startingLineNumber = "186" | |
234 | - endingLineNumber = "186" | |
220 | + startingLineNumber = "211" | |
221 | + endingLineNumber = "211" | |
235 | 222 | landmarkName = "AI_Think_SlideLookUpWordByHistory()" |
236 | 223 | landmarkType = "7"> |
237 | 224 | </FileBreakpoint> |
@@ -240,13 +227,39 @@ | ||
240 | 227 | ignoreCount = "0" |
241 | 228 | continueAfterRunningActions = "No" |
242 | 229 | filePath = "AI003/main.c" |
243 | - timestampString = "390602565.100723" | |
230 | + timestampString = "390676538.932936" | |
244 | 231 | startingColumnNumber = "9223372036854775807" |
245 | 232 | endingColumnNumber = "9223372036854775807" |
246 | - startingLineNumber = "192" | |
247 | - endingLineNumber = "192" | |
233 | + startingLineNumber = "217" | |
234 | + endingLineNumber = "217" | |
248 | 235 | landmarkName = "AI_Think_SlideLookUpWordByHistory()" |
249 | 236 | landmarkType = "7"> |
250 | 237 | </FileBreakpoint> |
238 | + <FileBreakpoint | |
239 | + shouldBeEnabled = "No" | |
240 | + ignoreCount = "0" | |
241 | + continueAfterRunningActions = "No" | |
242 | + filePath = "../chn/chnlib04.c" | |
243 | + timestampString = "390618368.792293" | |
244 | + startingColumnNumber = "9223372036854775807" | |
245 | + endingColumnNumber = "9223372036854775807" | |
246 | + startingLineNumber = "226" | |
247 | + endingLineNumber = "226" | |
248 | + landmarkName = "CHNLIB_UTF8_GetByteSizeFromLengthByCharacter()" | |
249 | + landmarkType = "7"> | |
250 | + </FileBreakpoint> | |
251 | + <FileBreakpoint | |
252 | + shouldBeEnabled = "Yes" | |
253 | + ignoreCount = "0" | |
254 | + continueAfterRunningActions = "No" | |
255 | + filePath = "../chn/chnlib04.c" | |
256 | + timestampString = "390618364.135592" | |
257 | + startingColumnNumber = "9223372036854775807" | |
258 | + endingColumnNumber = "9223372036854775807" | |
259 | + startingLineNumber = "220" | |
260 | + endingLineNumber = "220" | |
261 | + landmarkName = "CHNLIB_UTF8_GetByteSizeFromLengthByCharacter()" | |
262 | + landmarkType = "7"> | |
263 | + </FileBreakpoint> | |
251 | 264 | </FileBreakpoints> |
252 | 265 | </Bucket> |
@@ -1 +1,2 @@ | ||
1 | 1 | words.txt |
2 | +memory.txt | |
\ No newline at end of file |
@@ -13,11 +13,21 @@ | ||
13 | 13 | |
14 | 14 | #define AI_CONFIG_FILE_NAME "config.txt" |
15 | 15 | #define AI_INPUT_HISTORY_MAX 10 |
16 | +#define AI_EVENT_COUNT_0 10 | |
17 | + | |
18 | +#define AI_SW_Delimiter_Colon 1 | |
19 | +#define AI_SW_Delimiter_Comma 2 | |
20 | +#define AI_SW_Delimiter_Plus 3 | |
21 | +#define AI_SW_Bracket_Start 4 | |
22 | +#define AI_SW_Bracket_End 5 | |
16 | 23 | |
17 | 24 | typedef struct AI_WORKING_SET AI_WorkingSet; |
18 | 25 | struct AI_WORKING_SET { |
19 | - CHNLIB_UIPArray *SystemWordList0; | |
20 | - CHNLIB_UIPArray *RootWordList; | |
26 | + CHNLIB_UIPArray *SystemWordList0; //データ解釈用区切り文字列を格納 | |
27 | + CHNLIB_UIPArray *SystemWordList1; //記憶単位のデータ種類を表す文字列を格納 | |
28 | + CHNLIB_UIPArray *SystemWordList2; //数字に使用する文字列を格納 | |
29 | + CHNLIB_UIPArray *RootWordList; //あらゆる文字列のStringを保持する。data32は単語カウント。 | |
30 | + CHNLIB_UIPArray *RootMemory; //記憶データを保持する。 | |
21 | 31 | CHNLIB_UIPArray *InputHistory; |
22 | 32 | }; |
23 | 33 |
@@ -25,11 +35,22 @@ struct AI_WORKING_SET { | ||
25 | 35 | extern AI_WorkingSet WorkingSet; |
26 | 36 | void AI_Think_LearnWordFromInputString(CHNLIB_String *input); |
27 | 37 | CHNLIB_UIPArray *AI_Think_SlideLookUpWordByHistory(CHNLIB_String *input); |
28 | -int AI_Think_CandidateWordList_Filter00(CHNLIB_UIPArray **candidatewordlist); | |
29 | -int AI_Think_CandidateWordList_Filter01(CHNLIB_UIPArray **candidatewordlist, int length); | |
38 | +CHNLIB_UIPArray *AI_Think_WordList_GetSortedByLength(const CHNLIB_UIPArray *wordlist); | |
39 | +void AI_Think_WordList_SetLengthToData32(CHNLIB_UIPArray **wordlist); | |
40 | +void AI_System_InitializeSystemWorkingSet(void); | |
41 | + | |
42 | +//@memory.c | |
30 | 43 | int AI_Memory_AddRootWordData(CHNLIB_String *tag); |
31 | 44 | int AI_Memory_AddRootWordData_IsDuplicated(const void *listtag, const void *newtag); |
32 | -void AI_System_InitializeSystemWorkingSet(void); | |
45 | +int AI_Memory_AddRootMemoryData(CHNLIB_UIPArray *tag); | |
46 | +int AI_Memory_AddRootMemoryData_IsDuplicated(const void *listtag, const void *newtag); | |
33 | 47 | void AI_System_LoadMemory(const char configfilename[]); |
48 | +void AI_System_SaveMemory_RootWordList(const char configfilename[]); | |
49 | +void AI_System_SaveMemory_RootMemory(const char memlistfilename[]); | |
50 | + | |
51 | +//@wlfilter.c | |
52 | +int AI_Think_CandidateWordList_Filter00(CHNLIB_UIPArray **candidatewordlist); | |
53 | +int AI_Think_CandidateWordList_Filter01(CHNLIB_UIPArray **candidatewordlist, int length); | |
54 | +int AI_Think_CandidateWordList_Filter02(CHNLIB_UIPArray **candidatewordlist, uint count); | |
34 | 55 | |
35 | 56 | #endif |
@@ -22,23 +22,22 @@ AI_WorkingSet WorkingSet; | ||
22 | 22 | int main(int argc, const char * argv[]) |
23 | 23 | { |
24 | 24 | //エントリポイント |
25 | - int i, i_max; | |
25 | + int i, i_max, j, count; | |
26 | 26 | CHNLIB_String *input, *temp; |
27 | 27 | CHNLIB_UIPArray *separated, *sorted; |
28 | 28 | int passthink; |
29 | - FILE *readfp; | |
29 | + FILE *readfp, *writefp; | |
30 | 30 | |
31 | 31 | CHNLIB_Environment_SetCurrentWorkingDirectory(argv[0]); |
32 | 32 | |
33 | - CHNLIB_Debug("Hello, World.", CHNLIB_DEBUG_ARGUMENTS); | |
34 | - | |
35 | 33 | AI_System_InitializeSystemWorkingSet(); |
36 | 34 | |
37 | 35 | AI_System_LoadMemory(AI_CONFIG_FILE_NAME); |
38 | 36 | |
39 | 37 | readfp = NULL; |
38 | + writefp = NULL; | |
40 | 39 | |
41 | - for(;;){ | |
40 | + for(count = 0; ; count++){ | |
42 | 41 | passthink = False; |
43 | 42 | if(readfp == NULL){ |
44 | 43 | input = CHNLIB_ReadLine(stdin); |
@@ -64,26 +63,53 @@ int main(int argc, const char * argv[]) | ||
64 | 63 | } else if(CHNLIB_String_CompareStringWithCString(temp, "exit")){ |
65 | 64 | break; |
66 | 65 | } else if(CHNLIB_String_CompareStringWithCString(temp, "wordlist")){ |
67 | - sorted = CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(WorkingSet.RootWordList); | |
66 | + temp = CHNLIB_UIPArray_GetPointerByIndex(separated, 4); | |
67 | + if(temp == NULL){ | |
68 | + //そのまま表示 | |
69 | + sorted = WorkingSet.RootWordList; | |
70 | + retain(sorted); | |
71 | + } else if(CHNLIB_String_CompareStringWithCString(temp, "count")){ | |
72 | + //回数カウント順 | |
73 | + sorted = CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(WorkingSet.RootWordList); | |
74 | + } else if(CHNLIB_String_CompareStringWithCString(temp, "length")){ | |
75 | + //文字列長順 | |
76 | + sorted = AI_Think_WordList_GetSortedByLength(WorkingSet.RootWordList); | |
77 | + } else{ | |
78 | + sorted = NULL; | |
79 | + } | |
80 | + | |
68 | 81 | i_max = CHNLIB_UIPArray_GetNumberOfDatas(sorted); |
82 | + j = 0; | |
69 | 83 | for(i = 0; i < i_max; i++){ |
70 | 84 | printf("word%3d:%3d:%s\n", i, CHNLIB_UIPArray_GetData32ByIndex(sorted, i), CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(sorted, i))); |
85 | + j += CHNLIB_UIPArray_GetData32ByIndex(sorted, i); | |
86 | + } | |
87 | + if(i > 0){ | |
88 | + printf("Average:%d\n", j / i); | |
71 | 89 | } |
72 | 90 | //CHNLIB_UIPArray_FreeOnlyArray(&sorted); |
73 | 91 | release(sorted); |
92 | + } else if(CHNLIB_String_CompareStringWithCString(temp, "memlist")){ | |
93 | + CHNLIB_Debug_PrintStructureData(WorkingSet.RootMemory, 0); | |
74 | 94 | } else if(CHNLIB_String_CompareStringWithCString(temp, "readfile")){ |
75 | 95 | //::readfile:filename |
76 | - readfp = fopen(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(separated, 4)), "rb"); | |
77 | 96 | if(readfp == NULL){ |
78 | - puts("File open error."); | |
97 | + readfp = fopen(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(separated, 4)), "rb"); | |
98 | + if(readfp == NULL){ | |
99 | + puts("File open error."); | |
100 | + } | |
79 | 101 | } |
102 | + } else if(CHNLIB_String_CompareStringWithCString(temp, "savewordlist")){ | |
103 | + AI_System_SaveMemory_RootWordList(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(separated, 4))); | |
104 | + } else if(CHNLIB_String_CompareStringWithCString(temp, "savememlist")){ | |
105 | + AI_System_SaveMemory_RootMemory(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(separated, 4))); | |
106 | + } else if(CHNLIB_String_CompareStringWithCString(temp, "addmemtag")){ | |
107 | + //[not implemented] | |
80 | 108 | } else{ |
81 | 109 | passthink = False; |
82 | 110 | } |
83 | 111 | } |
84 | 112 | |
85 | - ////WorkingSet.SystemWordList0を使っているので、解放しないように注意 | |
86 | - //CHNLIB_UIPArray_FreeSelectedAll(&separated); | |
87 | 113 | release(separated); |
88 | 114 | } |
89 | 115 |
@@ -113,13 +139,12 @@ void AI_Think_LearnWordFromInputString(CHNLIB_String *input) | ||
113 | 139 | //入力文字列から単語を抽出して記憶する。 |
114 | 140 | CHNLIB_UIPArray *candidateWordList; |
115 | 141 | int i, i_max; |
116 | - int tagIndex, maxExistingWordIndex; | |
142 | + int tagIndex; | |
117 | 143 | |
118 | 144 | candidateWordList = CHNLIB_UIPArray_Initialize(); |
119 | 145 | candidateWordList = AI_Think_SlideLookUpWordByHistory(input); |
120 | 146 | i_max = CHNLIB_UIPArray_GetNumberOfDatas(candidateWordList); |
121 | - maxExistingWordIndex = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.RootWordList) - 1; | |
122 | - | |
147 | + | |
123 | 148 | printf("Index(Decimal),CountOfContain(Decimal), String\n"); |
124 | 149 | for(i = 0; i < i_max; i++){ |
125 | 150 | printf("%d,%d,%s\n", i, CHNLIB_UIPArray_GetData32ByIndex(candidateWordList, i), CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(candidateWordList, i))); |
@@ -201,134 +226,82 @@ CHNLIB_UIPArray *AI_Think_SlideLookUpWordByHistory(CHNLIB_String *input) | ||
201 | 226 | } |
202 | 227 | |
203 | 228 | //重複抽出フィルタリング |
229 | + AI_Think_CandidateWordList_Filter02(&candidatewordlist, 1); | |
204 | 230 | AI_Think_CandidateWordList_Filter01(&candidatewordlist, 1); |
205 | 231 | AI_Think_CandidateWordList_Filter00(&candidatewordlist); |
206 | 232 | |
207 | 233 | return candidatewordlist; |
208 | 234 | } |
209 | 235 | |
210 | -int AI_Think_CandidateWordList_Filter00(CHNLIB_UIPArray **candidatewordlist) | |
236 | +CHNLIB_UIPArray *AI_Think_WordList_GetSortedByLength(const CHNLIB_UIPArray *wordlist) | |
211 | 237 | { |
212 | - //[Not implemented] | |
213 | - //[UTF-8] | |
214 | - //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。 | |
215 | - //00:長い単語に含まれており、かつ出現頻度が長い単語と等しい単語を削除 | |
216 | - int i, i_max; | |
217 | - CHNLIB_String *nowstr, *basestr; | |
218 | - int basestrCoC; //CountOfContainInHistoryStrings | |
238 | + CHNLIB_UIPArray *temp, *sorted; | |
219 | 239 | |
220 | - i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist); | |
221 | - basestr = CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, 0); | |
222 | - basestrCoC = CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, 0); | |
223 | - for(i = 1; i < i_max; i++){ | |
224 | - nowstr = CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, i); | |
225 | - if(CHNLIB_UTF8_GetCountOfContain(CHNLIB_String_GetReferencePointerOfCString(basestr), CHNLIB_String_GetReferencePointerOfCString(nowstr)) > 0){ | |
226 | - //nowstrはbasestrに含まれている | |
227 | - if(basestrCoC == CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i)){ | |
228 | - //かつ出現頻度が等しいので不要な単語 | |
229 | - //出現頻度を0にして、後で削除する。 | |
230 | - CHNLIB_UIPArray_SetData32ByIndex(*candidatewordlist, i, 0); | |
231 | - } | |
232 | - } | |
233 | - | |
234 | - if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) != 0){ | |
235 | - //単語は削除されなかった、つまり異なる単語なので、basestrを更新 | |
236 | - basestr = nowstr; | |
237 | - basestrCoC = CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i); | |
238 | - } | |
239 | - } | |
240 | + temp = CHNLIB_UIPArray_CopyArray(wordlist); | |
240 | 241 | |
241 | - for(i = 1; i < i_max; i++){ | |
242 | - if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) == 0){ | |
243 | - //削除対象 | |
244 | - CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i); | |
245 | - i--; | |
246 | - i_max--; | |
247 | - } | |
248 | - } | |
242 | + AI_Think_WordList_SetLengthToData32(&temp); | |
243 | + sorted = CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(temp); | |
249 | 244 | |
250 | - return 0; | |
245 | + release(temp); | |
246 | + | |
247 | + return sorted; | |
251 | 248 | } |
252 | 249 | |
253 | -int AI_Think_CandidateWordList_Filter01(CHNLIB_UIPArray **candidatewordlist, int length) | |
250 | +void AI_Think_WordList_SetLengthToData32(CHNLIB_UIPArray **wordlist) | |
254 | 251 | { |
255 | - //[Not implemented] | |
256 | - //[UTF-8] | |
257 | - //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。 | |
258 | - //01:length以下の文字数の単語を削除 | |
259 | - | |
260 | 252 | int i, i_max; |
261 | 253 | |
262 | - i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist); | |
254 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(*wordlist); | |
255 | + | |
263 | 256 | for(i = 0; i < i_max; i++){ |
264 | - if(CHNLIB_UTF8_GetStringLengthByCharacter(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, i))) <= length){ | |
265 | - CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i); | |
266 | - i--; | |
267 | - i_max--; | |
268 | - } | |
257 | + CHNLIB_UIPArray_SetData32ByIndex(*wordlist, i, CHNLIB_UTF8_GetStringLengthByCharacter(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(*wordlist, i)))); | |
269 | 258 | } |
270 | 259 | |
271 | - return 0; | |
272 | -} | |
273 | - | |
274 | -int AI_Memory_AddRootWordData(CHNLIB_String *tag) | |
275 | -{ | |
276 | - //WorkingSet.RootWordListに文字列を追加する。 | |
277 | - //重複がある場合は警告を出し、追加しない。 | |
278 | - //戻り値は追加されたまたは重複したタグのIndex. | |
279 | - | |
280 | - return CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&WorkingSet.RootWordList, 0, tag, &AI_Memory_AddRootWordData_IsDuplicated); | |
281 | -} | |
282 | - | |
283 | -int AI_Memory_AddRootWordData_IsDuplicated(const void *listtag, const void *newtag) | |
284 | -{ | |
285 | - //CHNLIB_UIPArray_AppendLast_ProtectFromDuplicationに渡す関数ポインタ。 | |
286 | - if(CHNLIB_StructureHeader_GetTypeID(listtag) != CHNLIB_STRUCT_ID_String){ | |
287 | - return False; | |
288 | - } | |
289 | - if(CHNLIB_String_CompareString_Strict(listtag, newtag)){ | |
290 | - CHNLIB_ReportError("Word[%s] has already existed.", CHNLIB_DEBUG_ARGUMENTS, CHNLIB_String_GetReferencePointerOfCString(newtag)); | |
291 | - return True; | |
292 | - } | |
293 | - return False; | |
260 | + return; | |
294 | 261 | } |
295 | 262 | |
296 | 263 | void AI_System_InitializeSystemWorkingSet(void) |
297 | 264 | { |
298 | 265 | //WorkingSetを初期化する。 |
266 | + int i, i_max; | |
267 | + | |
299 | 268 | WorkingSet.SystemWordList0 = CHNLIB_UIPArray_Initialize(); |
300 | - CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, True, autorelease(CHNLIB_String_Initialize(":"))); | |
301 | - CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, True, autorelease(CHNLIB_String_Initialize(","))); | |
269 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Delimiter_Colon, autorelease(CHNLIB_String_Initialize(":"))); | |
270 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Delimiter_Comma, autorelease(CHNLIB_String_Initialize(","))); | |
271 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Delimiter_Plus, autorelease(CHNLIB_String_Initialize("+"))); | |
272 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Bracket_Start, autorelease(CHNLIB_String_Initialize("["))); | |
273 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Bracket_End, autorelease(CHNLIB_String_Initialize("]"))); | |
302 | 274 | |
303 | - WorkingSet.InputHistory = CHNLIB_UIPArray_Initialize(); | |
275 | + WorkingSet.SystemWordList1 = CHNLIB_UIPArray_Initialize(); | |
276 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList1, True, autorelease(CHNLIB_String_Initialize("未定義"))); | |
277 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList1, True, autorelease(CHNLIB_String_Initialize("真"))); | |
278 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList1, True, autorelease(CHNLIB_String_Initialize("偽"))); | |
279 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList1, True, autorelease(CHNLIB_String_Initialize("あいさつ"))); | |
304 | 280 | |
305 | - return; | |
306 | -} | |
307 | - | |
308 | -void AI_System_LoadMemory(const char configfilename[]) | |
309 | -{ | |
310 | - //指定されたファイル名のテキストファイルから設定を読み出す。 | |
311 | - FILE *fp; | |
312 | - CHNLIB_String *line, *currentfilename; | |
313 | - int i; | |
281 | + WorkingSet.SystemWordList2 = CHNLIB_UIPArray_Initialize(); | |
282 | + for(i = 0; i < 10; i++){ | |
283 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList2, True, autorelease(CHNLIB_String_InitializeWithFormat("%d", i))); | |
284 | + } | |
285 | + | |
286 | + WorkingSet.RootWordList = CHNLIB_UIPArray_Initialize(); | |
287 | + WorkingSet.RootMemory = CHNLIB_UIPArray_Initialize(); | |
288 | + WorkingSet.InputHistory = CHNLIB_UIPArray_Initialize(); | |
314 | 289 | |
315 | - fp = fopen(configfilename, "rb"); | |
316 | - currentfilename = CHNLIB_ReadLine(fp); | |
317 | - fclose(fp); | |
290 | + //WordListへシステム文字列を追加 | |
291 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.SystemWordList0); | |
292 | + for(i = 0; i < i_max; i++){ | |
293 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.RootWordList, 0, CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.SystemWordList0, i)); | |
294 | + } | |
318 | 295 | |
319 | - fp = fopen(CHNLIB_String_GetReferencePointerOfCString(currentfilename), "rb"); | |
320 | - release(currentfilename); | |
296 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.SystemWordList1); | |
297 | + for(i = 0; i < i_max; i++){ | |
298 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.RootWordList, 0, CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.SystemWordList1, i)); | |
299 | + } | |
321 | 300 | |
322 | - WorkingSet.RootWordList = CHNLIB_UIPArray_Initialize(); | |
323 | - for(i = 1; ;i++){ | |
324 | - line = CHNLIB_ReadLine(fp); | |
325 | - if(line == NULL){ | |
326 | - break; | |
327 | - } | |
328 | - CHNLIB_UIPArray_AppendLast(&WorkingSet.RootWordList, i, line); | |
329 | - release(line); | |
301 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.SystemWordList2); | |
302 | + for(i = 0; i < i_max; i++){ | |
303 | + CHNLIB_UIPArray_AppendLast(&WorkingSet.RootWordList, 0, CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.SystemWordList2, i)); | |
330 | 304 | } |
331 | - fclose(fp); | |
332 | 305 | |
333 | 306 | return; |
334 | 307 | } |
@@ -0,0 +1,252 @@ | ||
1 | +// | |
2 | +// memory.c | |
3 | +// AI003 | |
4 | +// | |
5 | +// Created by 西田 耀 on 13/05/20. | |
6 | +// Copyright (c) 2013年 Hikaru Nishida. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#include <stdio.h> | |
10 | +#include <stdlib.h> | |
11 | +#include "core.h" | |
12 | + | |
13 | +int AI_Memory_AddRootWordData(CHNLIB_String *tag) | |
14 | +{ | |
15 | + //WorkingSet.RootWordListに文字列を追加する。 | |
16 | + //重複がある場合は警告を出し、追加しない。 | |
17 | + //戻り値は追加されたまたは重複したタグのIndex. | |
18 | + | |
19 | + return CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&WorkingSet.RootWordList, 0, tag, &AI_Memory_AddRootWordData_IsDuplicated); | |
20 | +} | |
21 | + | |
22 | +int AI_Memory_AddRootWordData_IsDuplicated(const void *listtag, const void *newtag) | |
23 | +{ | |
24 | + //CHNLIB_UIPArray_AppendLast_ProtectFromDuplicationに渡す関数ポインタ。 | |
25 | + if(CHNLIB_StructureHeader_GetTypeID(listtag) != CHNLIB_STRUCT_ID_String){ | |
26 | + return False; | |
27 | + } | |
28 | + if(CHNLIB_String_CompareString_Strict(listtag, newtag)){ | |
29 | + //CHNLIB_ReportError("Word[%s] has already existed.", CHNLIB_DEBUG_ARGUMENTS, CHNLIB_String_GetReferencePointerOfCString(newtag)); | |
30 | + return True; | |
31 | + } | |
32 | + return False; | |
33 | +} | |
34 | + | |
35 | +int AI_Memory_AddRootMemoryData(CHNLIB_UIPArray *tag) | |
36 | +{ | |
37 | + //WorkingSet.RootWordListに文字列を追加する。 | |
38 | + //重複がある場合は警告を出し、追加しない。 | |
39 | + //戻り値は追加されたまたは重複したタグのIndex. | |
40 | + | |
41 | + return CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&WorkingSet.RootMemory, 0, tag, &AI_Memory_AddRootMemoryData_IsDuplicated); | |
42 | +} | |
43 | + | |
44 | +int AI_Memory_AddRootMemoryData_IsDuplicated(const void *listtag, const void *newtag) | |
45 | +{ | |
46 | + //CHNLIB_UIPArray_AppendLast_ProtectFromDuplicationに渡す関数ポインタ。 | |
47 | + CHNLIB_UIPArray *listtag_strArray, *newtag_strArray; | |
48 | + int i, i_max; | |
49 | + | |
50 | + if(CHNLIB_StructureHeader_GetTypeID(listtag) != CHNLIB_STRUCT_ID_UIPArray){ | |
51 | + return False; | |
52 | + } | |
53 | + | |
54 | + listtag_strArray = CHNLIB_UIPArray_GetPointerByIndex(listtag, 0); | |
55 | + newtag_strArray = CHNLIB_UIPArray_GetPointerByIndex(newtag, 0); | |
56 | + | |
57 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(listtag_strArray); | |
58 | + if(i_max == CHNLIB_UIPArray_GetNumberOfDatas(newtag_strArray)){ | |
59 | + //文字列配列の要素数が一致するので、内容も一致する可能性がある | |
60 | + for(i = 0; i < i_max; i++){ | |
61 | + if(!CHNLIB_String_CompareString_Strict(CHNLIB_UIPArray_GetPointerByIndex(listtag_strArray, i), CHNLIB_UIPArray_GetPointerByIndex(newtag_strArray, i))){ | |
62 | + //一致しないタグがあったので、不一致 | |
63 | + return False; | |
64 | + } | |
65 | + } | |
66 | + //すべて一致したので、重複している | |
67 | + return True; | |
68 | + } | |
69 | + //文字列配列の要素数が一致しないので、不一致 | |
70 | + return False; | |
71 | +} | |
72 | + | |
73 | +//記憶ファイルの構成・書式 | |
74 | +//-config.txt | |
75 | +// 一行目に単語リストファイル(words.txt) | |
76 | +// 二行目に記憶データファイル(memory.txt) | |
77 | +// のファイル名を記述する。 | |
78 | +// | |
79 | +//-words.txt | |
80 | +//<単語カウント>:<単語文字列> | |
81 | +// | |
82 | +//-memory.txt | |
83 | +//[<文字列単語>+<文字列単語>+...][<属性値1>,<属性値2>,...][<属性値a>,<属性値b>,...] | |
84 | +// | |
85 | +// | |
86 | +void AI_System_LoadMemory(const char configfilename[]) | |
87 | +{ | |
88 | + //指定されたファイル名のテキストファイルから設定を読み出す。 | |
89 | + FILE *configfp, *readfp; | |
90 | + CHNLIB_String *line, *currentfilename; | |
91 | + uint wordCount; | |
92 | + char *invchar; | |
93 | + int tagIndex, i, i_max; | |
94 | + CHNLIB_UIPArray *separated, *dataArray, *subDataArray; | |
95 | + | |
96 | + configfp = fopen(configfilename, "rb"); | |
97 | + | |
98 | + //単語リストの読み込み | |
99 | + currentfilename = CHNLIB_ReadLine(configfp); | |
100 | + readfp = fopen(CHNLIB_String_GetReferencePointerOfCString(currentfilename), "rb"); | |
101 | + release(currentfilename); | |
102 | + | |
103 | + for(;;){ | |
104 | + line = CHNLIB_ReadLine(readfp); | |
105 | + if(line == NULL){ | |
106 | + break; | |
107 | + } | |
108 | + wordCount = (uint)strtol(CHNLIB_String_GetReferencePointerOfCString(line), &invchar, 0); | |
109 | + for(; *invchar != '\0'; invchar++){ | |
110 | + if(*invchar == ':'){ | |
111 | + invchar++; | |
112 | + break; | |
113 | + } | |
114 | + } | |
115 | + tagIndex = AI_Memory_AddRootWordData(autorelease(CHNLIB_String_Initialize(invchar))); | |
116 | + CHNLIB_UIPArray_SetData32ByIndex(WorkingSet.RootWordList, tagIndex, CHNLIB_UIPArray_GetData32ByIndex(WorkingSet.RootWordList, tagIndex) + wordCount); | |
117 | + release(line); | |
118 | + } | |
119 | + fclose(readfp); | |
120 | + | |
121 | + //記憶データの読み込み | |
122 | + currentfilename = CHNLIB_ReadLine(configfp); | |
123 | + readfp = fopen(CHNLIB_String_GetReferencePointerOfCString(currentfilename), "rb"); | |
124 | + release(currentfilename); | |
125 | + | |
126 | + for(;;){ | |
127 | + line = CHNLIB_ReadLine(readfp); | |
128 | + if(line == NULL){ | |
129 | + break; | |
130 | + } | |
131 | + separated = CHNLIB_UIPArray_Initialize(); | |
132 | + CHNLIB_UIPArray_GetSeparatedStringByUIPArray(&separated, WorkingSet.SystemWordList0, line); | |
133 | + | |
134 | + dataArray = CHNLIB_UIPArray_Initialize(); | |
135 | + subDataArray = CHNLIB_UIPArray_Initialize(); | |
136 | + | |
137 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(separated); | |
138 | + for(i = 0; i < i_max; i++){ | |
139 | + switch (CHNLIB_UIPArray_GetData32ByIndex(separated, i)) { | |
140 | + case AI_SW_Delimiter_Colon: | |
141 | + //: | |
142 | + break; | |
143 | + | |
144 | + case AI_SW_Delimiter_Comma: | |
145 | + //, | |
146 | + break; | |
147 | + | |
148 | + case AI_SW_Delimiter_Plus: | |
149 | + //+ | |
150 | + break; | |
151 | + | |
152 | + case AI_SW_Bracket_Start: | |
153 | + //[ | |
154 | + subDataArray = CHNLIB_UIPArray_Initialize(); | |
155 | + break; | |
156 | + | |
157 | + case AI_SW_Bracket_End: | |
158 | + //] | |
159 | + CHNLIB_UIPArray_AppendLast(&dataArray, 0, subDataArray); | |
160 | + release(subDataArray); | |
161 | + break; | |
162 | + | |
163 | + case 0: | |
164 | + //文字列 | |
165 | + tagIndex = AI_Memory_AddRootWordData(CHNLIB_UIPArray_GetPointerByIndex(separated, i)); | |
166 | + CHNLIB_UIPArray_AppendLast(&subDataArray, 0, CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.RootWordList, tagIndex)); | |
167 | + | |
168 | + break; | |
169 | + } | |
170 | + } | |
171 | + if(dataArray != NULL){ | |
172 | + AI_Memory_AddRootMemoryData(dataArray); | |
173 | + release(dataArray); | |
174 | + } | |
175 | + release(separated); | |
176 | + release(line); | |
177 | + } | |
178 | + fclose(readfp); | |
179 | + | |
180 | + //終了処理 | |
181 | + fclose(configfp); | |
182 | + | |
183 | + return; | |
184 | +} | |
185 | + | |
186 | +void AI_System_SaveMemory_RootWordList(const char wordlistfilename[]) | |
187 | +{ | |
188 | + //指定されたファイル名へ単語リストを出力する。 | |
189 | + FILE *writefp; | |
190 | + CHNLIB_UIPArray *sorted; | |
191 | + int i, i_max; | |
192 | + | |
193 | + writefp = fopen(wordlistfilename, "wb"); | |
194 | + if(writefp == NULL){ | |
195 | + puts("File open error."); | |
196 | + } else{ | |
197 | + sorted = CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(WorkingSet.RootWordList); | |
198 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(sorted); | |
199 | + for(i = 0; i < i_max; i++){ | |
200 | + fprintf(writefp, "%10d:%s\n", CHNLIB_UIPArray_GetData32ByIndex(sorted, i), CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(sorted, i))); | |
201 | + } | |
202 | + fclose(writefp); | |
203 | + writefp = NULL; | |
204 | + release(sorted); | |
205 | + puts("Save RootWordList done."); | |
206 | + } | |
207 | + | |
208 | + return; | |
209 | +} | |
210 | + | |
211 | +void AI_System_SaveMemory_RootMemory(const char memlistfilename[]) | |
212 | +{ | |
213 | + //指定されたファイル名へ記憶データを出力する。 | |
214 | + FILE *writefp; | |
215 | + CHNLIB_UIPArray *subArray; | |
216 | + int i, i_max; | |
217 | + int j, j_max; | |
218 | + int k, k_max; | |
219 | + | |
220 | + writefp = fopen(memlistfilename, "wb"); | |
221 | + if(writefp == NULL){ | |
222 | + puts("File open error."); | |
223 | + } else{ | |
224 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.RootMemory); | |
225 | + for(i = 0; i < i_max; i++){ | |
226 | + subArray = CHNLIB_UIPArray_GetPointerByIndex(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.RootMemory, i), 0); | |
227 | + j_max = CHNLIB_UIPArray_GetNumberOfDatas(subArray); | |
228 | + fputc('[', writefp); | |
229 | + for(j = 0; j < j_max - 1; j++){ | |
230 | + fprintf(writefp, "%s+", CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(subArray, j))); | |
231 | + } | |
232 | + fprintf(writefp, "%s]", CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(subArray, j))); | |
233 | + | |
234 | + k_max = CHNLIB_UIPArray_GetNumberOfDatas(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.RootMemory, i)); | |
235 | + for(k = 1; k < k_max; k++){ | |
236 | + subArray = CHNLIB_UIPArray_GetPointerByIndex(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.RootMemory, i), k); | |
237 | + j_max = CHNLIB_UIPArray_GetNumberOfDatas(subArray); | |
238 | + fputc('[', writefp); | |
239 | + for(j = 0; j < j_max - 1; j++){ | |
240 | + fprintf(writefp, "%s,", CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(subArray, j))); | |
241 | + } | |
242 | + fprintf(writefp, "%s]", CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(subArray, j))); | |
243 | + } | |
244 | + fputc('\n', writefp); | |
245 | + } | |
246 | + fclose(writefp); | |
247 | + writefp = NULL; | |
248 | + puts("Save RootMemory done."); | |
249 | + } | |
250 | + | |
251 | + return; | |
252 | +} |
@@ -0,0 +1,92 @@ | ||
1 | +// | |
2 | +// wlfilter.c | |
3 | +// AI003 | |
4 | +// | |
5 | +// Created by 西田 耀 on 13/05/20. | |
6 | +// Copyright (c) 2013年 Hikaru Nishida. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#include <stdio.h> | |
10 | +#include "core.h" | |
11 | + | |
12 | +int AI_Think_CandidateWordList_Filter00(CHNLIB_UIPArray **candidatewordlist) | |
13 | +{ | |
14 | + //[UTF-8] | |
15 | + //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。 | |
16 | + //00:長い単語に含まれており、かつ出現頻度が長い単語と等しい単語を削除 | |
17 | + int i, i_max; | |
18 | + CHNLIB_String *nowstr, *basestr; | |
19 | + int basestrCoC; //CountOfContainInHistoryStrings | |
20 | + | |
21 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist); | |
22 | + basestr = CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, 0); | |
23 | + basestrCoC = CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, 0); | |
24 | + for(i = 1; i < i_max; i++){ | |
25 | + nowstr = CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, i); | |
26 | + if(CHNLIB_UTF8_GetCountOfContain(CHNLIB_String_GetReferencePointerOfCString(basestr), CHNLIB_String_GetReferencePointerOfCString(nowstr)) > 0){ | |
27 | + //nowstrはbasestrに含まれている | |
28 | + if(basestrCoC == CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i)){ | |
29 | + //かつ出現頻度が等しいので不要な単語 | |
30 | + //出現頻度を0にして、後で削除する。 | |
31 | + CHNLIB_UIPArray_SetData32ByIndex(*candidatewordlist, i, 0); | |
32 | + } | |
33 | + } | |
34 | + | |
35 | + if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) != 0){ | |
36 | + //単語は削除されなかった、つまり異なる単語なので、basestrを更新 | |
37 | + basestr = nowstr; | |
38 | + basestrCoC = CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i); | |
39 | + } | |
40 | + } | |
41 | + | |
42 | + for(i = 1; i < i_max; i++){ | |
43 | + if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) == 0){ | |
44 | + //削除対象 | |
45 | + CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i); | |
46 | + i--; | |
47 | + i_max--; | |
48 | + } | |
49 | + } | |
50 | + | |
51 | + return 0; | |
52 | +} | |
53 | + | |
54 | +int AI_Think_CandidateWordList_Filter01(CHNLIB_UIPArray **candidatewordlist, int length) | |
55 | +{ | |
56 | + //[UTF-8] | |
57 | + //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。 | |
58 | + //01:length以下の文字数の単語を削除 | |
59 | + | |
60 | + int i, i_max; | |
61 | + | |
62 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist); | |
63 | + for(i = 0; i < i_max; i++){ | |
64 | + if(CHNLIB_UTF8_GetStringLengthByCharacter(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, i))) <= length){ | |
65 | + CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i); | |
66 | + i--; | |
67 | + i_max--; | |
68 | + } | |
69 | + } | |
70 | + | |
71 | + return 0; | |
72 | +} | |
73 | + | |
74 | +int AI_Think_CandidateWordList_Filter02(CHNLIB_UIPArray **candidatewordlist, uint count) | |
75 | +{ | |
76 | + //[UTF-8] | |
77 | + //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。 | |
78 | + //02:count以下の出現回数の単語を削除 | |
79 | + | |
80 | + int i, i_max; | |
81 | + | |
82 | + i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist); | |
83 | + for(i = 0; i < i_max; i++){ | |
84 | + if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) <= count){ | |
85 | + CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i); | |
86 | + i--; | |
87 | + i_max--; | |
88 | + } | |
89 | + } | |
90 | + | |
91 | + return 0; | |
92 | +} |
@@ -0,0 +1 @@ | ||
1 | +[こんにちは][単語,あいさつ] |
@@ -28,6 +28,7 @@ | ||
28 | 28 | #ifdef DEBUG |
29 | 29 | //#define DEBUG_MEMORY_ALLOCATION |
30 | 30 | //#define DEBUG_MEMORY_REFERENCE_COUNT |
31 | +//#define DEBUG_STRING_STRICT | |
31 | 32 | #endif |
32 | 33 | |
33 | 34 | // |
@@ -117,6 +118,7 @@ CHNLIB_UIPArray *CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(const CHNLIB | ||
117 | 118 | typedef struct CHNLIB_STRING CHNLIB_String; |
118 | 119 | struct CHNLIB_STRING; |
119 | 120 | CHNLIB_String *CHNLIB_String_Initialize(const char str[]); |
121 | +CHNLIB_String *CHNLIB_String_InitializeWithFormat(const char format[], ...); | |
120 | 122 | void CHNLIB_String_Free(CHNLIB_String *strtag); |
121 | 123 | int CHNLIB_String_SetStringFromCString(CHNLIB_String *strtag, const char s[]); |
122 | 124 | int CHNLIB_String_Print(CHNLIB_String *strtag); |
@@ -15,6 +15,7 @@ | ||
15 | 15 | #include <stdio.h> |
16 | 16 | #include <stdlib.h> |
17 | 17 | #include <string.h> |
18 | +#include <stdarg.h> | |
18 | 19 | #include "chnlib.h" |
19 | 20 | |
20 | 21 | // |
@@ -62,6 +63,25 @@ CHNLIB_String *CHNLIB_String_Initialize(const char str[]) | ||
62 | 63 | return strtag; |
63 | 64 | } |
64 | 65 | |
66 | +CHNLIB_String *CHNLIB_String_InitializeWithFormat(const char format[], ...) | |
67 | +{ | |
68 | + CHNLIB_String *strtag; | |
69 | + va_list ap; | |
70 | + char str[CHNLIB_MAX_STRING_LENGTH]; | |
71 | + | |
72 | + va_start(ap, format); | |
73 | + vsnprintf(str, sizeof(str), format, ap); | |
74 | + va_end(ap); | |
75 | + | |
76 | + strtag = CHNLIB_String_Internal_Allocate(); | |
77 | + strtag->header.destructor = &CHNLIB_String_Internal_Destruct; | |
78 | + | |
79 | + if(str != NULL){ | |
80 | + CHNLIB_String_SetStringFromCString(strtag, str); | |
81 | + } | |
82 | + return strtag; | |
83 | +} | |
84 | + | |
65 | 85 | void CHNLIB_String_Free(CHNLIB_String *strtag) |
66 | 86 | { |
67 | 87 | //strtagを解放する。 |
@@ -289,10 +309,13 @@ int CHNLIB_CString_CompareString(const char s[], const char search[]) | ||
289 | 309 | //s[]の先頭からsearch[]と比較し、searchの終端まで一致したらTrue, 一致しなかったらFalseを返す。 |
290 | 310 | //終端文字'\0'はカウントしない。 |
291 | 311 | //search[]に含まれる文字(終端文字除く)がすべて入っていれば一致とみなす。 |
312 | + //どちらかがNULLであった場合は、Falseを返す。 | |
292 | 313 | int i; |
293 | 314 | |
294 | 315 | if(s == NULL || search == NULL){ |
316 | +#ifdef DEBUG_STRING_STRICT | |
295 | 317 | CHNLIB_ReportError("Null str.\n", CHNLIB_DEBUG_ARGUMENTS); |
318 | +#endif | |
296 | 319 | return False; |
297 | 320 | } |
298 | 321 |
@@ -54,10 +54,10 @@ void CHNLIB_Environment_SetCurrentWorkingDirectory(const char apppath[]) | ||
54 | 54 | } |
55 | 55 | } |
56 | 56 | path[last + 1] = '\0'; |
57 | - printf("%s\n", path); | |
57 | + //printf("%s\n", path); | |
58 | 58 | chdir(path); |
59 | 59 | getcwd(path, sizeof(path)); |
60 | - printf("%s\n", path); | |
60 | + //printf("%s\n", path); | |
61 | 61 | |
62 | 62 | return; |
63 | 63 | } |
@@ -216,11 +216,15 @@ int CHNLIB_UTF8_GetByteSizeFromLengthByCharacter(const char s[], int start, int | ||
216 | 216 | const char *p; |
217 | 217 | |
218 | 218 | if(s == NULL){ |
219 | +#ifdef DEBUG_STRING_STRICT | |
219 | 220 | CHNLIB_ReportError("Null str.\n", CHNLIB_DEBUG_ARGUMENTS); |
221 | +#endif | |
220 | 222 | return 0; |
221 | 223 | } |
222 | 224 | if(end < start){ |
225 | +#ifdef DEBUG_STRING_STRICT | |
223 | 226 | CHNLIB_ReportError("Invalid index.\n", CHNLIB_DEBUG_ARGUMENTS); |
227 | +#endif | |
224 | 228 | return 0; |
225 | 229 | } |
226 | 230 |