entity-predictor 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/predictor.js +5 -3
package/README.md
CHANGED
|
@@ -63,7 +63,8 @@ Output:
|
|
|
63
63
|
{
|
|
64
64
|
entity: "STATE BANK OF INDIA",
|
|
65
65
|
confidence: 1,
|
|
66
|
-
confidenceLevel: "Trustable"
|
|
66
|
+
confidenceLevel: "Trustable",
|
|
67
|
+
input: "sbi"
|
|
67
68
|
}
|
|
68
69
|
*/
|
|
69
70
|
```
|
|
@@ -78,7 +79,7 @@ console.log(result);
|
|
|
78
79
|
Output:
|
|
79
80
|
{
|
|
80
81
|
entity: "ICICI BANK",
|
|
81
|
-
confidence: 0.
|
|
82
|
+
confidence: 0.71,
|
|
82
83
|
confidenceLevel: "Moderate Confidence"
|
|
83
84
|
}
|
|
84
85
|
*/
|
|
@@ -141,7 +142,7 @@ predictor.addEntity("PUNJAB NATIONAL BANK", ["PNB"]);
|
|
|
141
142
|
|
|
142
143
|
- `input`: String to search for.
|
|
143
144
|
- `threshold`: (Optional) Minimum confidence score (default `0.6`).
|
|
144
|
-
- **Returns**: Best match object
|
|
145
|
+
- **Returns**: Best match object `{ entity: string, confidence: number, input: string, ... }`, `{ entity: "UNKNOWN", input: string, ... }` if no match found, or `null` if input is invalid.
|
|
145
146
|
|
|
146
147
|
### `predictTop(input, limit, threshold)`
|
|
147
148
|
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/predictor.js
CHANGED
|
@@ -127,6 +127,7 @@ export class EntityPredictor {
|
|
|
127
127
|
entity: "UNKNOWN",
|
|
128
128
|
confidence: 0,
|
|
129
129
|
confidenceLevel: "Low Confidence",
|
|
130
|
+
input,
|
|
130
131
|
};
|
|
131
132
|
}
|
|
132
133
|
|
|
@@ -146,11 +147,12 @@ export class EntityPredictor {
|
|
|
146
147
|
const matches = findBestMatch(normalizedInput, this.searchCandidates);
|
|
147
148
|
|
|
148
149
|
// Map all ratings to our format and sort
|
|
149
|
-
const sortedMatches = matches
|
|
150
|
+
const sortedMatches = (matches?.ratings || [])
|
|
150
151
|
.map((rating, index) => ({
|
|
151
152
|
entity: this.candidateToEntity[index],
|
|
152
|
-
confidence: rating
|
|
153
|
-
confidenceLevel: this._getConfidenceLevel(rating
|
|
153
|
+
confidence: Number(rating?.rating?.toFixed(2)),
|
|
154
|
+
confidenceLevel: this._getConfidenceLevel(rating?.rating),
|
|
155
|
+
input,
|
|
154
156
|
}))
|
|
155
157
|
.filter((m) => m.confidence >= threshold)
|
|
156
158
|
.sort((a, b) => b.confidence - a.confidence);
|