{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":915,"path":"api-reference/server-api-reference/SentimentAnalyserScoped.md","title":"SentimentAnalyser - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# SentimentAnalyser- Scoped\n\nThe SentimentAnalyser script include provides methods to perform sentiment analysis on a string value.\n\nYou should use this script include in a script that is treated as an admin-executing script. For example, use the Sentiment Analysis script includein a script action or scheduled job.\n\nTo use this class in a scoped application, use the `sn_nlp_sentiment` namespace identifier. The Sentiment Analysis plugin \\(com.snc.sentiment\\_analysis\\) must be enabled to access the SentimentAnalyser API.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## SentimentAnalyser - SentimentAnalyser\\(\\)\n\nCreates an instance of the SentimentAnalyser class with the default connector configuration that is used for sentiment analysis.\n\n```\nvar sa = new sn_nlp_sentiment.SentimentAnalyser();\n```\n\n## SentimentAnalyser - SentimentAnalyser\\(GlideRecord configGR\\)\n\nCreates an instance of the SentimentAnalyser class with the specified connector configuration that is used for sentiment analysis.\n\n|Name|Type|Description|\n|----|----|-----------|\n|configGR|GlideRecord|GlideRecord object of a connector configuration.|\n\n```\nvar sa = new sn_nlp_sentiment.SentimentAnalyser(configGR);\n```\n\n## SentimentAnalyser - analyze\\(String inputText\\)\n\nPerforms sentiment analysis on the specified text.\n\n|Name|Type|Description|\n|----|----|-----------|\n|inputText|String|Text on which sentiment analysis should be performed.|\n\n|Type|Description|\n|----|-----------|\n|JSON object|Result of the sentiment analysis specifying the status, score, normalised score, sys\\_id of the relevant connector configuration, and error message.|\n\n```\n\n        var sa = new sn_nlp_sentiment.SentimentAnalyser();\n        var result = sa.analyze (\"Example string\");\n```\n\nOutput:\n\n```\n{\"status\": \"Success\", \"score\": \"0.7\", \"normalizedScore\": \"0.7\", \"connectorConfig\": \"10932aa773101300734e234ffff6a777\", \"errorMessage\":\"\"}\n```\n\n## SentimentAnalyser - analyzeMultiple\\(Array inputTextArray\\)\n\nPerforms sentiment analysis on an array of strings.\n\n|Name|Type|Description|\n|----|----|-----------|\n|inputTextArray|Array|Array of text \\(string\\) on which to perform sentiment analysis.|\n\n|Type|Description|\n|----|-----------|\n|JSON Array|An array that gives the result of the sentiment analysis performed on multiple texts specifying the status, score, normalized score, sys\\_id of the relevant connector configuration, and error message.|\n\n```\nvar sa = new sn_nlp_sentiment.SentimentAnalyser();\nvar result = sa.analyzeMultiple ([\"Example string1\",\"Example string2\"]);\n```\n\nOutput:\n\n```\n[{\"text\": \"I am happy\",\"result\": {Success\", \"score\": \"0.7\", \"normalizedScore\": \"0.7\", \"connectorConfig\": \"10932aa773101300734e234ffff6a777\", \"errorMessage\":\"\"}},{\"text\": \"I am not happy\",\"result\": {Success\", \"score\": \"-0.7\", \"normalizedScore\": \"-0.7\", \"connectorConfig\": \"10932aa773101300734e234ffff6a777\", \"errorMessage\":\"\"}}]\n```\n\n## SentimentAnalyser - analyzeMultipleWithLanguage\\(Array inputTextArray, String language\\)\n\nPerforms sentiment analysis on an array of strings in the specified language.\n\n|Name|Type|Description|\n|----|----|-----------|\n|inputTextArray|Array|Array of text \\(string\\) on which to perform sentiment analysis.|\n|language|String|Language for the input text. This can very for different sentiment services.|\n\n|Type|Description|\n|----|-----------|\n|JSON Array|An array with the result of the sentiment analysis performed on multiple texts of the mentioned language, specifying the status, score, normalized score, sys\\_id of the relevant connector configuration, and error message.|\n\n```\nvar sa = new sn_nlp_sentiment.SentimentAnalyser();\nvar result = sa.analyzeMultipleWithLanguage ([\"Example string1\",\"Example string2\"], \"en\");\n```\n\nOutput:\n\n```\n[{\"text\": \"I am happy\",\"result\": {Success\", \"score\": \"0.7\", \"normalizedScore\": \"0.7\", \"connectorConfig\": \"10932aa773101300734e234ffff6a777\", \"errorMessage\":\"\"}},{\"text\": \"I am not happy\",\"result\": {Success\", \"score\": \"-0.7\", \"normalizedScore\": \"-0.7\", \"connectorConfig\": \"10932aa773101300734e234ffff6a777\", \"errorMessage\":\"\"}}]\n```\n\n## SentimentAnalyser - analyzeWithLanguage\\(String inputText, String language\\)\n\nPerforms sentiment analysis on a specified text and language.\n\n|Name|Type|Description|\n|----|----|-----------|\n|inputText|String|Text on which to perform sentiment analysis.|\n|language|String|Language for the input text. This can vary for different sentiment services.|\n\n|Type|Description|\n|----|-----------|\n|JSON object|Result of the sentiment analysis specifying the status, score, normalized score, sys\\_id of the relevant connector configuration, and error message.|\n\n```\nvar sa = new sn_nlp_sentiment.SentimentAnalyser();\nvar result = sa.analyze (\"Example string\", \"en\");\n```\n\nOutput:\n\n```\n{\"status\": \"Success\", \"score\": \"0.7\", \"normalizedScore\": \"0.7\", \"connectorConfig\": \"10932aa773101300734e234ffff6a777\", errorMessage\":\"\"}\n```\n\n## SentimentAnalyser - getConnectorByName\\(String connectorName\\)\n\nReturns the GlideRecord of the specified connector configuration.\n\n|Name|Type|Description|\n|----|----|-----------|\n|connectorName|String|Name of the connector configuration.|\n\n|Type|Description|\n|----|-----------|\n|GlideRecord|GlideRecord of the specified connector configuration.|\n\n```\nvar sa = new sn_nlp_sentiment.SentimentAnalyser();\nvar connector = sa.getConnectorByName(\"xxx\");\n```\n\nOutput:\n\n```\nGlideRecord object of the connector configuration with name \"xxx\", null if no connector is named as \"xxx\".\n\n```\n\n## SentimentAnalyser - getDefaultConnector\\(\\)\n\nReturns the GlideRecord of the default connector configuration.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideRecord|GlideRecord of the default connector configuration.|\n\n```\nvar sa = new sn_nlp_sentiment.SentimentAnalyser();\nvar defaultConnector = sa.getDefaultConnector();\n```\n\n"}}