Natural Language Query for .NET search-like interface in C#


features natural language interface c# library

  • pure C# rule-based NLP NER library for .NET
  • fast and efficient rule-based named entity recognition engine: parses natural language query, performs matching and generates top-combinations in milliseconds.
  • implements basic set of matchers for handling typical search queries
  • handles relative date phrases like "yesterday", "last week", "last month", "last year", conditions "between", "more than", "less than", "age>18", ranges like "before", "after".
  • supports matching in external indexes (like Lucene).
  • synonyms for better recognition results and ontology matching.
  • easy-to-use: includes a component that automatically configures recognizer by data table description.
  • helps users to form a query with autocomplete suggestions
  • OPEN SOURCE and FREE for usage in non-SaaS apps that have only one single-server production deployment

download and pricing

NReco.NLQuery provides simple way to add search-based interface into your .NET business application. It was specially designed for matching business entities in context of structured data (tabular data or database, OLAP cube, text indexes).

Library is useful for: keyword-based filters for lists/grids, custom semantic search by database(s), search-driven analytics (reports by search), parse incoming messages by bots.

how to use

  1. Install NReco.NLQuery nuget package
  2. Configure a recognition engine (C#):
    var tblMatchBuilder = new TableMatcherBuilder();
    tblMatchBuilder.Add(tasksTableSchema);
    var recognizer = new Recognizer(tblMatchBuilder.Build());
    
  3. Parse user's search query:
    var tokens = new Tokenizer().Parse("John closed tasks");
    var searchQuery = new TokenSequence(tokens.ToArray());
    recognizer.Recognize(searchQuery, matchesCombinationHandler);
    
  4. In matchesCombinationHandler choose best recognition with your scoring function and translate matches to formal query like SQL.
  5. Next steps:
Have a question? Feel free to ask.

online demo & examples

  1. NLQuery Demo: Search-based Filter for Data List
    • illustrates how to configure recognizers by data table schema
    • scoring function for best matches
    • generates SQL WHERE by recognition results
    • useful for adding user-friendly filter to the data lists or grids
    • source code for this demo: NliDataFilter
  2. NLQuery Example: Search-Driven Reports Builder
    • illustrates how to configure recognizers by PivotData object
    • scoring function for best pivot table configuration
    • generates PivotData SliceQuery by recognition results
    • result is a PivotTable object that can be used for rendering crosstab report or pivot chart
    • source code for this demo: NliPivotTable

frequently asked questions

Traditional NL statistical parsers (like Apache OpenNLP) are good in processing unstructured natural language text but not so good when used for natural language interfaces (NLI). Main reasons are:
  • in most cases natural language interfaces don't receive complete (and correct) natural language sentences: good examples are google search queries. NLI input is actually a set of interconnected keywords and phrases; words meaning may be very specific to the context of the search query.
  • statistical parsers require training on a massive corpus of questions (queries) and desired recognition, and manual creation of such corpus for each database usually is unacceptable for number of reasons; this might be not possible at all if database content is unique for each user (for instance, in SaaS applications).
  • when a database is changed, results may become unreliable without additional re-training. It's hard to incorporate special hints and formal expressions (say, field conditions) that are very desirable for NLI in the business applications.

NLQuery was specially designed for processing natural language queries in the context of tabular data (like database). It aims to be database-independent NLI that doesn't require any training; internally NLQuery mixes formal rule-based approach for named entity recognition by ontology information (database schema, unique values) with probability approach for getting the best formal result that matches a search query.
NLQuery library (NReco.NLQuery.dll) can be used for FREE in non-SaaS apps that have only one single-server production deployment (free license text).

A commercial license is required for multiple deployments, redistribution as part of your product, or usage in SaaS app.

what's new

2024 Aug 20 v.1.2.1 release:
  • TableMatcherBuilder: fixed an issue when default date column is assigned to DateMatch with MatchedTokensCount=0.
  • TableMatcherBuilder: fixed an issue when default date column is not assigned because of 'weak' hint-match of column with DataType=Unknown
2024 Aug 05 v.1.2.0 release:
  • Boost words now implemented using MergePhraseMatcher and can be used/handled consistently in TableMatcherBuilder.
  • Now words stemming is handled inside LikePhraseMatcher and ListContainsMatcher which gives more accurate recognition.
  • ComparisonMatcher: now can skip stop words + reverse order handling: OP_MATCH VALUE ENTITY (example: "more than 5 items")
  • Match added MatchedTokensCount property (needed for relevant scoring function when MergePhraseMatcher is used).
  • HintMatcher: now supports reverse-order like VALUE HINT-MATCH
  • Tokenizer: added '#', '^' as math-chars, single-quote as punctuation, and any valid unicode white-space works as a separator.
2022 Aug 29 v.1.1.1 release:
  • NReco.NLQuery goes open source: https://github.com/nreco/nlquery
  • Now free usage is allowed under certain limitations (non-SaaS apps with only one single-server prod deployment).
  • A license key is accepted & verified but all 'trial' restrictions are removed
2019 Oct 23 v.1.1 release:
  • added support of synonyms (TableSchema/TableMatcherBuilder)
  • added ComparisonMatcher for patterns like "age > 20", "temp above 30" etc
  • added GroupMatcher for matches combined with "and"/"or"
  • options for TableMatcherBuilder to control comparison/group matching
  • handle pharse in double-quotes as single token (Tokenizer)
2018 Mar 19 v.1.0 release:
  • totally redeveloped engine (API is changed): more efficient and highly extensible in comparing to beta1, supports custom external matchers (for example, Lucene index)
  • full set of generic matchers: Number, Date, DateOffset, ExactPhrase, LikePhrase, ListContains, Hint, MergePhrase
  • efficient greedy algorithm for matches combinations generation
  • TableMatcherBuilder that signficantly simplifies library usage for recognition in context of tabular data. It is enough to provide data table schema and builder will configure all needed matchers automatically.
2016 Sep 02 Added advanced example NliDataFilter: generates SQL where condition by search query.
2016 Apr 28 Added advanced example NliDataFilter: generates SQL where condition by search query.
2016 Apr 19 v.1.0-beta1 (first public version):
  • Implements tokenizer and basic matchers (date, relative date, list-contains).
  • Example that recognizes films by MovieLens dataset.

more components

  • PivotData Toolkit for .NET

    .NET components for manipulating multidimensional dataset (in-memory data cube) without OLAP server, aggregating huge datasets, calculating data for pivot tables / charts, web pivot table control for ASP.NET MVC/Blazor.

  • Recommendation Engine

    Fast collaborative filtering engine that takes users' behaviour and from that tries to find items users might like.