Last active
October 1, 2018 10:11
-
-
Save serban-petrescu/28756af0c088b7bacc2985a54c089b65 to your computer and use it in GitHub Desktop.
HANA XSC Simple TA Service
This file contains 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
function sentiment(sentiment) { | |
if (sentiment && sentiment.label) { | |
switch(sentiment.label) { | |
case "StrongNegativeSentiment": | |
case "StrongNegativeEmoticon": | |
return { | |
startIndex: sentiment.offset, | |
endIndex: sentiment.offset + sentiment.text.length, | |
text: sentiment.text, | |
type: "NEGATIVE", | |
strong: true | |
}; | |
case "WeakNegativeSentiment": | |
case "WeakNegativeEmoticon": | |
return { | |
startIndex: sentiment.offset, | |
endIndex: sentiment.offset + sentiment.text.length, | |
text: sentiment.text, | |
type: "NEGATIVE", | |
strong: false | |
}; | |
case "StrongPositiveSentiment": | |
case "StrongPositiveEmoticon": | |
return { | |
startIndex: sentiment.offset, | |
endIndex: sentiment.offset + sentiment.text.length, | |
text: sentiment.text, | |
type: "POSITIVE", | |
strong: true | |
}; | |
case "WeakPositiveSentiment": | |
case "WeakPositiveEmoticon": | |
return { | |
startIndex: sentiment.offset, | |
endIndex: sentiment.offset + sentiment.text.length, | |
text: sentiment.text, | |
type: "POSITIVE", | |
strong: false | |
}; | |
case "NeutralSentiment": | |
case "NeutralEmoticon": | |
return { | |
startIndex: sentiment.offset, | |
endIndex: sentiment.offset + sentiment.text.length, | |
text: sentiment.text, | |
type: "NEUTRAL", | |
strong: false | |
}; | |
} | |
} | |
return null; | |
} | |
function notNull(object) { | |
return object !== null; | |
} | |
var TA = new $.text.analysis.Session({configuration: "sap.hana.ta.config::EXTRACTION_CORE_VOICEOFCUSTOMER.hdbtextconfig"}); | |
var result = TA.analyze({ | |
inputDocumentText: $.request.parameters.get("text") || "" | |
}); | |
var sentiments = result.entities.map(sentiment).filter(notNull); | |
$.response.contentType = "application/json"; | |
$.response.setBody(JSON.stringify(sentiments)); | |
$.response.status = $.net.http.OK; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment