Discussions
Categories
- 17.9K All Categories
- 3.4K Industry Applications
- 3.3K Intelligent Advisor
- 62 Insurance
- 536K On-Premises Infrastructure
- 138.2K Analytics Software
- 38.6K Application Development Software
- 5.7K Cloud Platform
- 109.4K Database Software
- 17.5K Enterprise Manager
- 8.8K Hardware
- 71.1K Infrastructure Software
- 105.2K Integration
- 41.5K Security Software
Exporting/Importing a user-made thesaurus into the Knowledge Base
Hi,
I am working with Oracle Text on RDBMS 11g and 12c.
The Oracle documentation states that one can augment the existing Knowledge Base with your custom thesaurus using PL/SQL:
https://docs.oracle.com/database/121/CCAPP/GUID-63336C63-95D9-45FB-8824-A166A44E1370.htm#CCAPP9343
But how to instruct the engine that it has to be loaded in the Knowledge Base?
Or retrieved from, in the case of an export to CLOB?
Kind Regards
Answers
-
The following example loads a thesaurus named mythesaurus into the knowledge base. Although the mythesaurus can be created using pl/sql, it must be added to the knowledge base from the operating system or from sql*plus using the host command or by other roundabout means, such as scheduling an external job, but not directly from pl/sql.
C:\app\baboehme\product\12.1.0\dbhome_2\BIN>ctxkbtc -user ctxsys/[email protected] -name mythesaurus
Oracle Text knowledge base extension: thesaurus compiler
Connecting...
Deleting old extended knowledge base.
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\drelsUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\dreldUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\dreliUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\drelkUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\drefdUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\drefiUS.dat
Processing thesaurus: MYTHESAURUS
Processed 2 terms.
Done processing thesaurus: MYTHESAURUS
Compiling and writing new flat files.
Writing extended knowledge base to files.
.............................................
.......................................................................................................................
Oracle Text knowledge base successfully extended.
DisconnectedC:\app\baboehme\product\12.1.0\dbhome_2\BIN>
-
Hi,
If I am not mistaken, To load and merge a thesaurus in the Klnowledge Base is done in two steps (assuming we have it in an OS file mythesaurus.dat):
1) We load the thesaurus "mythesaurus":
ctxload -thes -thescase y -name mythesaurus -file mythesaurus.dat -user ctxsys/[email protected]
2) We compile or re-compile the thesaurus "mythesaurus" to the Knowledge Base (what you posted):
ctxkbtc -user ctxsys/[email protected] -name mythesaurus
In your example, where do you instruct ctxkbtc to find the *.dat thesaurus file?
What if we want to "unload" that thesaurus and remove it from the Klnowledge Base.
Kind Regards
-
Use the -revert argument to ctxkbtc to revert back to the default knowledgebase as shipped.
Thesaurus file must be in the local client directory where you run ctxload.
-
Hi Roger,
Thanks for the quick answer.
So, if I well understand, the *.dat thesaurus file must be located on the client directory where I run ctxload.
But, I do understand I neded to perform both stepsm 1) and 2), correct?
By doing the revert as you suggested, it means that I bo back to the previous version of the Knowledge Base (that might contain other customized thesaurus).
How can I extract (as a *.dat file) the current Knowledge Base (that might contain other customized thesaurus)>
Kind Regards
-
Laury wrote:Hi,If I am not mistaken, To load and merge a thesaurus in the Klnowledge Base is done in two steps (assuming we have it in an OS file mythesaurus.dat):1) We load the thesaurus "mythesaurus":ctxload -thes -thescase y -name mythesaurus -file mythesaurus.dat -user ctxsys/[email protected]) We compile or re-compile the thesaurus "mythesaurus" to the Knowledge Base (what you posted):ctxkbtc -user ctxsys/[email protected] -name mythesaurusIn your example, where do you instruct ctxkbtc to find the *.dat thesaurus file?What if we want to "unload" that thesaurus and remove it from the Klnowledge Base
You do not specify the file name when using ctxkbtc, just the thesaurus name. Please see the following link for ctxkbtc syntax:
https://docs.oracle.com/database/122/CCREF/oracle-text-utilities.htm#CCREF2191
-
Laury wrote:Hi Roger,Thanks for the quick answer.So, if I well understand, the *.dat thesaurus file must be located on the client directory where I run ctxload.But, I do understand I neded to perform both stepsm 1) and 2), correct?By doing the revert as you suggested, it means that I bo back to the previous version of the Knowledge Base (that might contain other customized thesaurus).How can I extract (as a *.dat file) the current Knowledge Base (that might contain other customized thesaurus)>Kind Regards
Please click on the link below for instructions for ctx_thes.export_thesaurus.
-
Hi,
Still I do not understand the procedure to load (and possibly unloador remove) a user-made thesaurus inside the Knowledge Base.
Suppose I have this file, mythesaurus-file.dat (that I just took from the documentation), with this content:
cat
SYN feline
NT domestic cat
NT wild cat
BT mammal
mammal
BT animal
domestic cat
NT Persian cat
NT Siamese cat
wild cat
NT tiger
tiger
NT Bengal tiger
dog
BT mammal
NT domestic dog
NT wild dog
SYN canine
domestic dog
NT German Shepard
wild dog
NT Dingo
I want add it to the Knowledge Base. I proceed the following way:
1) Load the thesaurus "mythesaurus":
ctxload -thes -thescase y -name mythesaurus -file mythesaurus-file.dat -user ctxsys/[email protected]
2) I compile or re-compile the thesaurus "mythesaurus" to the Knowledge Base (what you posted):
ctxkbtc -user ctxsys/[email protected] -name mythesaurus
Yes, I can use ctx_the.export_thesaurus if I want to export the thesaurus "mythesaurus".
But what if I want to export the whole Knowledge Base?
Kind Regards
-
Laury wrote:Hi,Still I do not understand the procedure to load (and possibly unloador remove) a user-made thesaurus inside the Knowledge Base.Suppose I have this file, mythesaurus-file.dat (that I just took from the documentation), with this content:cat SYN feline NT domestic cat NT wild cat BT mammalmammal BT animaldomestic cat NT Persian cat NT Siamese catwild cat NT tigertiger NT Bengal tigerdog BT mammal NT domestic dog NT wild dog SYN caninedomestic dog NT German Shepardwild dog NT DingoI want add it to the Knowledge Base. I proceed the following way:1) Load the thesaurus "mythesaurus":ctxload -thes -thescase y -name mythesaurus -file mythesaurus-file.dat -user ctxsys/[email protected]) I compile or re-compile the thesaurus "mythesaurus" to the Knowledge Base (what you posted):ctxkbtc -user ctxsys/[email protected] -name mythesaurusYes, I can use ctx_the.export_thesaurus if I want to export the thesaurus "mythesaurus".But what if I want to export the whole Knowledge Base?Kind Regards
Oracle supplies a file dr0thsus.txt that you load using ctxload to create the default thesaurus. Then you use ctxkbtc to create the initial knowledge base from that default thesaurus. Whatever you use as an initial thesaurus to create the initial knowledge base must be named default. You can then add other user-defined thesauri as you wish with whatever names you wish, loading them from files using ctxload, then adding them to the knowledge base using ctxkbtc. Each thesaurus can be exported separately, whether it is in the knowledge base or not. You can export the default thesaurus in the same manner that you export any other thesaurus.
I copied what you posted into a file named mythesaurus-file.dat on my system in my operating system directory c:\my_oracle_files. In the following example, which I ran from SQL*Plus, as user ctxsys, I loaded that file to a thesaurus named my thesaurus, then added it to the knowledge base, which already has the previously loaded default thesaurus. I then exported the thesaurus named mythesaurus to a file named mythesdump.dat and exported the default thesaurus to a file named defaultthesdump.dat. Please read the comment lines carefully as they contain additional information. Note that your ctxsys password and database name and directory names will be different on your system.
-- load the user-defined thesaurus named mythesaurus from the file mythesaurus-file.dat in the operating system directory c:\my_oracle_files:
[email protected]_12.1.0.2.0> host ctxload -thes -thescase y -name mythesaurus -file c:\my_oracle_files\mythesaurus-file.dat -user ctxsys/[email protected]
Connecting...
Creating thesaurus mythesaurus...
Thesaurus mythesaurus created...
Processing...
23 lines processed successfully
Beginning insert...23 lines inserted successfully
Disconnected
-- add the user-defined thesaurus named mythesaurus to the knowledge base:
[email protected]_12.1.0.2.0> host ctxkbtc -user ctxsys/[email protected] -name mythesaurus
Oracle Text knowledge base extension: thesaurus compiler
Connecting...
Deleting old extended knowledge base.
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\drelsUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\dreldUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\dreliUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\drelkUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\drefdUS.dat
Deleting C:\app\baboehme\product\12.1.0\dbhome_2\ctx\data\enlx\drefiUS.dat
Processing thesaurus: MYTHESAURUS
Processed 22 terms.
Done processing thesaurus: MYTHESAURUS
Compiling and writing new flat files.
Writing extended knowledge base to files.
.............................................
.......................................................................................................................
Oracle Text knowledge base successfully extended.
-- create an oracle directory object named THESDIR that maps to the operating system directory you want to export to (c:\my_oracle_files in this example):
[email protected]_12.1.0.2.0> create or replace directory THESDIR as 'c:\my_oracle_files'
2 /Directory created.
-- export the thesaurus named mythesaurus to a clob and write the clob to a file named mythesdump.dat and
-- export the default thesaurus to a clob and write the clob to a file named defaultthesdump.dat
-- into the operating system directory c:\my_oracle_files mapped to the oracle directory object THESDIR (must be in capital letters):
[email protected]_12.1.0.2.0> declare
2 mythesdump clob;
3 begin
4 ctx_thes.export_thesaurus ('mythesaurus', mythesdump);
5 dbms_xslprocessor.clob2file (mythesdump, 'THESDIR', 'mythesdump.dat');
6 ctx_thes.export_thesaurus ('default', mythesdump);
7 dbms_xslprocessor.clob2file (mythesdump, 'THESDIR', 'defaultthesdump.dat');
8 end;
9 /PL/SQL procedure successfully completed.
-
Just to try to clarify things a bit more, exporting and removing are not the same things and I am not sure which you want to do. Exporting just writes the thesaurus data to a clob which can be written to a file if you like, but leaves the thesaurus in the knowledge base. Running ctxkbtc using -revert removes all user-defined thesauri from the knowledge base, leaving only the default thesaurus. You can then use ctx_thes to also remove the user-defined thesauri and/or default thesaurus from the database, if you like. That still leaves the original files intact, so that you can reload from them if you like. You can also, of course, delete those files from your operating system, if you like.
-
There is no mechanism for exporting the knowledgebase itself, only to export a thesaurus. The initial knowledgebase is supplied as a binary file, not a user-readable thesaurus, and cannot be directly accessed or read by the user.