Nice to know commands
For downloading packs via Git clone
Windows
On Windows (Work in progress)
> cd %LOCALAPPDATA%\swi-prolog\pack
> git clone https://github.com/JanWielemaker/rocksdb.git
> git clone https://github.com/JanWielemaker/rocks-predicates.git
> cd %USERPROFILE%
On Ubuntu
$ sudo apt install libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev libgflags-dev
$ mkdir -p ~/.local/share/swi-prolog/pack
$ cd ~/.local/share/swi-prolog/pack
$ git clone https://github.com/JanWielemaker/rocksdb.git
$ git clone https://github.com/JanWielemaker/rocks-predicates.git
$ cd rocksdb
$ git clone https://github.com/facebook/rocksdb.git
Nice to know queries.
Is the module rocksdb loaded?
?- current_module(rocksdb).
true.
Load the rocksdb module.
?- use_module(library(rocksdb)).
true.
For ther error:
ERROR: rocksdb4pl: cannot open shared object file: No such file or directory
If the RockDB pack was recently installed/built/rebuilt within SWI-Prolog try halt/0 then restart swipl and try the command again, it might resolve the error.
Is the module rocks_preds loaded?
?- current_module(rocks_preds).
true.
Load the rocks_preds module.
Note: This expects the the code to under the pack directory.
Note: You will need to change the user name accordingly.
?- assertz(user:file_search_path(library, '/home/groot/.local/share/swi-prolog/pack/rocks-predicates')).
true.
?- use_module(library(rocks_preds)).
What predicates are in module rocksdb?
?- listing(rocksdb:P).
...
What predicates are in module rocks_preds:P?
?- listing(rocks_preds:P).
...
Is there currently a RocksDB?
?- current_blob(Blob,rocksdb).
Blob = <rocksdb>(0x560f3641a570) ;
false.
Note: More than one RocksDB can be open at a time, e.g.
?- current_blob(Blob,rocksdb).
Blob = <rocksdb>(0x557a667b1960) ;
Blob = <rocksdb>(0x557a66692920) ;
false.
What is the default RocksDB?
Note: Identified by file directory.
?- rocks_preds:default_db(Dir).
Dir = '/mnt/d/...'.
Note: If default_db/1 returns Dir = 'predicates.db'.
then no default RocksDB has been set. This helps to understand error messages like
ERROR: rocksdb `'predicates.db'' does not exist
Note: predicates.db
may actually be created, used and contain data. The parent directory at the time of creation will be the current working directory. So if you load up some data and then it seems to go missing look for the directory name predicates.db
somewhere.
What is SWI-Prolog using for the current working directory?
?- pwd.
% /home/groot/
true.
What predicates exist in the RocksDB?
?- current_table(rocks_preds:H,_),H=rdb_clause_index(_,M:P/I,_).
H = rdb_clause_index(<rocksdb>(0x560f3641a570), umls:mrcol/8, '$VAR'('_')),
M = umls,
P = mrcol,
I = 8 ;
H = rdb_clause_index(<rocksdb>(0x560f3641a570), umls:mrfile/6, '$VAR'('_')),
M = umls,
P = mrfile,
I = 6 ;
H = rdb_clause_index(<rocksdb>(0x560f3641a570), '$VAR'('M'):'$VAR'('P')/'$VAR'('I'), '$VAR'('_')) ;
H = rdb_clause_index(<rocksdb>(0x560f3641a570), '$VAR'('M'):'$VAR'('P')/'$VAR'('I'), '$VAR'('_')) ;
false.
A variation that also reports the predicate with predication.
?- current_table(rocks_preds:H,_),H=rdb_clause_index(_,M:P/I,_),pi_head(M:P/I,Predication).
H = rdb_clause_index(<rocksdb>(0x55dff497bd10), issue_5:fact_01/9, _),
M = issue_5,
P = fact_01,
I = 9,
Predication = issue_5:fact_01(_, _, _, _, _, _, _, _, _) ;
false.
What are the properties for the predicates?
?- rocks_preds:default_db(Dir),rocks_preds:rdb_predicate_property(Dir,umls:mrfile(_,_,_,_,_,_),Property).
Dir = '/mnt/d/...',
Property = database('/mnt/d/...') ;
Dir = '/mnt/d/...',
Property = defined ;
Dir = '/mnt/d/...',
Property = number_of_clauses(100).
?- rocks_preds:default_db(Dir),rocks_preds:rdb_predicate_property(Dir,umls:mrcol(_,_,_,_,_,_,_,_),Property).
Dir = '/mnt/d/...',
Property = database('/mnt/d/...') ;
Dir = '/mnt/d/...',
Property = defined ;
Dir = '/mnt/d/...',
Property = number_of_clauses(329).
A variation using predication; since a predication is a most general query (goal) it can be executed as such.
?- current_table(rocks_preds:H,_),H=rdb_clause_index(_,M:P/I,_),pi_head(M:P/I,Goal),Goal.
H = rdb_clause_index(<rocksdb>(0x55dff497bd10), issue_5:fact_01/9, _),
M = issue_5,
P = fact_01,
I = 9,
Goal = issue_5:fact_01('1', 'Mars 2MV-3 No.1', '04 Nov 1962', '25 Nov 1962', '890', -, -, 'Failed', 'Soviet Union') ;
...
When issue 2 is corrected the need to open the RocksDB and then run queries from the top-level will be desired. As noted the use of break/0 can accomplish this.
interactive :-
absolute_file_name(rocksdb('.'),Rocksdb_directory),
setup_call_cleanup(
rdb_open(Rocksdb_directory,RocksDB),
break,
rdb_close(RocksDB)
).
Example run:
?- interactive.
% Break level 1
[1] ?- mars_lander(Sequence,Lander,Launch_date,Landing_date,Mass_kg,Landing_site,Region,Status,Country_of_origin).
Sequence = '1',
Lander = 'Mars 2MV-3 No.1',
Launch_date = '04 Nov 1962',
Landing_date = '25 Nov 1962',
Mass_kg = '890',
Landing_site = Region, Region = (-),
Status = 'Failed',
Country_of_origin = 'Soviet Union' .
...
Sequence = '21',
Lander = 'Tianwen-1',
Launch_date = '23 July 2020',
Landing_date = '14 May 2021',
Mass_kg = '240',
Landing_site = '109.7°E, 25.1°N',
Region = 'Utopia Planitia',
Status = 'Operational',
Country_of_origin = 'China'.
[1] ?- ^D
% Exit break level 1
true.
?-
Note: ^D
is the visualization of holding down the keyboard key Ctrl
and pressing the key D
.
It should be possible to use initialization/1 (which is only used as a Prolog directive) to open the RocksDB an thus enter top-level with the predicates loaded and use at_halt/1 to close the RocksDB when SWI-Prolog halts; just not high on my priority list at present to work out the details.