- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
[Components] rosette_text_analytics #10937 #18441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            51 changes: 51 additions & 0 deletions
          
          51 
        
  components/rosette_text_analytics/actions/extract-entities/extract-entities.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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; | ||
| }, | ||
| }; | 
        
          
          
            39 changes: 39 additions & 0 deletions
          
          39 
        
  components/rosette_text_analytics/actions/match-names/match-names.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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; | ||
| }, | ||
| }; | 
        
          
          
            35 changes: 35 additions & 0 deletions
          
          35 
        
  components/rosette_text_analytics/actions/translate-name/translate-name.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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; | ||
| }, | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            106 changes: 101 additions & 5 deletions
          
          106 
        
  components/rosette_text_analytics/rosette_text_analytics.app.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
📝 Committable suggestion
🤖 Prompt for AI Agents