<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Alexander Stahl</string-name>
          <email>stahlale@b-tu.de</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>. From Examples to Queries</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Brandenburg University of Technology Cottbus-Senftenberg</institution>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2025</year>
      </pub-date>
      <abstract>
        <p>Query-by-Example (QBE) is a classical method for formulating database queries by filling out relation templates with example values, which avoids the need for formal query languages. Extensions such as Fuzzy QBE have introduced variants, where users label example tuples as relevant or irrelevant to guide the construction of a query condition. In this paper, we examine how such label-driven query induction can be applied to quantum logic-based query languages, focusing on the Commuting Quantum Query Language (CQQL). We assume the problem to be a form of classification and approach it using Quantum Logic Decision Trees. The resulting conditions are expressed as CQQL formulas and compiled into executable queries using Quantum SQL. We provide illustrative examples and discuss practical considerations.</p>
      </abstract>
      <kwd-group>
        <kwd>query by example</kwd>
        <kwd>query learning</kwd>
        <kwd>classification</kwd>
        <kwd>quantum logic</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>Germany
CEUR
Workshop
ISSN1613-0073</p>
    </sec>
    <sec id="sec-2">
      <title>2. Related Work and Problem Reformulation</title>
      <p>
        QBE was introduced in the 1970s as a user-friendly interface for relational databases, aimed at users
unfamiliar with formal query languages like SQL [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. In QBE, users fill out a template table by entering
example values or conditions into selected fields. These entries are then interpreted as constraints on
the corresponding attributes, and the system translates the filled-in template into a formal relational
query. The approach allows users to express simple selection, projection, and join queries without
writing explicit code. However, classical QBE is limited to Boolean logic, fixed schema interactions, and
exact matches, which makes it unsuitable for more expressive logic-based frameworks with gradual
relevance values.
      </p>
      <p>
        A more recent line of work proposes generating queries directly from natural language with
techniques from natural language processing, particularly using large language models (LLMs). Examples of
this approach can be found in studies such as [
        <xref ref-type="bibr" rid="ref4 ref5">4, 5</xref>
        ]. These methods allow the translation of information
needs into executable query languages with minimal efort by the user. However, while their appeal is
clear, the black-box nature and inherent unpredictability of LLMs, despite significant recent advances,
may still render them unsuitable for applications where reliability and transparency are essential.
      </p>
      <p>
        To overcome the limitations of classical QBE in handling vague or graded relevance, Moreau et al.
proposed Fuzzy Query-by-Example (FQBE) [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. Their approach allows users to label a small set of
tuples as relevant or irrelevant, and the system then infers a fuzzy characterization of the relevant
examples. In particular, the method identifies attribute intervals or value patterns that are common
among the positive examples and uncommon among the negatives, and constructs a fuzzy selection
condition that best captures this contrast. The resulting fuzzy query is expressed using linguistic
quantifiers and graded predicates, which provides a retrieval method that tolerates imprecision. While
FQBE extends classical QBE with graded relevance and soft matching, it is not conceptually compatible
with quantum logic-based approaches. As mentioned above, fuzzy logic, as used in FQBE, is based on
numerical aggregation (e.g. t-norms and membership functions) rather than projection-based semantics
or subspace logic. More importantly, fuzzy logic does not universally satisfy several core logical
properties that are preserved in quantum logic! In particular, the law of the excluded middle and the
law of non-contradiction hold only under specific combinations of negation and aggregation operators,
and are violated in many common fuzzy systems [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. These diferences make FQBE unsuitable as
a foundation for querying in quantum-logical frameworks, where the logic structure itself must be
preserved throughout the inference process.
      </p>
      <p>
        However, a closer examination of FQBE reveals that the problem it addresses is structurally equivalent
to that of a classification task. The user, by labeling tuples as relevant or irrelevant, efectively provides
a training set, and the system learns a selection condition that distinguishes the relevant examples from
the rest. This is much like how a classifier learns a decision boundary. In this light, QBE can be viewed
as an instance of logic-based supervised learning, where the goal is to infer an interpretable predicate
that approximates user intent. This places the problem in the domain of query learning, where queries
are induced from labeled examples [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ].
      </p>
      <p>The approach of viewing query construction as a classification problem based on labeled examples
has been adopted in other works as well. For example, [9] propose Libra, a system that synthesizes
relational selection queries by learning decision trees from input-output tuple examples. Even though it
operates strictly in the classical Boolean context, its methodology is very similar to that of Fuzzy QBE.
Both treat the user’s labeling as a form of supervision, and both induce a condition that distinguishes
relevant from irrelevant tuples. Notably, Libra does not reference earlier fuzzy QBE approaches, but can
be seen as continuing the same fundamental idea of query learning. The works of these authors show
that classification can be used as a tool to learn queries that represent user wishes, which motivates
our approach. This perspective motivates our approach: in the following chapters, we explore how
classification models can be used to learn such queries directly from labeled examples.</p>
      <sec id="sec-2-1">
        <title>Unlabeled</title>
      </sec>
      <sec id="sec-2-2">
        <title>Records</title>
        <p>(User-provided)</p>
      </sec>
      <sec id="sec-2-3">
        <title>Relevance</title>
      </sec>
      <sec id="sec-2-4">
        <title>Labels</title>
      </sec>
      <sec id="sec-2-5">
        <title>Labeled</title>
      </sec>
      <sec id="sec-2-6">
        <title>Records</title>
      </sec>
      <sec id="sec-2-7">
        <title>QLDT</title>
      </sec>
      <sec id="sec-2-8">
        <title>Classifier</title>
      </sec>
      <sec id="sec-2-9">
        <title>SQL/QSQL</title>
      </sec>
      <sec id="sec-2-10">
        <title>Query</title>
      </sec>
      <sec id="sec-2-11">
        <title>Relevant</title>
      </sec>
      <sec id="sec-2-12">
        <title>Records</title>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Query Induction via Classification</title>
      <p>
        As an initial step towards our logic-based formulation and to motivate the next steps, we first consider a
simplified version using classical decision trees (DT) and Boolean logic, with a methodology similarly to
the approaches in [
        <xref ref-type="bibr" rid="ref6">9, 6</xref>
        ]. This example provides a more intuitive foundation for the quantum logic-based
method introduced in the next sections.
      </p>
      <p>A DT is a classification model that partitions the input space by recursively applying conditions on
attribute values, resulting in a tree structure where each internal node represents a decision based on an
attribute, and each leaf corresponds to a classification outcome. It is a classical and widely used model,
particularly valued for its interpretability, as each decision path from root to leaf can be translated into a
Boolean expression that explains why a particular classification was made [ 10]. For binary classification,
a decision tree can be represented by a single Boolean formula that captures the conditions under which
an input is assigned the positive class. Aside from XAI aspects, this property is also useful in database
contexts, as the resulting Boolean expression can be directly embedded into an SQL query, which would
efectively transform a learned classifier into a selection predicate.</p>
      <p>In practice, the process proceeds as follows. We begin by collecting labels from the user, who marks
a selection of randomly chosen tuples from the input relation as either relevant or not relevant. Each
labeled tuple is treated as a feature vector for training, where the relevance label serves as the class, and
each column in the relation corresponds to an attribute. A classification algorithm, such as CART [ 11],
is then applied to learn a DT. The resulting tree is transformed into a Boolean expression that represents
the selection condition for the relevant class. This expression can be inserted into the WHERE clause of a
prepared SQL query. The process of this approach is illustrated in Figure 1. While we focus here on
single-table selections for simplicity, this method can be extended to support JOIN and more complex
queries.</p>
      <p>For a simple example, consider the toy dataset in Table 1, which describes colored balls of difering
size. The column “Label” refers to the user-provided relevance evaluation and encodes “irrelevant” as 0
and “relevant” as 1. Training a DT classifier on this dataset could result in a simple DT such as depicted
in Figure 2.</p>
      <p>This DT can be expressed as a Boolean expression, which expresses the truth value of the statement:
“The record is relevant”. Such an expression would be:
( =
’Red’) ∧ ( =
’Large’)
Incorporating the expression into an SQL statement, would yield the query in the following Listing 1:</p>
      <p>True</p>
      <p>Size = Large?
True
1</p>
      <p>False</p>
      <p>0
Color = Red?</p>
      <p>False
0</p>
      <sec id="sec-3-1">
        <title>SELECT ∗ FROM B a l l s</title>
        <p>WHERE C o l o r = ’ Red ’ AND S i z e = ’ L a r g e ’ ;</p>
        <p>This example demonstrates how a classification model, in this case a DT, can be used to derive a
logical query predicate from user-labeled data. The resulting condition is interpretable, executable, and
mirrors the user’s intent. In the following sections, we extend this approach beyond Boolean logic by
explaining and applying a quantum logic-based classifier instead of the DT, which adds support for
graded relevance.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. The QLDT Model</title>
      <p>A QLDT [12] is a classification model for tabular data that uses quantum-inspired logic at its core.
Note that the usage of quantum logic does not, by itself, imply any connection to quantum computing.
Although quantum logic borrows mathematical ideas from quantum mechanics, it operates on classical
computers and does not involve concepts such as superposition, entanglement, or quantum circuits.</p>
      <p>
        A QLDT consists of a CQQL condition on normalized attribute values and a threshold. CQQL refers
to Commuting Quantum Query Language [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. It allows for logic conditions that are syntactically
equivalent to propositional logic and preserve many rules of Boolean algebra (such as commutativity
and De Morgan’s rules), while the truth values are in [
        <xref ref-type="bibr" rid="ref1">0, 1</xref>
        ] instead of {true, false}.
      </p>
      <p>
        For brevity, we do not describe the full formalism of CQQL here and instead refer to [13] for a
simplified explanation based on probability theory. In this interpretation, the evaluation of a condition
 against a feature vector  , which is notated as []  , works as follows. Atomic conditions  denote the
event that a given attribute of an object  “is high” and their evaluation []  returns the corresponding
attribute value of  normalized to [
        <xref ref-type="bibr" rid="ref1">0, 1</xref>
        ]. Disjunctions such as   =  1 ∨  2 can be evaluated as a sum:
assuming all normalized attribute values   represent statistically independent events. Conjunctions
like   =  1 ∧  2 are evaluated as a product:
analogously. Finally, negation is expressed as
[  ] = [ 1] + [ 2] ,
[  ] = [ 1] ⋅ [ 2] ,
      </p>
      <p>
        [  ] = 1 − []  ,
mirroring the complement of a probability value. This evaluation scheme remains valid even if the terms
of the logical expression are themselves non-atomic, as long as they remain statistically independent.
This is typically the case when the overall expression is in disjunctive normal form (DNF), where each
conjunction can be treated as an independent unit. It should be noted that full distributivity does not
hold in general quantum logic. To address this, CQQL expressions are always evaluated in DNF.
evaluation of CQQL conditions generates a score []  ∈ [
        <xref ref-type="bibr" rid="ref1">0, 1</xref>
        ] as their output. In order to enable
classification, a suitable threshold value  is chosen, which is used to compare and map the score to {0, 1}.
      </p>
    </sec>
    <sec id="sec-5">
      <title>5. Query Induction with QLDT</title>
      <p>With the methodology from Section 3 established, we now adapt it to the quantum logic setting by
integrating the Quantum Logic Decision Tree (QLDT) introduced in Section 4. As before, the goal is
to induce a query condition from labeled tuples by extracting a logical expression that best separates
relevant from irrelevant examples. In this case, however, we aim to learn a CQQL condition instead.
This condition can then be used to construct a query, just as in the Boolean case.</p>
      <p>A key diference is that standard SQL does not support quantum logic operators, similarity-based
predicates, or graded relevance evaluation. To address this, we propose using the Quantum SQL
(QSQL) dialect [14], which is specifically designed to support such semantics. Since QSQL is not widely
supported in commercial systems, we optionally translate the resulting QSQL query into standard
SQL-99. This is possible, as long as the required similarity functions are defined in the database system
for the relevant attributes, for example using user-defined functions in a procedural SQL dialect like
PL/SQL.</p>
      <p>To illustrate this concept, we provide a second example relation and apply the method on this data.
value for safety and emission level, where a possible consumer would prefer a high safety and a low
emission level. Furthermore, the table shows the the label that was provided by a user and a score that
we will discuss below.</p>
      <p>Training a QLDT classifier on this data yields the decision tree shown in Figure 3. In this figure, the
safety attribute is abbreviated as  and the emission attribute as  , purely for compactness of presentation.
(This difers from the rest of the paper, where  denotes a condition!)</p>
      <p>[]  = [safety] ⋅ (1 − [emission] ).</p>
      <p>Keep in mind that for the evaluation of an atomic attribute (e.g. emission), the attribute value is taken
from the feature vector of the evaluated object  . Incorporating this condition into QSQL could result in
the query in Listing 2:</p>
      <p>Listing 2: QSQL query expressing the CQQL condition</p>
      <sec id="sec-5-1">
        <title>SELECT ∗</title>
        <p>FROM a u t o m o b i l e s
WHERE ( s a f e t y ~ 1 )</p>
        <p>AND NOT ( e m i s s i o n ~ 1 )</p>
      </sec>
      <sec id="sec-5-2">
        <title>ORDER BY s c o r e v a l DESC ;</title>
        <p>In QSQL, the operator ∼ denotes similarity to a reference value, here 1, evaluated according to CQQL
semantics. This is equivalent to the condition that the value “is high” since 1 is the upper limit of its
domain. Conjunction and negation are evaluated as described in Section 4.</p>
        <p>As discussed earlier, this QSQL code can be converted into normal SQL. For the actual mechanisms
of parsing from QSQL to SQL, we refer to [14]. The SQL version of the previous query can be found in
Listing 3 below:</p>
        <p>Listing 3: SQL translation of the QSQL query</p>
      </sec>
      <sec id="sec-5-3">
        <title>SELECT ∗ ,</title>
        <p>LAND (</p>
        <p>SAFE_TO_SCORE ( s a f e t y , 1 ) ,
LNOT ( EM_TO_SCORE ( e m i s s i o n , 1 ) )
) AS s c o r e v a l
FROM a u t o m o b i l e s</p>
      </sec>
      <sec id="sec-5-4">
        <title>ORDER BY s c o r e v a l DESC ;</title>
        <p>This, of course, requires the used functions to be defined in the system beforehand. A short list with
descriptions of the functions in this example is provided in Table 3. It should be emphasized that in
this SQL version, the condition is not placed in the WHERE clause but computed in the SELECT clause.
This is because its gradual fulfillment is expressed as the attribute scoreval, which must be part of the
result relation. Thresholding can be added in WHERE by referencing scoreval, but the intended query
includes all tuples and orders them by their degree of fulfillment.</p>
        <p>This demonstrates how a QLDT can be used to derive interpretable, graded query conditions in the
form of CQQL expressions, which can then be translated into executable QSQL and SQL statements.</p>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>6. Conclusion</title>
      <p>This work contributes a conceptual step toward bringing example-based query formulation into the
setting of quantum logic. Our main outcome is to show that query learning, when framed as a
classification problem, can be extended beyond Boolean logic by employing Quantum Logic Decision
Trees (QLDT). This allows queries to be induced from labeled tuples in a way that produces interpretable
conditions, which can then be executed as Commuting Quantum Query Language (CQQL) expressions
and compiled into Quantum SQL (QSQL) or SQL.</p>
      <p>Our method generates clean, Boolean algebra-compliant logic expressions, supports fuzzy decision
boundaries and gradual relevance without being confined to classical Boolean logic, and inherits the
classification performance of QLDTs, which have been shown to perform well in prior studies. As
for the limitations of the method, it relies on suficient and representative labeled data, which may be
challenging to obtain from the user.</p>
      <p>The generated CQQL conditions require evaluation in QSQL, for which no current implementation
exists, or must be mapped manually to SQL-99 with user-defined similarity functions. Additionally,
QLDT currently supports only simple similarity cases (conditions like “is high” or “is low”) and lacks
more flexible or attribute-specific similarity semantics. This could be partially mitigated by replacing
the QLDT with a BBQ-Tree, a variant that includes more types of possible splits [15].</p>
      <p>This paper is primarily conceptual and does not include an empirical evaluation of user efectiveness.
Nonetheless, the underlying components (QBE, DT and QLDT) have been validated individually in
prior research. Future work could investigate the practical usability of this method through user studies,
system implementation, and comparative benchmarks. Furthermore, strategies such as Active Learning
or weak supervision could be explored to reduce the labeling efort required from users.</p>
      <p>In summary, we have shown that query induction from labeled examples is feasible even in the
context of quantum logic. This contributes a small but necessary step toward supporting example-based
query formulation in systems that rely on quantum logic.</p>
    </sec>
    <sec id="sec-7">
      <title>Declaration on Generative AI</title>
      <p>During the preparation of this work, the author used ChatGPT-4 in order to: Grammar and spelling
check and preparation of TikZ code for figures. After using this service, the author reviewed and edited
the content as needed and takes full responsibility for the publication’s content.
by examples: An experiment using relevance feedback, id3, genetic algorithms, and simulated
annealing, Journal of the American Society for Information Science 49 (1998) 693–705.
[9] A. Naik, A. Thakkar, A. Stein, R. Alur, M. Naik, Relational query synthesis ⋈ decision tree
learning, Proc. VLDB Endow. 17 (2023) 250–263. URL: https://doi.org/10.14778/3626292.3626306.
doi:10.14778/3626292.3626306.
[10] S. Russell, P. Norvig, Artificial Intelligence: A Modern Approach, Global Edition, Pearson Education,</p>
      <p>London, 2021.
[11] L. Breiman, J. H. Friedman, R. A. Olshen, C. J. Stone, Classification and Regression Trees, CRC</p>
      <p>Press, New York, 1984. doi:10.1201/9781315139470.
[12] I. Schmitt, QLDT: A decision tree based on quantum logic, in: S. Chiusano, T. Cerquitelli,
R. Wrembel, K. Nørvåg, B. Catania, G. Vargas-Solar, E. Zumpano (Eds.), New Trends in Database
and Information Systems, Springer International Publishing, Cham, 2022, pp. 299–308.
[13] I. Schmitt, Logic interpretations of ann partition cells, 2024. URL: https://arxiv.org/abs/2408.14314.</p>
      <p>arXiv:2408.14314.
[14] S. Lehrack, I. Schmitt, QSQL: Incorporating logic-based retrieval conditions into SQL, in: H.
Kitagawa, Y. Ishikawa, Q. Li, C. Watanabe (Eds.), Database Systems for Advanced Applications, Springer
Berlin Heidelberg, Berlin, Heidelberg, 2010, pp. 429–443.
[15] A. Stahl, I. Schmitt, BBQ-Tree – a decision tree with boolean and quantum logic decisions, in:
Lecture Notes in Computer Science, volume 14918, 2024.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>C. J. van Rijsbergen</surname>
          </string-name>
          ,
          <source>The Geometry of Information Retrieval</source>
          , Cambridge University Press,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>I. Schmitt</surname>
          </string-name>
          , QQL:
          <string-name>
            <surname>A DB</surname>
          </string-name>
          &amp;
          <article-title>IR query language</article-title>
          ,
          <source>The VLDB Journal</source>
          <volume>17</volume>
          (
          <year>2008</year>
          )
          <fpage>39</fpage>
          -
          <lpage>56</lpage>
          . doi:
          <volume>10</volume>
          .1007/ s00778- 007- 0070- 1.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>M. M. Zloof</surname>
          </string-name>
          ,
          <article-title>Query-by-example: A data base language</article-title>
          ,
          <source>IBM Systems Journal</source>
          <volume>16</volume>
          (
          <year>1977</year>
          )
          <fpage>324</fpage>
          -
          <lpage>343</lpage>
          . doi:
          <volume>10</volume>
          .1147/sj.164.0324.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A.</given-names>
            <surname>Kharade</surname>
          </string-name>
          ,
          <article-title>Generation of sql query using natural language processing</article-title>
          ,
          <source>SSRN preprint</source>
          ,
          <year>2023</year>
          . doi:
          <volume>10</volume>
          .2139/ssrn.4515801.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>M.</given-names>
            <surname>Uma</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Sneha</surname>
          </string-name>
          , G. Sneha,
          <string-name>
            <given-names>J.</given-names>
            <surname>Bhuvana</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Bharathi</surname>
          </string-name>
          ,
          <article-title>Formation of SQL from natural language query using NLP</article-title>
          , in: 2019
          <source>International Conference on Computational Intelligence in Data Science (ICCIDS)</source>
          ,
          <year>2019</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>5</lpage>
          . doi:
          <volume>10</volume>
          .1109/ICCIDS.
          <year>2019</year>
          .
          <volume>8862080</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>A.</given-names>
            <surname>Moreau</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Pivert</surname>
          </string-name>
          , G. Smits,
          <article-title>Fuzzy query by example</article-title>
          ,
          <source>in: Proceedings of the 33rd Annual ACM Symposium on Applied Computing</source>
          ,
          <year>2018</year>
          , pp.
          <fpage>688</fpage>
          -
          <lpage>695</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>S.</given-names>
            <surname>Demir Sağlam</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. Karadeniz</given-names>
            <surname>Gözeri</surname>
          </string-name>
          ,
          <article-title>Some properties of boolean-like laws in fuzzy logic</article-title>
          ,
          <source>Symmetry</source>
          <volume>17</volume>
          (
          <year>2025</year>
          ). URL: https://www.mdpi.com/2073-8994/17/4/548. doi:
          <volume>10</volume>
          .3390/sym17040548.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>H.</given-names>
            <surname>Chen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G.</given-names>
            <surname>Shankaranarayanan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>She</surname>
          </string-name>
          ,
          <string-name>
            <surname>A. Iyer,</surname>
          </string-name>
          <article-title>A machine learning approach to inductive query</article-title>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>