Skip to content

Domain Specific Language (DSL) for query generation

License

Notifications You must be signed in to change notification settings

brianmatute011/kmalsq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KmalSQ

antlr badge version badge test badge release badge

KmalSQ v1

Welcome to KmalSQ v1

KmalSQ is a Generic DSL that allows the generation of queries to multiple search and database engines (See more about the KmalSQ kernel). KmalSQ is part of a research in the field of domain-specific language design (DSL) and its application in the field of information search in search engines and databases. We are open to collaborations and suggestions.

Available Integrations

-[x] Elasticsearch

Integration with ElascticSearch

Using KmalSQ with ElasticSearch

KmalSQ allows the generation of queries for ElasticSearch, below are examples of how KmalSQ can be used to generate queries for ElasticSearch. Currently support for an executor and a query builder is provided to each integrated engine.

From the query builder

package mlix.global;
import mlix.global.build.ElasticSearchKmalBuildQuery;
import org.elasticsearch.index.query.QueryBuilder;

public class App {
    public static void main( String[] args ) {
        ElasticSearchKmalBuildQuery elasticSearchKmalBuildQuery = new ElasticSearchKmalBuildQuery();
        String dslPrompt = "NOT [asin.keyword] == '1234567890';";
        QueryBuilder queryBuilder = elasticSearchKmalBuildQuery.query(dslPrompt);
        System.out.println(queryBuilder.toString());
    }
}

Prompt vs Translation

KmalSQ prompt: [asin.keyword] == '0609804340';
->
{
  "bool" : {
    "must" : [
      {
        "match" : {
          "asin.keyword" : {
            "query" : "0609804340",
            "operator" : "OR",
            "prefix_length" : 0,
            "max_expansions" : 50,
            "fuzzy_transpositions" : true,
            "lenient" : false,
            "zero_terms_query" : "NONE",
            "auto_generate_synonyms_phrase_query" : true,
            "boost" : 1.0
          }
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}
KmalSQ prompt: ([reviews.entries.date] RANGOUT FROM 04/04/2004 TO 05/08/2005 
                    AND [title.keyword] ENDS_WITH 'say') OR  [title.keyword] CONTAINS 'something';
->
{
  "bool" : {
    "should" : [
      {
        "bool" : {
          "must" : [
            {
              "bool" : {
                "must_not" : [
                  {
                    "bool" : {
                      "must" : [
                        {
                          "range" : {
                            "reviews.entries.date" : {
                              "from" : 1081051200000,
                              "to" : 1123300799000,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        }
                      ],
                      "adjust_pure_negative" : true,
                      "boost" : 1.0
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            },
            {
              "bool" : {
                "must" : [
                  {
                    "wildcard" : {
                      "title.keyword" : {
                        "wildcard" : "*say",
                        "boost" : 1.0
                      }
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "must" : [
            {
              "wildcard" : {
                "title.keyword" : {
                  "wildcard" : "*something*",
                  "boost" : 1.0
                }
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}
KmalSQ prompt: NOT ([asin.keyword] == '0786926503' AND NOT ([title.keyword] STARTS_WITH 'The' OR [title.keyword] STARTS_WITH 'B'));
->
{
  "bool" : {
    "must_not" : [
      {
        "bool" : {
          "must" : [
            {
              "bool" : {
                "must" : [
                  {
                    "match" : {
                      "asin.keyword" : {
                        "query" : "0786926503",
                        "operator" : "OR",
                        "prefix_length" : 0,
                        "max_expansions" : 50,
                        "fuzzy_transpositions" : true,
                        "lenient" : false,
                        "zero_terms_query" : "NONE",
                        "auto_generate_synonyms_phrase_query" : true,
                        "boost" : 1.0
                      }
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            },
            {
              "bool" : {
                "must_not" : [
                  {
                    "bool" : {
                      "should" : [
                        {
                          "bool" : {
                            "must" : [
                              {
                                "wildcard" : {
                                  "title.keyword" : {
                                    "wildcard" : "The*",
                                    "boost" : 1.0
                                  }
                                }
                              }
                            ],
                            "adjust_pure_negative" : true,
                            "boost" : 1.0
                          }
                        },
                        {
                          "bool" : {
                            "must" : [
                              {
                                "wildcard" : {
                                  "title.keyword" : {
                                    "wildcard" : "B*",
                                    "boost" : 1.0
                                  }
                                }
                              }
                            ],
                            "adjust_pure_negative" : true,
                            "boost" : 1.0
                          }
                        }
                      ],
                      "adjust_pure_negative" : true,
                      "boost" : 1.0
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}

Releases

No releases published

Packages

No packages published