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

# Semantic similarity

Compute semantic similarity of two documents, potentially in different languages.

This API call allows you to compare two documents, potentially in different languages, and compute the semantic similarity between them. The computation will be based on the number of people, locations, organizations and things that are shared between the two documents.

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

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

#### `Parameters`

#### `apiKey`

string (required)

Your API key

#### `text1`

string (required)

The first text that will be used in the comparison.

#### `text2`

string (required)

The second text that will be used in the comparison.

## Request examples

### Example 1

Request body:

```json
{
  "text1": "The editor, Carrie Gracie, who joined the network 30 years ago, said she quit her position as China editor last week to protest pay inequality within the company. In the letter posted on her website, she said that she and other women had long suspected their male counterparts drew larger salaries and that BBC management had refused to acknowledge the problem.",
  "text2": "Paukenschlag bei der britischen BBC: Die China-Expertin Carrie Gracie hat aus Protest gegen die illegale Gehaltskultur und damit verbundene Heimlichtuerei ihren Job bei dem öffentlich-rechtlichen Sender hingeworfen. Zwei ihrer männlichen Kollegen in vergleichbaren Positionen würden nachweislich wesentlich besser bezahlt.",
  "apiKey": "YOUR_API_KEY"
}
```

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

doc1 = "The editor, Carrie Gracie, who joined the network 30 years ago, said she quit her position as China editor last week to protest pay inequality within the company. In the letter posted on her website, she said that she and other women had long suspected their male counterparts drew larger salaries and that BBC management had refused to acknowledge the problem."
doc2 = "Paukenschlag bei der britischen BBC: Die China-Expertin Carrie Gracie hat aus Protest gegen die illegale Gehaltskultur und damit verbundene Heimlichtuerei ihren Job bei dem öffentlich-rechtlichen Sender hingeworfen. Zwei ihrer männlichen Kollegen in vergleichbaren Positionen würden nachweislich wesentlich besser bezahlt."

annInfo = analytics.semanticSimilarity(doc1, doc2)

print("Similarity: %.3f" % (annInfo.get("similarity", 0)))
print("Annotations in first document: %d" % (annInfo.get("annotations1", 0)))
print("Annotations in second document: %d" % (annInfo.get("annotations2", 0)))
print("Total unique annotations: %d" % (annInfo.get("totalAnnotations", 0)))
```

```javascript
var er = new erBase.EventRegistry();
                    var analytics = new erBase.Analytics(er);
                    var doc1 = "The editor, Carrie Gracie, who joined the network 30 years ago, said she quit her position as China editor last week to protest pay inequality within the company. In the letter posted on her website, she said that she and other women had long suspected their male counterparts drew larger salaries and that BBC management had refused to acknowledge the problem.";
                    var doc2 = "Paukenschlag bei der britischen BBC: Die China-Expertin Carrie Gracie hat aus Protest gegen die illegale Gehaltskultur und damit verbundene Heimlichtuerei ihren Job bei dem öffentlich-rechtlichen Sender hingeworfen. Zwei ihrer männlichen Kollegen in vergleichbaren Positionen würden nachweislich wesentlich besser bezahlt.";
                    analytics.semanticSimilarity(doc1, doc2).then((annInfo) => {
                        console.log(annInfo);
                    });
```

```typescript
const er = new EventRegistry();
                    const analytics = new Analytics(er);
                    const doc1 = "The editor, Carrie Gracie, who joined the network 30 years ago, said she quit her position as China editor last week to protest pay inequality within the company. In the letter posted on her website, she said that she and other women had long suspected their male counterparts drew larger salaries and that BBC management had refused to acknowledge the problem.";
                    const doc2 = "Paukenschlag bei der britischen BBC: Die China-Expertin Carrie Gracie hat aus Protest gegen die illegale Gehaltskultur und damit verbundene Heimlichtuerei ihren Job bei dem öffentlich-rechtlichen Sender hingeworfen. Zwei ihrer männlichen Kollegen in vergleichbaren Positionen würden nachweislich wesentlich besser bezahlt.";
                    analytics.semanticSimilarity(doc1, doc2).then((annInfo) => {
                        console.log(annInfo);
                    });
```

## Example output

```json
{
  "similarity": 0.4045859505360701,
  "annotations1": 15,
  "annotations2": 13,
  "totalAnnotations": 22
}
```

## Output schema

```json
{
  "type": "object",
  "properties": {
    "similarity": {
      "type": "double"
    }
  }
}
```
