Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import app from "../../rosette_text_analytics.app.mjs";

export default {
key: "rosette_text_analytics-extract-entities",
name: "Extract Entities",
description: "Extract entities from content using Rosette. [See the documentation](https://documentation.babelstreet.com/analytics/text-analytics/entity-extractor/extract-entities)",
version: "0.0.1",
type: "action",
props: {
app,
content: {
propDefinition: [
app,
"content",
],
},
calculateConfidence: {
propDefinition: [
app,
"calculateConfidence",
],
},
calculateSalience: {
propDefinition: [
app,
"calculateSalience",
],
},
includeDBpediaTypes: {
propDefinition: [
app,
"includeDBpediaTypes",
],
},
},
async run({ $ }) {
const response = await this.app.extractEntities({
$,
data: {
content: this.content,
options: {
calculateConfidence: this.calculateConfidence,
calculateSalience: this.calculateSalience,
includeDBpediaTypes: this.includeDBpediaTypes,
},
},
});
$.export("$summary", "Successfully extracted " + response.entities.length + " entities");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import app from "../../rosette_text_analytics.app.mjs";

export default {
key: "rosette_text_analytics-match-names",
name: "Match Names",
description: "Compare two names using Rosette. [See the documentation](https://documentation.babelstreet.com/analytics/match-names/name-similarity/match-names)",
version: "0.0.1",
type: "action",
props: {
app,
nameOne: {
propDefinition: [
app,
"nameOne",
],
},
nameTwo: {
propDefinition: [
app,
"nameTwo",
],
},
},
async run({ $ }) {
const response = await this.app.matchName({
$,
data: {
name1: {
text: this.nameOne,
},
name2: {
text: this.nameTwo,
},
},
});
$.export("$summary", "Successfully compared names, resulting in a score of " + response.score);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import app from "../../rosette_text_analytics.app.mjs";

export default {
key: "rosette_text_analytics-translate-name",
name: "Translate Name",
description: "Translate name using Rosette. [See the documentation](https://documentation.babelstreet.com/analytics/match-names/name-translation/translate-names)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
propDefinition: [
app,
"name",
],
},
targetLanguage: {
propDefinition: [
app,
"targetLanguage",
],
},
},
async run({ $ }) {
const response = await this.app.translateName({
$,
data: {
name: this.name,
targetLanguage: this.targetLanguage,
},
});
$.export("$summary", "Successfully translated name with " + response.confidence + " confidence");
return response;
Comment on lines +25 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix request payload shape for Rosette translate API (wrap name in { text }).
Rosette APIs expect name fields as objects with a text property. Sending a string will likely 400. Also, make the summary robust to missing fields.

Apply this diff:

-    const response = await this.app.translateName({
-      $,
-      data: {
-        name: this.name,
-        targetLanguage: this.targetLanguage,
-      },
-    });
-    $.export("$summary", "Successfully translated name with " + response.confidence + " confidence");
-    return response;
+    const response = await this.app.translateName({
+      $,
+      data: {
+        name: { text: this.name },
+        targetLanguage: this.targetLanguage,
+      },
+    });
+    $.export(
+      "$summary",
+      `Translated ${this.name} to ${this.targetLanguage}` +
+        (response?.translatedName ? `: ${response.translatedName}` : "") +
+        (typeof response?.confidence === "number" ? ` (confidence: ${response.confidence})` : "")
+    );
+    return response;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const response = await this.app.translateName({
$,
data: {
name: this.name,
targetLanguage: this.targetLanguage,
},
});
$.export("$summary", "Successfully translated name with " + response.confidence + " confidence");
return response;
const response = await this.app.translateName({
$,
data: {
name: { text: this.name },
targetLanguage: this.targetLanguage,
},
});
$.export(
"$summary",
`Translated ${this.name} to ${this.targetLanguage}` +
(response?.translatedName ? `: ${response.translatedName}` : "") +
(typeof response?.confidence === "number" ? ` (confidence: ${response.confidence})` : "")
);
return response;
🤖 Prompt for AI Agents
In components/rosette_text_analytics/actions/translate-name/translate-name.mjs
around lines 25 to 33, the payload sends name as a raw string but Rosette
expects name fields as an object with a text property; change the request data
to send name: { text: this.name } (keep targetLanguage unchanged), and make the
exported summary robust by handling missing response.confidence (e.g., default
to 'unknown' or similar) so the summary string never breaks.

},
};
5 changes: 4 additions & 1 deletion components/rosette_text_analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/rosette_text_analytics",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Rosette Text Analytics Components",
"main": "rosette_text_analytics.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
106 changes: 101 additions & 5 deletions components/rosette_text_analytics/rosette_text_analytics.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,107 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "rosette_text_analytics",
propDefinitions: {},
propDefinitions: {
nameOne: {
type: "string",
label: "Name One",
description: "Primary name for comparison or translation",
},
nameTwo: {
type: "string",
label: "Name Two",
description: "Secondary name for comparison",
},
name: {
type: "string",
label: "Name",
description: "Name to be translated",
},
targetLanguage: {
type: "string",
label: "Target Language",
description: "Target language code for translation or analysis",
async options() {
const response = await this.getLanguages();
const languages = response.supportedLanguagePairs;
return languages.map(({ target }) => ({
label: target.language,
value: target.language,
}));
},
},
content: {
type: "string",
label: "Content",
description: "Text content to extract entities from",
},
calculateConfidence: {
type: "boolean",
label: "Calculate Confidence",
description: "Include confidence scores in entity extraction results",
optional: true,
},
calculateSalience: {
type: "boolean",
label: "Calculate Salience",
description: "Include salience values indicating entity relevance",
optional: true,
},
includeDBpediaTypes: {
type: "boolean",
label: "Include DBpedia Types",
description: "Include DBpedia types associated with extracted entities",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.rosette.com/rest";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
"X-RosetteAPI-Key": `${this.$auth.api_key}`,
...headers,
},
});
},
async matchName(args = {}) {
return this._makeRequest({
path: "/v1/name-similarity",
method: "post",
...args,
});
},
async translateName(args = {}) {
return this._makeRequest({
path: "/v1/name-translation",
method: "post",
...args,
});
},
async extractEntities(args = {}) {
return this._makeRequest({
path: "/v1/entities",
method: "post",
...args,
});
},
async getLanguages(args = {}) {
return this._makeRequest({
path: "/v1/name-translation/supported-languages",
...args,
});
},
},
};
};
Loading