{"componentChunkName":"component---node-modules-carrotsearch-gatsby-theme-apidocs-templates-documentation-page-js","path":"/rest-api-request-templates/","result":{"data":{"html":{"frontmatter":{"id":"rest-api-request-templates","title":"Request templates"},"html":"<article>\n  <h1>Request templates</h1>\n\n  <p id=\"e8b1c96e\">\n    You can simplify your REST API requests by moving the common configuration\n    parts to a request template.\n  </p>\n\n  <p id=\"f8f6cbc8\">\n    Request templates define default values for parts of the\n    <a href=\"/rest-api-basics/#/cluster\">clustering request JSON</a>, such as\n    algorithm name or language. If you use a template to make the clustering\n    request, you can omit the parts defined in the template. If you do provide\n    the parts in the request as well, they will override the defaults defined in\n    the template.\n  </p>\n\n  <section id=\"use-cases\">\n    <h2>\n        <a class=\"anchor\" href=\"#use-cases\" aria-hidden=\"true\"><svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"/></svg></a>Use cases\n      </h2>\n\n    <p id=\"use-cases:dafa455b\">REST API request templates can be useful in the following situations:</p>\n\n    <ul>\n      <li>\n        <p id=\"use-cases:4c97bc57\">\n          To detach the clustering algorithm configuration from the code that\n          makes clustering requests. In this arrangement, the request JSON\n          contains only the documents for clustering and the template provides\n          the remaining configuration.\n        </p>\n      </li>\n\n      <li>\n        <p id=\"use-cases:05353c77\">\n          To create aliases for differently tuned versions of Lingo3G. For\n          example, you can create a template called <code>focused</code> that\n          changes a number of parameters to\n          <a href=\"/parameter-tuning/#faq-specific-clusters\">make clusters more specific</a>.\n        </p>\n      </li>\n    </ul>\n  </section>\n\n  <section id=\"creating-request-templates\">\n    <h2>\n        <a class=\"anchor\" href=\"#creating-request-templates\" aria-hidden=\"true\"><svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"/></svg></a>Creating request templates\n      </h2>\n\n    <p id=\"creating-request-templates:7c48b724\">To create a request template, perform these steps:</p>\n\n    <ol>\n      <li>\n        <p id=\"creating-request-templates:60f08268\">\n          Create a file called, for example, <code>01 focused.json</code> in the\n          <code>dcs/web/service/templates/</code> directory of your Lingo3G\n          installation.\n        </p>\n\n        <p id=\"creating-request-templates:e42bea3f\">\n          The <code>focused</code> part of the file name is the identifier of\n          the template. The <code>01</code> number at the front is not part of\n          the identifier, it is used to sort templates for display purposes.\n        </p>\n      </li>\n\n      <li>\n        <p id=\"creating-request-templates:905da78f\">\n          Edit the template file to contain a JSON object with the same\n          structure as the\n          <a href=\"/rest-api-basics/#/cluster\">clustering request JSON</a>.\n        </p>\n\n        <p id=\"creating-request-templates:c4e6c3e8\">\n          For example, a template for creating\n          <a href=\"/parameter-tuning/#faq-specific-clusters\">more specific clusters</a>\n          can contain the following:\n        </p>\n\n        <figure id=\"creating-request-templates:example\">\n          <div class=\"gatsby-highlight\">\n    <pre class=\"language-json\"><code data-language=\"json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"language\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"English\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"algorithm\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Lingo3G\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"parameters\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"clusters\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"maxClusterSize\"</span><span class=\"token operator\">:</span> <span class=\"token number\">0.2</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token property\">\"hierarchy\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"maxClusteringPassesTop\"</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token property\">\"labels\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"singleWordLabelWeight\"</span><span class=\"token operator\">:</span> <span class=\"token number\">0.2</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre>\n  </div>\n\n          <figcaption>\n            <p>\n              Example clustering request template that generates more focused\n              clusters.\n            </p>\n          </figcaption>\n        </figure>\n      </li>\n\n      <li>\n        <p id=\"creating-request-templates:2f80b0da\">\n          Restart Lingo3G DCS to make the new template available for clustering.\n        </p>\n      </li>\n\n      <li>\n        <p id=\"creating-request-templates:69484a72\">\n          (Optional) Verify that the new template is present by making a\n          <code>GET</code> request to the\n          <a href=\"/rest-api-basics/#/list\"><code>/list</code></a>\n          endpoint. The response should contain the following section:\n        </p>\n\n        <div class=\"gatsby-highlight\">\n    <pre class=\"language-json\"><code data-language=\"json\">...\n  <span class=\"token property\">\"templates\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token string\">\"frontend-default\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">\"foo\"</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre>\n  </div>\n      </li>\n    </ol>\n  </section>\n\n  <section id=\"using-request-templates\">\n    <h2>\n        <a class=\"anchor\" href=\"#using-request-templates\" aria-hidden=\"true\"><svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"/></svg></a>Using request templates\n      </h2>\n\n    <p id=\"using-request-templates:eb62eaac\">\n      To use a template for a clustering request, pass the template identifier\n      in the <code>template</code> query parameter of the\n      <a href=\"/rest-api-basics/#/cluster\"><code>/cluster</code></a>\n      endpoint:\n    </p>\n\n    <div class=\"gatsby-highlight\">\n    <pre class=\"language-shell\"><code data-language=\"shell\"><span class=\"token function\">curl</span> -X POST --header <span class=\"token string\">\"Content-Type: text/json\"</span> --data-binary @template-request.json <span class=\"token string\">\"http://localhost:8080/service/cluster?indent&template=focused\"</span></code></pre>\n  </div>\n\n    <p id=\"using-request-templates:e935a097\">\n      The request JSON you submit can now contain only the document list, the\n      template provides the remaining parts:\n    </p>\n\n    <div class=\"gatsby-highlight\">\n    <pre class=\"language-json\"><code data-language=\"json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"documents\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Data Mining in Python\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"content\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Collection of libraries for machine learning.\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span> <span class=\"token operator\">:</span> <span class=\"token string\">\"KDD Lab: knowledge discovery from large spatial data.\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Data Mining\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"snippet\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token string\">\"Data mining uses machine learning ...\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string\">\"... automated knowledge discovery tools.\"</span>\n      <span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre>\n  </div>\n\n    <p id=\"using-request-templates:2b4bb3cb\">\n      If you provide other parts in your request JSON too, they will override\n      the configuration from the template. For example, you can change the\n      clustering language by providing a new <code>language</code> name:\n    </p>\n\n    <div class=\"gatsby-highlight\">\n    <pre class=\"language-json\"><code data-language=\"json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"language\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"German\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"documents\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Was ist Data Mining? \"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"content\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Data Mining ist die systematische Anwendung ...\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span> <span class=\"token operator\">:</span> <span class=\"token string\">\"Das Dilemma mit den sozialen Medien.\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Kollaboratives Filtern\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"snippet\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token string\">\"Interessen Einzelner zu schließen.\"</span>\n      <span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre>\n  </div>\n  </section>\n</article>","tableOfContents":[{"heading":"Use cases","anchor":"use-cases"},{"heading":"Creating request templates","anchor":"creating-request-templates"},{"heading":"Using request templates","anchor":"using-request-templates"}]}},"pageContext":{"slug":"/rest-api-request-templates/"}},"staticQueryHashes":["1164750013"]}