---
agentTools:
  projectIndex: https://help.logichub.com/llms.txt
---

# buildTermCorpus

Build a model from corpus

There are many cases where we have a handful (10 - 2000) past examples of text data and we want to see if new text is close to these saved examples.  Machine learning techniques like classification are not appropriate because we don’t have enough data to train an accurate model.

[block:api-header]
{
  "title": "Operator Usage in Easy Mode"
}
[/block]

1. Click **+** on the parent node.
2. Enter the **Build Term Corpus** operator in the search field and select the operator from the **Results** to open the operator form.
3. In the **Table** drop-down, enter or select a table to create the model.
4. In the **Model Name** field, enter the name of a model.
5. In the **Column** field, enter a column name that contains the text to extract TF-IDF features.
6. In the **Columns to Keep** drop-down, select a column name to store with the corpus as enrichment to retrieve when used in matchSimilarFromCorpus.
7. Optional. Click **Add More** to add values for minimum and maximum TF parameters.
8. Click **Run** to view the result.
9. Click **Save** to add the operator to the playbook.
10. Click **Cancel** to discard the operator form.

[block:api-header]
{
  "type": "basic",
  "title": "Usage Details"
}
[/block]

We then want to match them against an incoming stream of events to determine how close they are to what we've already observed and retrieve some enrichment about those past examples.

[block:code]
{
  "codes": [
    {
      "code": "buildTermCorpus(table: TableReference, modelName: String, column:String, columnsToKeep:String[], parameters:Double*)",
      "language": "cplusplus",
      "name": "LQL Command"
    }
  ]
}
[/block]

**Input Parameters**
*table*	(TableReference)	-	The table to create a model
*modelName*	(String)	-	name of a model
*column*	(String)	-	Column name that contains the text to extract TF-IDF features
*columnsToKeep*	(String\[])	-	list of columns to store with the corpus as enrichment to retrieve when used in matchSimilarFromCorpus
*parameters*	(Double)	-	minDF and minTF parameters, default values for both is 1.0 (include 100% of terms). First parameter will be always set for minTF. e.g.
buildTermCorpus(table, model, corpus, \[columnsToKeep], 0.5, 0.4) // minDF = 0.5, minTF=0.4

**Output**
If the operator successfully run, it will return success message of model being stored.

[block:api-header]
{
  "title": "Example"
}
[/block]

**Input**
table = github\_logs

[block:html]
{
  "html": "<style>\n  th {\n    border: 1px solid #cccccc;\n    background-color: #eeeeee;\n    padding: 8px 5px 8px 5px;\n    text-align: left\n  }\n</style>\n\n<div><table>\n<thead>\n<tr>\n<th>corpus</th>\n<th>label</th>\n<th>domain</th>\n</tr>\n</thead>\n<tbody>\n<tr><td>a b c, d e f, g, h, i, j</td><td>x</td><td>google</td></tr><tr><td>aa b, c, d ee, ff, gg, hh, i, jj</td><td>y</td><td>facebook</td></tr>\n  <tr><td>k, l, m, n, o, p, q</td><td>z</td><td>apple</td></tr>\n</tbody>\n</tr>\n</table></div>"
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "buildModelFromCorpus(inputTable, \"corpusModel\", \"corpus\", [\"label\", \"domain\"])\n// table = inputTable\n// text to train model = corpus\n// columns to keep so they will be added after match is found = label and domain\n// minDF and minTF are default",
      "language": "sql",
      "name": "LQL command"
    }
  ]
}
[/block]

**Output**

[block:html]
{
  "html": "<div><table>\n<thead>\n<tr>\n<th>RESULT</th>\n</tr>\n</thead>\n<tbody>\n  <tr><td>'Successfully created model and stored into <<testModel>> file'</td></tr>\n</tbody>\n</tr>\n</table></div>\n\n"
}
[/block]