32 2 9 B_____ 五,發明說明(1) 本發明係有關於一種資料庫的查詢系統與方法,特別 係有關於_種適用於關聯式資料庫之自然語法檢索系統及 方法。 一般關聯式資料庫係將資料庫中所有的資料都以資料 表格的方式來表示’對關聯式資料庫而言,資料表格係由 資料列與攔位所組成,而所有的資料便都以資料表格的組 成方式來表示。相關的資料表格可組成資料庫,而在關聯 式資料庫中的各資料表格都是各自分開且具有相同地位, 其間並無階層排列的關係。由於關聯式資料庫的此種特 性’要想找到所要的資料,就必須先知道所屬的資料表名 稱與其欄位,還有其資料列的主鍵,或是可辨認出資料列 的攔位組合。此外’還需要使用一種高階語言來對資料庫 裡的資料加以結構化、查詢、及修改等,而雖然理論上所 有的資料庫語言都可以提供上述功能,不過仍是以結構化 查詢語言(SQL,Structured Query Language)最為適用於 關聯式資料庫。 然而,在一般的關聯式資料庫中卻未提供有自然語法 查詢功能’同時也沒有提供中文斷辭辭典管理之功能。欲 對關聯式資料庫進行查詢時,同時必須以輸入關鍵字的方 式進行,以SQL為例,欲進行查詢,則必須在seiect指令 後指定查詢的對象。此種查詢方式,除了不易供_般使用 者使用外,在查詢時也往往因不易界定關鍵字或是查詢範 圍,而使得查詢工作倍增困難。 有鑑於此,為了改進習知關聯式資料庫的問題,本發32 2 9 B_____ V. Description of the invention (1) The present invention relates to a database query system and method, and particularly relates to _ natural grammar retrieval systems and methods suitable for relational databases. A general relational database refers to all the data in the database in the form of data tables. For a relational database, a data table consists of rows and stops, and all data is represented by data. The composition of the table. Related data tables can form a database, and each data table in a relational database is separate and has the same status, and there is no hierarchical relationship between them. Due to this characteristic of the relational database ’, if you want to find the required data, you must first know the name of the data table and its fields, the primary key of its data column, or the combination of discernable data columns. In addition, you need to use a high-level language to structure, query, and modify the data in the database. Although theoretically all database languages can provide the above functions, they are still structured query languages (SQL, Structured Query Language) works best with relational databases. However, the general relational database does not provide the function of natural grammar query 'and it also does not provide the function of Chinese dictionary management. When you want to query the relational database, you must also enter keywords. For example, if you want to query SQL, you must specify the query object after the seiect command. In addition to this query method, it is not easy for ordinary users to use, and it is often difficult to define keywords or query ranges when making queries, which makes the query work more difficult. In view of this, in order to improve the problem of the conventional relational database, the present invention
第5頁 ^ FA 3229 ^ "" _ ___ ____ — 五、發明說明(2) 明之目的即在於提供一種適用於關聯式資料庫之自然語法 檢索系統及方法,其可提供使用者使用自然語法查詢的功 能。 本發明之另一目的在於提供一種適用於關聯式資料庫 之自然語法檢索系統及方法,其可提供資料庫管理者斷辭 辭典管理功能,使得以自然語法輸入的句子斷辭更精確。 為了達到上述目的,本發明提出了一種適用於關聯式 資料庫之自然語法檢索系統,其主要係包括兩個部分,即 使用者使用自然語法查詢部分及斷辭辭典維護部分。 上述使用者使用自然語言查詢部分包含有斷辭辭典、 關聯式資料庫及自然語法查詢工具,可用以在使用者以自 然語法輸入查詢資料後,配合上述斷辭辭典對該查詢資料 進行斷辭’然後再根據斷辭所得到的結果,對上述關聯式 資料庫進行查詢。 上述斷辭辭典維護部分係供維護管理者使用’主要包 括斷辭辭典、關聯式資料庫、初始載入工具及斷辭辭典維 護工具。維護管理者可利用上述初始載入工具將關聯式資 料庫内的資料建入至斷辭辭典中,然後再利用上述斷辭辭 典維護工具調整斷辭辭典的内容,以供斷辭使用。 利用上述本發明之適用於關聯式資料庫之自然語法檢 索系統’使用者可以輕易且精確地查詢到所需要的資訊。 為了進一步說明本發明之架構、方法及特點,茲配合 附圖說明其實施例如下,其中: 第1圖係繪示本發明之適用於關聯式資料庫之自然語Page 5 ^ FA 3229 ^ " " _ ___ ____ — V. Description of the invention (2) The purpose of the invention is to provide a natural grammar retrieval system and method suitable for relational databases, which can provide users with natural grammar Query function. Another object of the present invention is to provide a natural grammar retrieval system and method suitable for a relational database, which can provide a database manager's dictionary management function and make the sentence input in natural grammar more accurate. In order to achieve the above object, the present invention proposes a natural grammar retrieval system suitable for a relational database, which mainly includes two parts, that is, a user uses a natural grammar query part and a segmentation dictionary maintenance part. The above-mentioned user's natural language query part includes a segmentation dictionary, a relational database, and a natural grammar query tool, which can be used to segment the query data in conjunction with the above segmentation dictionary after the user inputs the query data in natural grammar. Then, based on the results obtained from the segmentation, the above relational database is queried. The above-mentioned segmentation dictionary maintenance part is intended for use by maintenance managers', and mainly includes a segmentation dictionary, a relational database, an initial loading tool, and a segmentation dictionary maintenance tool. The maintenance manager can use the initial loading tool to build the data in the relational database into the segmentation dictionary, and then use the segmentation dictionary maintenance tool to adjust the content of the segmentation dictionary for segmentation use. Using the above-mentioned natural grammar retrieval system for a relational database according to the present invention, a user can easily and accurately query the required information. In order to further illustrate the architecture, methods, and features of the present invention, the accompanying drawings are used to illustrate its implementation examples as follows, wherein: FIG. 1 is a diagram illustrating the natural language of the present invention applicable to a relational database
第6頁 ^432298 五、發明說明(3) 法檢索系統的基本架構示意圖。 第2圖係繪示本發明之適用於關聯式資料庫之自然語 法檢索系統的方塊圖。 第3圖係繪示根據本發明之自然語句斷辭處理流程 圖。 第4圖係繪示根據本發明之查詢語辭轉換處理流程 圖。 第5圖係繪示根據本發明之斷辭辭典產生處理流程 圖。 參考標號之說明 1 0使用者使用自然語言查詢部分;1 2、32斷辭辭 典;1 4、30關聯式資料庫;1 6自然語法查詢工具;20 斷辭辭典維護部分;22斷辭辭典載入工具;24 斷辭辭典 維護工具;34自然語句斷辭系統;36 查詢語辭轉換系 統;38 斷辭辭典產生系統;40 查詢工具。 實施例之說明 請參閱第1圖,本發明之適用於關聯式資料庫之自然 語法檢索系統整體的基本架構主要係包括兩個部分,即使 用者使用自然語法查詢部分1 0及斷辭辭典維護部分20。 上述使用者使用自然語言查詢部分1 0包含有斷辭辭典 1 2、關聯式資料庫1 4及自然語法查詢工具1 6,用以在使用 者以自然語法輸入查詢資料後,配合上述斷辭辭典1 2對該 查詢資料進行斷辭,然後再根據斷辭所得到的結果,對上 述關聯式資料庫1 4進行查詢。Page 6 ^ 432298 V. Description of the invention (3) Schematic diagram of the basic structure of the method retrieval system. FIG. 2 is a block diagram illustrating a natural syntax retrieval system suitable for a relational database according to the present invention. Fig. 3 is a flowchart showing a natural sentence segmentation processing process according to the present invention. Fig. 4 is a flowchart showing a query word conversion process according to the present invention. Fig. 5 is a flowchart showing a process of generating a dictionary according to the present invention. Explanation of reference numerals 10 users use natural language query parts; 1, 2, 32 dictionary dictionaries; 1, 4, 30 relational databases; 16 natural grammar query tools; 20 dictionary dictionaries maintenance parts; 22 dictionary dictionaries are contained Input tools; 24 segmentation dictionary maintenance tools; 34 natural sentence segmentation system; 36 query phrase conversion system; 38 segmentation dictionary generation system; 40 query tools. For the description of the embodiment, please refer to FIG. 1. The overall basic structure of the natural grammar retrieval system applicable to the relational database of the present invention mainly includes two parts, namely, the user uses the natural grammar query part 10 and the dictionary maintenance. Section 20. The above-mentioned user uses natural language query part 10 which includes a segmentation dictionary 1 2. a relational database 14 and a natural grammar query tool 16 for matching the above segmentation dictionary after the user inputs query data in natural grammar 12 Perform segmentation on the query data, and then perform a query on the above-mentioned relational database 14 based on the results obtained by the segmentation.
* 4 32 29 3 五、發明說明(4) 上述斷辭辭典維護部分2 0係供維護管理者使用,主要 包括斷辭辭典12、關聯式資料庫14、斷辭辭典載入工具22 及斷辭辭典維護工具24。維護管理者可利用上述斷辭辭典 載入工具22將關聯式資料庫14内的資料建入至斷辭辭典12 中,然後再利用上述斷辭辭典維護工具2 4調整斷辭辭典1 2 的内容,以供斷辭使用。 請參閱第2圖,本發明之適用於關聯式資料庫之自然 語法檢索系統係包括:斷辭辭典32、自然語句斷辭系統 34、查詢語辭轉換系統36、及斷辭辭典產生系統38。 上述斷辭辭典3 2可由上述斷辭辭典產生系統38自動產 生並加以維護,用以提供使用者在輸入自然語法字串時的 查詢之用。 上述自然語句斷辭系統34係用以將使用者以自然語法 輸入的字串斷辭,以找出可用以進行查詢的語句。 上述查詢語辭轉換系統3 6係用以將所得之斷辭語句轉 換成SQL指令,藉以對上述關聯式資料庫30進行查詢。 當使用者透過查詢工具40輸入自然語法之字串時,會 由自然語句斷辭系統34配合斷辭辭典32進行斷辭,然後將 所得到的已斷辭之語句經由查詢語辭轉換系統3 6轉換成 SQL指令,並對關聯式資料庫30進行查詢。 至於斷辭辭典32的產生與維護方面,則係將關聯式資 料庫3 0中各資料表格的資料經由斷辭辭典產生系統3 8載 入,然後建入至斷辭辭典32中。 請參閱第3圖,上述自然語句斷辭系統34的運作方法* 4 32 29 3 V. Description of the invention (4) The above-mentioned segmentation dictionary maintenance part 20 is used by maintenance managers, mainly including the segmentation dictionary 12, the relational database 14, the segmentation dictionary loading tool 22, and the segmentation Dictionary maintenance tool 24. The maintenance manager can use the above-mentioned broken-word dictionary loading tool 22 to build the data in the relational database 14 into the broken-word dictionary 12, and then use the above-mentioned broken-word dictionary maintenance tool 2 4 to adjust the content of the broken-word dictionary 1 2 For use in excerpts. Referring to FIG. 2, the natural grammar retrieval system of the present invention applicable to a relational database includes: a segmentation dictionary 32, a natural phrase segmentation system 34, a query phrase conversion system 36, and a segmentation dictionary generation system 38. The above-mentioned segmentation dictionary 32 can be automatically generated and maintained by the above-mentioned segmentation dictionary generating system 38, so as to provide a user with a query when inputting a natural grammar string. The above-mentioned natural sentence segmentation system 34 is used to segment a string input by a user in natural grammar to find a sentence that can be used for query. The query word conversion system 36 is used to convert the obtained phrase into a SQL command, so as to query the relational database 30. When a user inputs a natural grammar string through the query tool 40, the natural sentence segmentation system 34 cooperates with the segmentation dictionary 32 to perform segmentation, and then the obtained segmented phrase is passed through the query segment conversion system 3 6 It is converted into SQL commands, and the relational database 30 is queried. As for the generation and maintenance of the segmentation dictionary 32, the data of each data table in the relational database 30 is loaded into the segmentation dictionary generation system 38 and then built into the segmentation dictionary 32. Please refer to FIG. 3, the operation method of the above-mentioned natural sentence segmentation system 34
r P432 29 8_ 五、發明說明(5) 主要係包括下列步驟:(i)步驟100,由使用者輸入字串; (ii)步驟102,倒轉字串處理;(iii)步驟104,判斷字串 是否結束,若是則進行步驟11 8,否則進行下一步驟; (iv)步驟106,判斷在斷辭辭典中是否存在第一字,若是 則進行下一步驟,否則進行步驟11 4 ;(v )步騍1 0 8,記錄 語辭;(v i)步驟11 0,判斷下一字是否為連續辭,若是則 進行步驟116,否則進行下一步驟;(vii)步驟112,寫入 分隔字元;(viii)步驟114,寫入分隔字元繼續下一字; (i X)步驟11 6,繼續下一字;(X)步驟11 8,倒轉語辭字 串,然後結束。 請參閱第4圖,上述查詢語辭轉換系統36的運作方法 係包括下列步驟:(i)步驟200,產生已斷辭之語句;(ii) 步驟202,查詢辭典;(i i i )步驟204,判斷是否結束,若 是則結束,否則進行下一步驟;(i v )步驟2 0 6,記錄語辭 之關聯式資料庫屬性;(v)步驟208,寫入SQL,然後繼續 下一辭,回到步驟202。 請參閱第5圖,上述斷辭辭典產生系統38的運作方法 係包括下列步驟:(i )步驟3 0 0,讀取關聯式資料庫結構; (i i )步驟302,判斷是否已無欄位,若是則結束流程,否 則進行下一步驟;(i i i)步驟3 0 4,將欄位名稱及屬性倒轉 建入斷辭辭典;(iv)步驟306,讀取欄位資料;(v)步驟 308,判斷是否已無下一筆資料,若是則進行步驟312,否 則進行下一步驟;(v i )步驟3 1 0,將資料斷辭並將相關屬 性寫入斷辭辭典,然後回到步驟3 0 8 ;(v i i)步驟3 1 2,繼r P432 29 8_ 5. Description of the invention (5) It mainly includes the following steps: (i) step 100, where the user enters the string; (ii) step 102, which reverses the string processing; (iii) step 104, which determines the string Whether to end, if yes, go to step 11 8; otherwise, go to the next step; (iv) step 106, determine whether the first word exists in the segmentation dictionary, if yes, go to the next step, otherwise go to step 11 4; (v) Step 108, record the words; (vi) Step 110, determine whether the next word is a continuous word, if it is, go to Step 116, otherwise go to the next step; (vii) Step 112, write the separated characters; (Viii) Step 114, write the separated characters to continue the next word; (i X) Step 116, continue to the next word; (X) Step 118, reverse the word string, and then end. Please refer to FIG. 4. The operation method of the query language conversion system 36 includes the following steps: (i) step 200 to generate a segmented sentence; (ii) step 202 to query a dictionary; (iii) step 204 to determine Whether to end, if yes, end, otherwise proceed to the next step; (iv) step 206, record the related database attributes of the lexicon; (v) step 208, write SQL, then continue to the next lexicon, return to step 202. Please refer to FIG. 5. The operation method of the above-mentioned segmentation dictionary generating system 38 includes the following steps: (i) step 300, reading the relational database structure; (ii) step 302, determining whether there is no column, If it is, then end the process, otherwise proceed to the next step; (iii) step 304, invert the field name and attributes into the broken dictionary; (iv) step 306, read the field data; (v) step 308, Determine whether there is no next item of data, if yes, go to step 312, otherwise proceed to the next step; (vi) step 3 1 0, the data is segmented and related attributes are written into the segmentation dictionary, and then return to step 3 0 8; (vii) Step 3 1 2 followed by
r F4 32 29 8_ 五、發明說明(6) 續下一攔位,回到步驟302。 接下來,再以一實例說明本發明,有關使用者維護斷 辭辭典資料的方式,首先是利用斷辭辭典載入工具將關聯 式資料庫中的資料建立至斷辭辭典中,例如,關聯式資料 庫中有一表格(table)為研究報告,定義為作者、著作名 稱及内容三個欄位,而在資料庫中存有一筆資料為 作者:孫璐西 著作名稱:吃檳榔之研究 内容:吃檳榔與身體健康 則維護管理者利用斷辭辭典載入工具將關聯式資料庫 中的資料建入斷辭辭典後,斷辭辭典内即具有下列資料: 孫璐西:名詞 資料庫:研究報告 欄位:作者 檳榔:名詞 資料庫:研究報告 欄位:内容、著作 健康:名詞 資料庫:研究報告 攔位:内容 著作名稱:名詞 資料庫:研究報告 攔位:著作名稱 維護管理者也可利用斷辭辭典維護工具調整斷辭辭典r F4 32 29 8_ V. Description of the invention (6) Continue to the next stop and return to step 302. Next, an example is used to illustrate the present invention. As for the way for users to maintain the dictionary data, first use the dictionary load tool to build the data in the relational database into the dictionary, for example, the relational database has a table (table) for the study, is defined as the author, book name and the contents of three fields, but there piece of data in the database author: Sun Luxi book name: eat study betel nut of content: betel nuts and For health, the maintenance manager uses the broken dictionary dictionary loading tool to build the data in the relational database into the broken dictionary. The broken dictionary has the following information: Sun Luxi: Noun database: Research report field: Author Areca : Nomenclature Database: Research Report Field: Content, Work Health: Nomenclature Database: Research Report Stop: Content Book Name: Noun Database: Research Report Stop: Author Name Maintenance Manager can also use the dictionary maintenance tool Adjusted Dictionary
第10頁 f4 32 29 8 五、發明說明(7) 中辭的内容,舉例而言,對於上述有關「著作名稱」的資 料,可調整為 著作:名詞 資料庫:研究報告 攔位名:著作名稱 然後,再將上述資料建入至斷辭辭典中,以提供斷辭 使用。 當使用者利用自然語法查詢關聯式資料庫時,假設使 用者使用自然語法輸入查詢條件為「孫璐西有關檳榔與健 康的著作」。則經本發明之系統斷辭並找出屬性後,會得 到下列資料: 孫璐西:名詞 資料庫:研究報告 欄位:作者 檳榔:名詞 資料庫:研究報告 襴位:内容、著作名稱 健康:名詞 資料庫:研究報告 欄位:内容、著作名稱 著作:名詞 資料庫:研究報告 攔位:著作名稱 然後,本發明之檢索系統會將上述資料轉換成SQL如Page 10 f4 32 29 8 V. Description of the invention (7) The content of the diction in (7), for example, the above-mentioned data on "titles of works" can be adjusted to works: noun database: research report stop name: title of work Then, the above information is built into the dictionary of lexicons to provide lexicon use. When the user uses natural grammar to query the relational database, it is assumed that the user uses natural grammar to enter the query condition as "Sun Luxi's work on betel nut and health". After the system according to the present invention breaks down the words and finds the attributes, the following information will be obtained: Sun Luxi: Noun database: Research report field: Author Betel nut: Noun database: Research report niches: Content, work name health: Noun database : Research report field: content, title of work, works: noun database: research report stop: title of work, then the retrieval system of the present invention will convert the above data into SQL such as
五、發明說明(8) 下: SELECT 著作 FROM研究報告 WHERE作者=孫璐西 接著’利用上述SQL杳、M(檳榔,健康) 結果回覆使用者。 關聯式資料庫後’再將查詢 的各本:月5適用於關聯式資料庫之自然語法檢索系統中 : = 電腦中之處理器及記憶禮等裝置,配合 上述各系統的運作流程加以實 利用上述本發明之% + 料座之έ缺往、t 檢索系統’可提供適用於關聯式資 ^ ^ ^ 3® i ll文斷辭辭典的管理功能,使關聯式資料 的育料及資料推述均可記錄於斷辭辭典中。再 处"提供自然語法斷辭及轉換為結構化查詢語言(SQL) 功能’使關聯式資料庫可使用自然語法進行查詢,滿足使 用者查詢的需求。本發明之適用於關聯式資料庫之自然語 法檢索系統更可針對不同的資料庫,使用相同或不同的斷 辭辭典,以做為配合文字斷辭使用,使查詢結果更加精 確〇V. Description of the invention (8) Next: SELECT works FROM research report WHERE author = Sun Luxi Then ’use the above SQL 杳, M (betel nut, health) results to reply to the user. After the relational database, the query books will be used again: Month 5 is applicable to the natural grammar retrieval system of the relational database: = The processor and memory device in the computer, which are used in conjunction with the operation processes of the above systems The above-mentioned% + material base of the present invention, the t-retrieval system 'can provide management functions applicable to the relational resources ^ ^ ^ 3 ® i ll dictionary, so that both the breeding of the relational materials and the data deduction It can be recorded in the dictionary. In addition, "quoting of natural grammar and conversion to structured query language (SQL) 'is provided to enable relational databases to query using natural grammar to meet the query needs of users. The natural grammar retrieval system of the present invention applicable to a relational database can also use the same or different dictionary for different databases, and use it as a combination of word segmentation to make the query result more accurate.