When using NLPCraft to develop natural language interface to the existing SQL RDBMS one of the routine tasks is to develop a data model that mirrors the SQL schema for the given database. Doing it manually can be time consuming and error prone.
SQL model generator automates this task. This is a Java-based utility that takes JDBC configuration, reads database schema using it and creates initial JSON or YAML stub for the data model. This stub then can be further extended and modified.
This utility can be run in several ways:
$ bin/nlpcraft.sh gen-sql --url=jdbc:postgresql://localhost:5432/mydb --driver=org.postgresql.Driver --schema=public --out=model.json
bin/nlpcraft.sh help --cmd=gen-sqlto get a full help on this command.
$ java -cp apache-nlpcraft-incubating-0.9.0-all-deps.jar org.apache.nlpcraft.model.tools.sqlgen.NCSqlModelGenerator
org.apache.nlpcraft.model.tools.sqlgen.NCSqlModelGeneratorclass directly to execute it from IDE or programmatically.
After the data model stub is generated:
SQL model generator comes with a several utility classes that can be used to programmatically explore generated data model, its elements and their metadata. You should start with the following builders to learn more about these utility classes:
SQL model generator is used by SQL Model example. This example comes with two YAML models:
sql_model_init.yaml- original generated model straight out of the SQL model generator.
sql_model.yaml- modified and updated model ultimately used by the example.
It is recommended to run a diff between these two files to see what was actually changed and how.