Skip to main content

Terms boolean expressions to query containers

Project description

Boolean Search for Python Containers

Library to make simple boolean queries for python string containers (e.g. sets or lists). E.g. query built from expression 'Alice & Bob & ~John' can be applied to any container to check if it contains strings 'Alice' and 'Bob' and not contains 'John'.

Base example:

#!/usr/bin/env python

from termsquery import TermsQuery

query = TermsQuery('Alice & (Bob | "Unknown user")')

container1 = {'Alice', 'Unknown user'}
container2 = {'Bob'}

assert True == query(container1)
assert False == query(container2)

Library can be used to tag collection of documents: create query for each tag and apply that query for document words.

Simple tagging example:

#!/usr/bin/env python

from termsquery import TermsQuery

tags = {
    'A-not-B' : TermsQuery('A & ~B'),
    'X-and-Y' : TermsQuery('X & Y')
}

docs = [
    'A is the first letter of ...',
    'A and B letters, X and Y letters'
]

for doc in docs:
    words = doc.split()
    doc_tags = [name for (name, query) in tags.items() if query(words)]
    print(doc, doc_tags)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

termsquery-0.2.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file termsquery-0.2.tar.gz.

File metadata

  • Download URL: termsquery-0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for termsquery-0.2.tar.gz
Algorithm Hash digest
SHA256 598bd011d51cf293ee49b5c3049c5797e69b83650272e3579995065b302585f4
MD5 2f45d28c1e0f136f13fddf5685d45b77
BLAKE2b-256 63070d4395cd0ffa2312237cc0ffae654019cabf677d95bcc3021b96f15fb9a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page