Source: https://eventregistry.org/documentation?tab=categorize

# Categorize

Categorize the content into a set of predefined categories.

The API call can be used to compute a list of predefined categories that summarize your content. There are two taxonomies of categories that can be used - `dmoz` and `news`. The `dmoz` taxonomy contains over 5000 categories and can only be used for documents in English language. It is organized into 3 levels and go from more general to more specific topics. The `news` taxonomy contains only 8 top level categories commonly used to categorize the news content, but can be applied on any language. The categorization into both taxonomies can work well only on documents of decent size (like news articles). The `iptc` subject codes contain over 1,000 categories organized into 3 levels. The taxonomy is maintained by [IPTC standards body of the news media](https://iptc.org/standards/subject-codes/).

**Endpoint:** GET | POST `http://analytics.eventregistry.org/api/v1/categorize`

**Headers:** Content-Type: application/json

#### `Parameters`

#### `apiKey`

string (required)

Your API key

#### `text`

string (required)

Define a text that you'll like to see categorized.

#### `taxonomy`

string (required)

Define the taxonomy in which you'll want to categorize the selected text

Available values: `dmoz`, `news`, `iptc`

## Request examples

### Example 1

Categorize the input text using the DMOZ taxonomy.

Request body:

```json
{
  "text": "Microsoft released a new version of Windows OS.",
  "taxonomy": "dmoz",
  "apiKey": "YOUR_API_KEY"
}
```

```python
from eventregistry import *
er = EventRegistry(apiKey = YOUR_API_KEY)
analytics = Analytics(er)

# use the DMOZ taxonomy to categorize the input text
annInfo = analytics.categorize("Microsoft released a new version of Windows OS.")

for cat in annInfo.get("categories", []):
    print(cat)

for kw in annInfo.get("keywords", []):
    print(kw)
```

```javascript
var er = new erBase.EventRegistry();
                    var analytics = new erBase.Analytics(er);
                    analytics.categorize("Microsoft released a new version of Windows OS.").then((annInfo) => {
                        console.log(annInfo);
                    });
```

```typescript
const er = new EventRegistry();
                    const analytics = new Analytics(er);
                    analytics.categorize("Microsoft released a new version of Windows OS.").then((annInfo) => {
                        console.log(annInfo);
                    });
```

### Example 2

Categorize the input text using the news taxonomy.

Request body:

```json
{
  "text": "Coronavirus live news: global cases pass 5m as EU health chief warns of second wave.",
  "taxonomy": "news",
  "apiKey": "YOUR_API_KEY"
}
```

```python
from eventregistry import *
er = EventRegistry(apiKey = YOUR_API_KEY)
analytics = Analytics(er)

# use the news taxonomy to categorize the input text
annInfo = analytics.categorize("Coronavirus live news: global cases pass 5m as EU health chief warns of second wave.", taxonomy = "news")

for cat in annInfo.get("categories", []):
    print(cat)
```

```javascript
var er = new erBase.EventRegistry();
                    var analytics = new erBase.Analytics(er);
                    analytics.categorize("Coronavirus live news: global cases pass 5m as EU health chief warns of second wave.", taxonomy = "news").then((annInfo) => {
                        console.log(annInfo);
                    });
```

```typescript
const er = new EventRegistry();
                    const analytics = new Analytics(er);
                    analytics.categorize("Coronavirus live news: global cases pass 5m as EU health chief warns of second wave.", taxonomy = "news").then((annInfo) => {
                        console.log(annInfo);
                    });
```

## Example output

```json
{
  "categories": [
    {
      "label": "dmoz/Society/Politics/Campaigns_and_Elections",
      "score": 0.1590137586442502
    },
    {
      "label": "dmoz/Society/Issues/Government_Operations",
      "score": 0.09788376841818867
    },
    {
      "label": "dmoz/Sports/Running/Training",
      "score": 0.09113215743926972
    },
    {
      "label": "dmoz/Society/Politics",
      "score": 0.08833645912765467
    },
    {
      "label": "dmoz/Sports/Running/Women",
      "score": 0.08633878749684593
    }
  ],
  "keywords": [
    {
      "keyword": "Society",
      "wgt": 0.1562750829170778
    },
    {
      "keyword": "Politics",
      "wgt": 0.133749498823212
    },
    {
      "keyword": "Campaigns_and_Elections",
      "wgt": 0.104674684563492
    }
  ]
}
```

## Output schema

```json
{
  "type": "object",
  "properties": {
    "categories": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "example": "dmoz/Business/Investing/Stocks_and_Bonds"
          },
          "score": {
            "type": "double",
            "example": 0.123
          }
        }
      }
    },
    "keywords": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "keyword": {
            "type": "string",
            "example": "Investing"
          },
          "wgt": {
            "type": "double",
            "example": 0.24
          }
        }
      }
    }
  }
}
```
