Implementation of AI in Schematron

To call an implementation of AI in Schematron, you can use XSLT functions or extension functions.

  1. Using XSLT functions:

    You can use XSLT functions to call an implementation of AI in Schematron. For example, you can use implement function to call ChatGPT API. Here's an example:

    Example 1. Example of XSLT functions that calls ChatGPT

    <xsl:function name="ai:chatGPT">
        <xsl:param name="userInput"/>
        <xsl:variable name="url" select="'https://api.chatgpt.com/v1/chatbot/question'"/>
        <xsl:variable name="requestBody" select="concat('{', '&quot;text&quot;:&quot;',
            $userInput,'&quot;', '}')"/>
        <xsl:variable name="response" select="document(concat($url, '?apiKey=',
            '&lt;your_api_key>'))//response"/>
        <xsl:sequence select="$response"/>
    </xsl:function>


  2. Using extension functions:

    You can also use extension functions to call an implementation of AI in Schematron. For example, you can define an extension function called `ai:verify-content` that takes an instruction and content as parameters and returns a boolean. Here's an example:

    Example 2. Example an extensions function ai:verify-content()

    <sch:rule context="...">
      <sch:assert test="ai:verify-content('instruction', 'content')">Message</sch:assert>
    </sch:rule>


    In this example, the `ai:verify-content` function is called within a `sch:assert` element to verify that the content meets certain criteria specified by the instruction.

    To modify the content using AI, you can define an extension function called `ai:transform-content` that takes an instruction and content as string parameters and returns transformed content as string. You can use this function an SQF action to correct the content. Here's an example:

    Example 3. Example an extension function ai:transform-content

    <sqf:fix id="rephrase">
        <sqf:replace select="ai:transform-content('instruction', 'content')"/>
    </sqf:fix>

    The `ai:transform-content` function is called within a `sqf:replace` element and will transform the given content according to the instruction, the returned result will be inserted in the document replacing the current node content .