<!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>
      <journal-title-group>
        <journal-title>T. Jiang); https://lfnothias.github.io/ (L. Nothias); http://fabien.info/ (F. Gandon)
Ȉ</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <article-id pub-id-type="doi">10.5281/zenodo.15388693</article-id>
      <title-group>
        <article-title>Building Questions and Queries Datasets for Knowledge Graphs: a Demo of Q²Forge</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Yousouf Taghzouti</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff4">4</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Franck Michel</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Tao Jiang</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff3">3</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Louis-Felix Nothias</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff3">3</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Fabien Gandon</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Demonstrated Resource License Online prototype Q</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Inria, Univ. Côte d'Azur</institution>
          ,
          <addr-line>CNRS, I3S</addr-line>
          ,
          <country country="FR">France</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>KGBot Demo video</institution>
        </aff>
        <aff id="aff3">
          <label>3</label>
          <institution>Univ. Côte d'Azur</institution>
          ,
          <addr-line>CNRS, ICN</addr-line>
          ,
          <country country="FR">France</country>
        </aff>
        <aff id="aff4">
          <label>4</label>
          <institution>Univ. Côte d'Azur</institution>
          ,
          <addr-line>Inria, ICN, I3S</addr-line>
          ,
          <country country="FR">France</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2025</year>
      </pub-date>
      <volume>000</volume>
      <fpage>0</fpage>
      <lpage>0003</lpage>
      <abstract>
        <p>In this paper, we present a demo of how Q2Forge addresses the challenge of generating competency questions and corresponding SPARQL queries for any target Knowledge Graph. It iteratively validates those queries with human feedback and LLM as a judge. Q2Forge is open source, generic, extensible and modular. The demo shows the complete pipeline from competency question formulation to query evaluation, supporting the creation of reference question-query sets.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
    </sec>
    <sec id="sec-2">
      <title>2. From a Knowledge Graph to Q2Forge Pipeline</title>
      <p>Through an interactive and iterative process, Q2Forge helps users to carry out three main tasks:
generate CQs in NL for a target KG, based on information about the KG and its domain; propose SPARQL
query counterparts of the CQs, given the KG and its schemata; test the SPARQL queries, judge the
relevance of question-query pairs, and recommend refinements. To do so, Q 2Forge orchestrates the use of
various services to manage multiple per-KG configurations, extract the schema of a KG, invoke various
language models depending on the task to achieve at each step of the pipeline, etc. The services are
invoked through a documented Web API implemented by a back-end server. We provide a prototype
implementation of the back-end server called Gen2KGBot. A community may reuse Gen2KGBot as-is,
or customize or extend its services to meet their specific needs.</p>
      <p>
        Figure 1 describes the pipeline of Q2Forge: (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) create the configuration for a KG and (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) extract its
schema; (
        <xref ref-type="bibr" rid="ref3">3</xref>
        ) generate CQs and (
        <xref ref-type="bibr" rid="ref4">4</xref>
        ) optionally export them for reuse with another application or for
documenting purpose; (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) translate a CQ into SPARQL; (
        <xref ref-type="bibr" rid="ref6">6</xref>
        ) execute the query and propose an interpretation
of the results; (
        <xref ref-type="bibr" rid="ref7">7</xref>
        ) judge the relevance of the question-query pair and allow the user to iteratively refine
the query; (8) export the Q2set for reuse with other systems. Note that Q2Forge remains very flexible:
a user may follow the whole pipeline, but may also run each task independently by simply
importing/pasting input data and exporting/copying the outputs. The rest of this section further describes the
steps depicted in Figure 1.
      </p>
      <sec id="sec-2-1">
        <title>2.1. KG Configuration and Pre-processing</title>
        <p>The pipeline starts with creating a KG configuration (depicted in Figure 2a) where the user provides
minimal information about the target KG: a name, a short name used later as an identifier, a textual
description, a SPARQL endpoint URL, and the namespaces and prefixes to be used in the SPARQL queries
and Turtle descriptions. Optionally, the user may fill in the URL of a SPARQL endpoint hosting the
ontologies in case they are not on the same endpoint as the KG itself. The configuration is stored on
the back-end server and additional parameters can be edited manually to configure the available
language models (seq-to-seq and embedding), where they are hosted (e.g. local vs. cloud resources, vector
database etc.), and how they are assigned to each step of the pipeline. For instance, one may choose to
use a large model with reasoning capabilities for generating a SPARQL query, but use a smaller model
to interpret SPARQL results. Other parameters configure the strategy adopted to serialize ontology
(a) KG configuration and pre-processing
(b) Competency question generation
(c) SPARQL Query Generator/Executor
(d) Query refinement
classes in the prompts submitted to seq-to-seq models, such as the number of ontology classes to
describe and the linearization format used to describe them. Multiple formats are supported (currently
Turtle, tuples or a NL format), since diferent language models may behave diferently depending on
the selected format.</p>
        <p>We then extract from the KG various types of information that will be helpful to carry out the
downstream text-to-SPARQL task. This can be ontology classes that are relevant with respect to a
NL question, example SPARQL queries, etc. In our implementation, this step first creates a textual
description of the classes from the labels and descriptions available in the ontologies, and computes text
embeddings thereof. In Figure 2a, this is achieved in steps 2 and 3. Furthermore, there is usually a gap
between how an ontology defines classes and how instances of these classes are concretely represented
in the KG. Typically, instances may use properties and resources from additional vocabularies that are
not explicitly mentioned in the ontology. Therefore, the text-to-SPARQL task requires not only a
textual description of the classes, but also a description of how instances of these classes are represented.
Gen2KGBot addresses this need by sampling class instances and analyzing the properties and value
types they use. Lastly, the user may provide existing examples of NL question and associated SPARQL
query. The pre-processing includes computing embeddings of these question-query pairs.</p>
      </sec>
      <sec id="sec-2-2">
        <title>2.2. Competency Question Generation</title>
        <p>This step invokes a language model to generates CQs based on various information about the KG: name
and description, endpoint URL, list of the used ontologies. This information is either taken from the KG
configuration (created in the previous step) or manually entered in a form. The user may also provide
any other relevant information, e.g. the abstract of an article describing the KG.</p>
        <p>Figure 2b depicts the competency question generation interface. The user can select the language
model to be used for the generation of the CQs and the number of CQs to be generated. The model is
instructed to return each question with an evaluation of its complexity (Basic, Intermediate or Advanced)
and a set of tags. The Enforce Structured Output toggle can be used to compel the model to return the
CQs as a JSON-formatted document. Upon completion of the process, the user may download the
output as a JSON document, and save it in a browser’s cookie for reuse in the next step.</p>
      </sec>
      <sec id="sec-2-3">
        <title>2.3. SPARQL Query Generator/Executor</title>
        <p>In this step, the user has the ability to generate a SPARQL query counterpart of a NL question, execute
it against a KG, and get an interpretation of the results. The question may originate from the preceding
task, or the user may paste a question either hand-crafted or generated by another system.</p>
        <p>Q2Forge relies on various strategies provided by Gen2KGBot to accomplish this task, which we refer
to as “scenarios”. The demo will focus on Scenario 5, depicted in Figure 3. When running a scenario, the
steps of that scenario are progressively rendered on the interface, and for the ones that make an LLM
call, the response is dynamically streamed to ensure a good user experience. Figure 2c is a snapshot of
the interface of the SPARQL Query Generator/Executor. The steps are as follows:
1. Initial question: the workflow is initiated by the user posing a NL question.
2. Question validation: the question is evaluated to ensure its relevance to the context of the KG.</p>
        <p>If it is deemed invalid, the workflow stops.
3. Question pre-processing: named entities (NEs) are extracted from the question.
4. Select similar classes: similarity search between the question and the ontology class
descriptions (computed in the KG pre-processing step) selects relevant classes.
5. Get context information about the classes: retrieve a description of the properties and value
types used with instances of the selected classes.
6. Generate query: generate a prompt from a template1 using the KG configuration and the inputs
from the previous steps, and submit it to the configured LLM.
7. Verify query and retry: check if a SPARQL query was generated and if it is syntactically correct.</p>
        <p>If not, generate a retry prompt that includes the last generated answer and the reason for the
retry, e.g. syntax errors, and submit this retry prompt to the configured LLM.
8. Execute the SPARQL query: if a valid SPARQL query was generated, submit it to the KG
endpoint and get the results.
9. Use the configured LLM to interpret the SPARQL results.</p>
        <p>Scenario 5 is useful as a starting point when no prior question-query pair exists. However, once
some pairs have been validated or if some pairs were hand-crafted, they can be added to the context
and serve as examples. Scenario 6 can then be applied instead, as it provides the model with relevant
example SPARQL queries that can help in generating more accurate queries with fewer refinement
iterations.</p>
      </sec>
      <sec id="sec-2-4">
        <title>2.4. SPARQL Query Refinement</title>
        <p>In this step, the user can incrementally refine a SPARQL query so that it reflects precisely the question.
Figure 2d is a snapshot of the interface, and the process is as follows:
1. First, the query is displayed in a SPARQL editor that highlights potential syntactic errors and
can be used to submit the query to the endpoint.
2. To help the user understand the query, Q2Forge can extract the qualified (prefixed) names (QNs)
and fully qualified names (FQNs) from the query and get their labels and descriptions. For
instance, the label of http://purl.obolibrary.org/obo/CHEBI_53289 is “donepezil”, and its
description is “a racemate comprising equimolar amounts of (R)- and (S)-donepezil (...)”.
3. Then the LLM is asked to judge whether the query matches the given question. It is requested
to provide a grade between 0 and 10 along with explanations justifying the grade.
1https://github.com/Wimmics/gen2kgbot/blob/master/app/scenarios/scenario_5/prompt.py#L3
The user may then iterate as needed: amend the query based on the grade and insights from the model,
test it, have the model judge it, etc. Once a satisfying query is reached, the user can add the
questionquery pair to a dataset and export it in a variety of formats, catering to diferent use cases.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Conclusion and Availability</title>
      <p>The article proposes to demonstrate Q2Forge designed to address the generation of competency
questions (CQ) in NL, translate them into SPARQL queries, help users to refine those queries, and export
high-quality QALD-like Q2sets that can be used for benchmarking, training and evaluating
text-toSPARQL models. Q2Forge is provided under the GNU Afero General Public License v3.0 or later
(AGPL-3.0-or-later) license. The code is published on public Github repositories, and the versions used
at the time of writing are identified by DOIs to ensure the long-term preservation and citability. A
prototype is available for public access and has been assigned a W3ID. The API provided by Gen2KGBot
is documented according to the OpenAPI format.2</p>
    </sec>
    <sec id="sec-4">
      <title>Acknowledgments</title>
      <p>This work was supported by the French government through the France 2030 investment plan managed
by the National Research Agency (ANR), as part of the Initiative of Excellence Université Côte d’Azur
(ANR-15-IDEX-01). Additional support came from French Government’s France 2030 investment plan
(ANR-22-CPJ2-0048-01), through 3IA Cote d’Azur (ANR-23-IACL-0001) as well as the MetaboLinkAI
bilateral project (ANR-24-CE93-0012-01 and SNSF 10002786).</p>
    </sec>
    <sec id="sec-5">
      <title>Declaration on Generative AI</title>
      <p>During the preparation of this work, the author(s) used ChatGPT and DeepL for the following:
Grammar and spelling checks. After using these tools/services, the author(s) reviewed and edited the content
as needed, taking full responsibility for the publication’s content.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>R.</given-names>
            <surname>Alharbi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Tamma</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Grasso</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T. R.</given-names>
            <surname>Payne</surname>
          </string-name>
          ,
          <article-title>The Role of Generative AI in Competency Question Retrofitting</article-title>
          , in: The Semantic Web:
          <article-title>ESWC 2024 Satellite Events</article-title>
          : Hersonissos, Crete, Greece, May
          <volume>26</volume>
          -30,
          <year>2024</year>
          , Proceedings,
          <string-name>
            <surname>Part</surname>
            <given-names>I</given-names>
          </string-name>
          , Springer-Verlag,
          <year>2025</year>
          , pp.
          <fpage>3</fpage>
          -
          <lpage>13</lpage>
          . doi:
          <volume>10</volume>
          .1007/978- 3-
          <fpage>031</fpage>
          - 789
          <fpage>52</fpage>
          -
          <lpage>6</lpage>
          _
          <fpage>1</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>F.</given-names>
            <surname>Ciroku</surname>
          </string-name>
          , J. de Berardinis,
          <string-name>
            <given-names>J.</given-names>
            <surname>Kim</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Meroño-Peñuela</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Presutti</surname>
          </string-name>
          , E. Simperl,
          <article-title>RevOnt: Reverse Engineering of Competency Questions from Knowledge Graphs via Language Models</article-title>
          , Web Semant.
          <volume>82</volume>
          (
          <year>2024</year>
          ). doi:
          <volume>10</volume>
          .1016/j.websem.
          <year>2024</year>
          .
          <volume>100822</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>X.</given-names>
            <surname>Pan</surname>
          </string-name>
          ,
          <string-name>
            <surname>J. van Ossenbruggen</surname>
          </string-name>
          , V. de Boer,
          <string-name>
            <given-names>Z.</given-names>
            <surname>Huang</surname>
          </string-name>
          ,
          <string-name>
            <surname>A RAG</surname>
          </string-name>
          <article-title>Approach for Generating Competency Questions in Ontology Engineering</article-title>
          , in: M.
          <string-name>
            <surname>Sfakakis</surname>
            , E. Garoufallou,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Damigos</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          <string-name>
            <surname>Salaba</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          Papatheodorou (Eds.),
          <source>Metadata and Semantic Research</source>
          , Springer Nature Switzerland,
          <year>2025</year>
          , pp.
          <fpage>70</fpage>
          -
          <lpage>81</lpage>
          . doi:
          <volume>10</volume>
          .1007/978- 3-
          <fpage>031</fpage>
          - 81974-
          <issue>2</issue>
          _
          <fpage>6</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A.</given-names>
            <surname>Zouaq</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Martel</surname>
          </string-name>
          ,
          <article-title>What Is the Schema of Your Knowledge Graph? Leveraging Knowledge Graph Embeddings and Clustering for Expressive Taxonomy Learning</article-title>
          ,
          <source>in: Proceedings of The International Workshop on Semantic Big Data, SBD '20</source>
          ,
          <string-name>
            <surname>Association</surname>
          </string-name>
          for Computing Machinery,
          <year>2020</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>6</lpage>
          . doi:
          <volume>10</volume>
          .1145/3391274.3393637.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Rebboud</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Tailhardat</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Lisena</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Troncy</surname>
          </string-name>
          , Can LLMs Generate Competency Questions?, in: A.
          <string-name>
            <surname>Meroño Peñuela</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          <string-name>
            <surname>Corcho</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          <string-name>
            <surname>Groth</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          <string-name>
            <surname>Simperl</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <string-name>
            <surname>Tamma</surname>
            ,
            <given-names>A. G.</given-names>
          </string-name>
          <string-name>
            <surname>Nuzzolese</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Poveda-Villalón</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Sabou</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <string-name>
            <surname>Presutti</surname>
            ,
            <given-names>I. Celino</given-names>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Revenko</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Raad</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Sartini</surname>
          </string-name>
          , P. Lisena (Eds.),
          <source>The Semantic Web: ESWC 2024 Satellite Events</source>
          , Springer Nature Switzerland,
          <year>2025</year>
          , pp.
          <fpage>71</fpage>
          -
          <lpage>80</lpage>
          . doi:
          <volume>10</volume>
          .1007/978- 3 -
          <fpage>031</fpage>
          - 78952-
          <issue>6</issue>
          _
          <fpage>7</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>K. B.</given-names>
            <surname>Cohen</surname>
          </string-name>
          ,
          <string-name>
            <surname>J.-D. Kim</surname>
          </string-name>
          ,
          <article-title>Evaluation of SPARQL Query Generation from Natural Language Questions</article-title>
          ,
          <source>Proceedings of the Joint Workshop on NLP&amp;LOD and SWAIE: Semantic Web, Linked Open Data and Information Extraction</source>
          <year>2013</year>
          (
          <year>2013</year>
          )
          <fpage>3</fpage>
          -
          <lpage>7</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>V.</given-names>
            <surname>Emonet</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Bolleman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Duvaud</surname>
          </string-name>
          ,
          <string-name>
            <surname>T. M. de Farias</surname>
          </string-name>
          , A. C.
          <article-title>Sima, LLM-based SPARQL Query Generation from Natural Language over Federated Knowledge Graphs</article-title>
          ,
          <year>2024</year>
          . URL: https://arxiv.org/abs/ 2410.06062. arXiv:
          <volume>2410</volume>
          .
          <fpage>06062</fpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>