Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4094918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:48:53+00:00 2026-05-20T19:48:53+00:00

I have a corpus of token-index based documents which offers a query method. The

  • 0

I have a corpus of token-index based documents which offers a query method. The user manually(!) enters a query string which needs to be parsed and evaluated. The corpus should then return a list of all documents matching the given query string. The query language features the simple boolean operators AND, NOT and OR which can also be prioritized by parenthesis.
After some research I already used ANTLR to parse a given query string into a syntax tree.

For example: The query

"Bill OR (John AND Jim) OR (NOT Simon AND Mike)"

is translated in the following syntax tree:

EDIT: Please see the correct graph in Bart Kiers post (copied here):

enter image description here

All nodes in the tree are simple strings and each node knows its parent and children but not its siblings.
As you can see, the ANTLR grammar already dictated the order in which the operations need to be executed: the ones at the bottom of the tree come first.

So what I probably need to do is recusively(?) evaluate all operands in the tree.
In general, I can do a simple search on my corpus using a method Get(string term) for each leaf in the tree (like “Bill” or “John”). Get() returns a list of documents containing the term in the leaf. I can also evaluate the parent of each leaf to recognize a possible NOT operator which would then lead to a result list of documents NOT containing the term in the leaf (using the method Not() instead of Get()).

The AND and OR operator should be transformed into method calls which need two parameters:

  • AND should call a method Intersect(list1, list2) which returns a list of documents that are in list1 AND in list2.
  • OR should call a method Union(list1, list2) which returns a list of documents that are either in list1 OR in list2.

The parameters list1 and list2 contain the documents I received before using Get() or Not().

My question is: How can I – semantically and syntactically in C# – evaluate all necessary search terms and use them to call the right operator methods in the correct order? Intuitively it sounds like recursion but somehow I can’t picture it – especially since not all methods that need to be called have the same amount of parameters. Or are there maybe entirely other ways to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:48:54+00:00Added an answer on May 20, 2026 at 7:48 pm

    In Pseudo Code

    Set Eval (Tree t) {
    
        switch (t.Operator) {
            case OR:
                 Set result = emptySet;
                 foreach(child in T.Children) {
                     result = Union(result, Eval(child));
                 }
                 return result;
            case AND:
                 Set result = UniversalSet;
                 foreach(child in T.Children) {
                     result = Intersection(result, Eval(child));
                 }
                 return result;
            case blah: // Whatever.
        }
        // Unreachable.
    }
    

    Does that help?

    Or were you looking to optimize the order of evaluations, which probably has books written on it…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather large text corpus, of which I would like to check
I have an index from a large corpus with several fields. Only one these
I have a string which contains XML. I want to create an XMLdocument from
I have corpus of several hundred of documents and I am using NLTK PlaintextCorpusReader
I have a corpus of documents and I want to represent each document as
I have a human tagged corpus of over 5000 subject indexed documents in XML.
Which open-source package is the best for clustering a large corpus of documents? It
I have a large corpus of text (10 million sentences or so) which I'd
I have a Lucene indexed corpus of more than 1 million documents. I am
I have a fairly small corpus of structured records sitting in a database. Given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.