Entity Query Language#
Welcome to the Entity Query Language package!
EQL is a relational query language that is pythonic, and intuitive.
The interface side of EQL is inspired by euROBIN entity query language white paper.
Installation#
pip install entity_query_language
If you want to use the visualization feature, you will also need to install rustworkx_utils.
pip install rustworkx_utils
Example Usage#
Basic Example#
An important feature of EQL is that you do not need to do operations like JOIN in SQL, this is performed implicitly. EQL tries to mirror your intent in a query statement with as less boiler plate code as possiple. For example an attribute access with and equal check to another value is just how you expect:
from dataclasses import dataclass
from typing_extensions import List
from entity_query_language import entity, an, let, contains, symbolic_mode, symbol
@symbol
@dataclass
class Body:
name: str
@dataclass
class World:
id_: int
bodies: List[Body]
world = World(1, [Body("Body1"), Body("Body2")])
with symbolic_mode():
body = let(type_=Body, domain=world.bodies)
query = an(entity(body, contains(body.name, "2"),
body.name.startswith("Body"))
)
results = list(query.evaluate())
assert len(results) == 1
assert results[0].name == "Body2"
where this creates a body variable that gets its values from world.bodies, and filters them to have their att “name” equal to “Body1”.ample shows generic usage of the Ripple Down Rules to classify objects in a propositional setting.
Notice that it is possible to use both provided helper methods by EQL and other methods that are accessible through your object instance and use them as part of the query conditions.
More Example Usage#
Example with
the
: This example shows how to usethe
entity wrapper instead ofan
.Example with
And
+OR
: This shows an example of usingAnd
withOr
together.Example with
Not
: This shows an example of usingNot
.Example with Joining Multiple Sources: This shows an example of using and joining multiple sources in your query.
Example with Nested Queries: This shows how to compose queries by nesting queries inside others.
Example with Rule Inference: This shows an example of writing inference rules in EQL.
Example with Rule Tree: This shows how to build and visualize a rule tree.
Example with Predicates: This shows how to write and use reusable predicates in queries.
Example with Predicate Style Query/Rule: This shows queries and rules written in predicate (functional) style.
Example with Cached Symbols: This shows using cached @symbol instances without providing a domain.
Example with Indexing: This shows capturing getitem (indexing) in symbolic expressions.
Example with Flatten: This shows the usage of the flatten() operation on nested variables.
Example with Concatenate: This shows the concatenate operation that combines inner iterables into one.
To Cite:#
@software{bassiouny2025eql,
author = {Bassiouny, Abdelrhman},
title = {Entity-Query-Language},
url = {https://github.com/AbdelrhmanBassiouny/entity_query_language},
version = {3.0.0},
}