# Detectors

### Introduction

Detectors are a higher level analysis functions that run on top of processors to get a more curated and specific results. Technically, any function that utilize and analyse the tokens, POS tags, and/or dependencies can be considered a detector.

Typically, detector function should be added to the `Fin.Run` function prototype. So whenever a new instance is created the detector function can be applied on the processing result which resides on the context (`this`object) of the instance.

The reason that **Fin** has been designed to have it's detectors on the prototype, **not** as part of the core processors, is that the detector function might cause performance issues. So you can call detector function only when you need them.

### Basic Example <a href="#basic-example" id="basic-example"></a>

A very basic example that will just return the number of sentences in a given instance.

#### JavaScript <a href="#javascript" id="javascript"></a>

```javascript
import {Run} from "finnlp";
Run.prototype.sentencesCount = function () {
    return this.sentence.length;
}
```

#### TypeScript <a href="#typescript" id="typescript"></a>

```typescript
import * as Fin from "finnlp";
declare module "finnlp" {
    export interface Run {
        sentencesCount: () => number;
    }
}

Fin.Run.prototype.sentencesCount = function (this:Fin.Run) {
    return this.sentences.length;
};

```

### More elaborate examples <a href="#more-elaborate-examples" id="more-elaborate-examples"></a>

I'm maintaining few useful detectors, have a look at them if you want more elaborate examples:

* [American vs British spelling variation detector and converter](https://github.com/FinNLP/fin-ukus/blob/master/src/index.ts)
* [URLs Detector](https://github.com/FinNLP/fin-urls/blob/master/src/index.ts)
* [Sentiment Detector](https://github.com/FinNLP/fin-sentiment/blob/master/src/index.ts)
* [Sentence Type Detector](https://github.com/FinNLP/fin-sentence-type/blob/master/src/index.ts)
* [Negation Detector](https://github.com/FinNLP/fin-negation/blob/master/src/index.ts)
* [Emphasis Detector](https://github.com/FinNLP/fin-emphasis/blob/master/src/index.ts)
