Giter Site home page Giter Site logo

tagexp's Introduction

Overview

Tagexp is a very simple utility library (a single class, really) that can be used to evaluate tag expressions on a collection of strings. For example, suppose that you have a collection of documents where each has a set of tags associated with it. A document about Minnesota sports, for example, might be tagged with, "Minnesota", "Sports", "Vikings", and "Twins", among others.

Now, suppose that you want to make complex search available to your end users and create queries like, "find all documents that include the terms 'Minnesota' and 'Vikings', but not 'Sports'." The Tagexp library makes this possible by evaluating the truth value of such queries against collections of tag strings.

Usage

Suppose that the document mentioned above has its tags stored in a Java Set called, tags. We can run the following query against it to determine if it includes the tags 'Minnesota' and 'Vikings' but not 'Sports':

Evaluator eval = new Evaluator();	// Get an Evaluator instance
boolean isAboutHistoricalVikings = eval.evaluate("(Minnesota and Vikings) and not Sports", tags);

The Evaluator class supports the following operators. Note that these are case-sensitive:

  • and - Logical AND.
  • or - Logical OR.
  • not - Logical NOT. The "-" character also functions as a logical NOT.
  • xor - Logical XOR.

Sub-expressions can be grouped using parentheses. All other strings are treated as individual tags. Note that if multiple tags are separated by spaces in an expression, they are treated as if they had an AND operator between them.

By default, tag searches are case-sensitive. Setting the 'caseSensitive' parameter on the evaluate() method to false will cause searching to be case-insensitive. Note that doing so may reduce the performance of the evaluation.

Building

Gradle is used to build the Tagexp JAR:

./gradlew build

Dependencies

In order to use Tagexp in another program or build, the ANLTR 3 JAR will need to be included on the classpath. To add this JAR to a Gradle build from Maven Central, simply include the following dependency in your build script:

compile 'org.antlr:antlr:3.5.2'

tagexp's People

Contributors

upcrob avatar

Watchers

 avatar  avatar

tagexp's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.