Skip to content

Commit 1d2cce5

Browse files
committed
Added actions
1 parent 0c007db commit 1d2cce5

File tree

5 files changed

+227
-6
lines changed

5 files changed

+227
-6
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import app from "../../rosette_text_analytics.app.mjs";
2+
3+
export default {
4+
key: "rosette_text_analytics-extract-entities",
5+
name: "Extract Entities",
6+
description: "Extract entities from content using Rosette. [See the documentation](https://documentation.babelstreet.com/analytics/text-analytics/entity-extractor/extract-entities)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
content: {
12+
propDefinition: [
13+
app,
14+
"content",
15+
],
16+
},
17+
calculateConfidence: {
18+
propDefinition: [
19+
app,
20+
"calculateConfidence",
21+
],
22+
},
23+
calculateSalience: {
24+
propDefinition: [
25+
app,
26+
"calculateSalience",
27+
],
28+
},
29+
includeDBpediaTypes: {
30+
propDefinition: [
31+
app,
32+
"includeDBpediaTypes",
33+
],
34+
},
35+
},
36+
async run({ $ }) {
37+
const response = await this.app.extractEntities({
38+
$,
39+
data: {
40+
content: this.content,
41+
options: {
42+
calculateConfidence: this.calculateConfidence,
43+
calculateSalience: this.calculateSalience,
44+
includeDBpediaTypes: this.includeDBpediaTypes,
45+
},
46+
},
47+
});
48+
$.export("$summary", "Successfully extracted " + response.entities.length + " entities");
49+
return response;
50+
},
51+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import app from "../../rosette_text_analytics.app.mjs";
2+
3+
export default {
4+
key: "rosette_text_analytics-match-names",
5+
name: "Match Names",
6+
description: "Compare two names using Rosette. [See the documentation](https://documentation.babelstreet.com/analytics/match-names/name-similarity/match-names)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
nameOne: {
12+
propDefinition: [
13+
app,
14+
"nameOne",
15+
],
16+
},
17+
nameTwo: {
18+
propDefinition: [
19+
app,
20+
"nameTwo",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.matchName({
26+
$,
27+
data: {
28+
name1: {
29+
text: this.nameOne,
30+
},
31+
name2: {
32+
text: this.nameTwo,
33+
},
34+
},
35+
});
36+
$.export("$summary", "Successfully compared names, resulting in a score of " + response.score);
37+
return response;
38+
},
39+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import app from "../../rosette_text_analytics.app.mjs";
2+
3+
export default {
4+
key: "rosette_text_analytics-translate-name",
5+
name: "Translate Name",
6+
description: "Translate name using Rosette. [See the documentation](https://documentation.babelstreet.com/analytics/match-names/name-translation/translate-names)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"name",
15+
],
16+
},
17+
targetLanguage: {
18+
propDefinition: [
19+
app,
20+
"targetLanguage",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.translateName({
26+
$,
27+
data: {
28+
name: this.name,
29+
targetLanguage: this.targetLanguage,
30+
},
31+
});
32+
$.export("$summary", "Successfully translated name with " + response.confidence + " confidence");
33+
return response;
34+
},
35+
};

components/rosette_text_analytics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/rosette_text_analytics",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Rosette Text Analytics Components",
55
"main": "rosette_text_analytics.app.mjs",
66
"keywords": [
Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,107 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "rosette_text_analytics",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
nameOne: {
8+
type: "string",
9+
label: "Name One",
10+
description: "Primary name for comparison or translation",
11+
},
12+
nameTwo: {
13+
type: "string",
14+
label: "Name Two",
15+
description: "Secondary name for comparison",
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "Name to be translated",
21+
},
22+
targetLanguage: {
23+
type: "string",
24+
label: "Target Language",
25+
description: "Target language code for translation or analysis",
26+
async options() {
27+
const response = await this.getLanguages();
28+
const languages = response.supportedLanguagePairs;
29+
return languages.map(({ target }) => ({
30+
label: target.language,
31+
value: target.language,
32+
}));
33+
},
34+
},
35+
content: {
36+
type: "string",
37+
label: "Content",
38+
description: "Text content to extract entities from",
39+
},
40+
calculateConfidence: {
41+
type: "boolean",
42+
label: "Calculate Confidence",
43+
description: "Include confidence scores in entity extraction results",
44+
optional: true,
45+
},
46+
calculateSalience: {
47+
type: "boolean",
48+
label: "Calculate Salience",
49+
description: "Include salience values indicating entity relevance",
50+
optional: true,
51+
},
52+
includeDBpediaTypes: {
53+
type: "boolean",
54+
label: "Include DBpedia Types",
55+
description: "Include DBpedia types associated with extracted entities",
56+
optional: true,
57+
},
58+
},
559
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
60+
_baseUrl() {
61+
return "https://api.rosette.com/rest";
62+
},
63+
async _makeRequest(opts = {}) {
64+
const {
65+
$ = this,
66+
path,
67+
headers,
68+
...otherOpts
69+
} = opts;
70+
return axios($, {
71+
...otherOpts,
72+
url: this._baseUrl() + path,
73+
headers: {
74+
"X-RosetteAPI-Key": `${this.$auth.api_key}`,
75+
...headers,
76+
},
77+
});
78+
},
79+
async matchName(args = {}) {
80+
return this._makeRequest({
81+
path: "/v1/name-similarity",
82+
method: "post",
83+
...args,
84+
});
85+
},
86+
async translateName(args = {}) {
87+
return this._makeRequest({
88+
path: "/v1/name-translation",
89+
method: "post",
90+
...args,
91+
});
92+
},
93+
async extractEntities(args = {}) {
94+
return this._makeRequest({
95+
path: "/v1/entities",
96+
method: "post",
97+
...args,
98+
});
99+
},
100+
async getLanguages(args = {}) {
101+
return this._makeRequest({
102+
path: "/v1/name-translation/supported-languages",
103+
...args,
104+
});
9105
},
10106
},
11-
};
107+
};

0 commit comments

Comments
 (0)