'Analyze Sentiments' is a Fiori app that helps you perform Sentiment Analysis on the topics that interest you. To learn more about the app, please go check out these links:
Ready to get your feet wet?!
Here are a few steps to add a chart control into a UI5 control that supports aggregations (like sap.m.List, etc) and to connect the OData service to this chart.
When you run the app, you will be able to see nice little charts added into each item in the aggregation that shows sentiment information.
Follow these steps to quickly integrate Sentiment Analysis capability into your already existing UI5 app:
1) Insert the chart into the appropriate location in your app. In the sample code below, the chart is embedded into a custom list item:
<List id="main_list" headerText="Vendors">
<items>
<CustomListItem>
<HBox justifyContent="SpaceAround">
<ObjectHeader title="playstation" />
<viz:VizFrame vizType="bar" uiConfig="{applicationSet:'fiori'}" height="250px" width="250px"> </viz:VizFrame>
</HBox>
</CustomListItem>
...
2) In the controller code on initialization, add the following code to fill data in the chart that we added into the UI in the previous step:
//Get the reference to the Odata service
var oModel = new sap.ui.model.odata.ODataModel("http://localhost:8080/ux.fnd.snta/proxy/http/lddbvsb.wdf.sap.corp:8000/sap/hba/apps/snta/s/odata/sntmntAnlys.xsodata/", true);
//Get the reference of the control where you want the charts embedded
var oList = this.getView().byId("main_list");
//This code gets the Subjectname from the control in which the chart is going to get embedded. You can see that the subjectname is extracted from the Title of the items in the list
for (var i = 0; i < oList.getItems().length; i++) {
var oChart = oList.getItems()[i].getContent()[0].getItems()[1];
var sItemName = oList.getItems()[i].getContent()[0].getItems()[0].getTitle();
//Now we set the data for each item in the list as per the subject that we extracted from the listitem.
oModel.read('/SrchTrmSntmntAnlysInSoclMdaChnlQry(P_SAPClient=\'' + self.sSAPClient + '\')/Results', null, ['$filter=SocialPostSearchTermText%20eq%20\'' + sItemName + "\' and " + "SocialPostCreationDate_E" + " ge datetime\'" + '2014-06-14' + '\'' + '&$select=Quarter,Year,SearchTermNetSntmntVal_E,NmbrOfNtrlSoclPostVal_E,NmbrOfNgtvSocialPostVal_E,NmbrOfPstvSocialPostVal_E'], false, function(oData, oResponse) {
oChart.setVizProperties({
interaction: {
selectability: {
mode: "single"
}
},
valueAxis: {
label: {
formatString: 'u'
}
},
legend: {
title: {
visible: false
}
},
title: {
visible: false
},
plotArea: {
dataLabel: {
visible: true
},
colorPalette: ['sapUiChartPaletteSemanticNeutral', 'sapUiChartPaletteSemanticBad', 'sapUiChartPaletteSemanticGood']
}
});
var oChartDataset = new sap.viz.ui5.data.FlattenedDataset({
measures: [{
name: "Neutral",
value: '{NmbrOfNtrlSoclPostVal_E}'
}, {
name: "Negative",
value: '{NmbrOfNgtvSocialPostVal_E}'
}, {
name: "Positive",
value: '{NmbrOfPstvSocialPostVal_E}'
}],
data: {
path: "/results"
}
});
oChart.setDataset(oChartDataset);
var oDim1 = new sap.viz.ui5.data.DimensionDefinition({
name: "Year",
value: '{Year}'
});
var oDim2 = new sap.viz.ui5.data.DimensionDefinition({
name: "Quarter",
value: '{Quarter}'
});
var oDataset = oChart.getDataset();
oDataset.addDimension(oDim1);
oDataset.addDimension(oDim2);
var oChartModel = new sap.ui.model.json.JSONModel(oData);
oChart.setModel(oChartModel);
oChart.setVizProperties({
valueAxis: {
title: {
visible: true,
text: "Mentions"
}
},
categoryAxis: {
title: {
visible: true,
text: "Quarter"
}
}
});
var feedValueAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "valueAxis",
'type': "Measure",
'values': ["Neutral", "Negative", "Positive"]
});
var feedCategoryAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "categoryAxis",
'type': "Dimension",
'values': [new sap.viz.ui5.controls.common.feeds.AnalysisObject({
'uid': "Year",
'type': "Dimension",
'name': "Year"
}),
new sap.viz.ui5.controls.common.feeds.AnalysisObject({
'uid': "Quarter",
'type': "Dimension",
'name': "Quarter"
})
]
});
oChart.addFeed(feedCategoryAxis);
oChart.addFeed(feedValueAxis);
}, function() {
sap.m.MessageBox.show("Odata failed", sap.m.MessageBox.Icon.ERROR, "Error", [
sap.m.MessageBox.Action.CLOSE
]);
});
}
PS: Depending on how you add the chart into your app, the above chunk of code will have to be adjusted to get the subjectname and pass it to the chart.
In the above sample code, you can find that the chart in each custom list item is bound to data in a loop. If you have added the chart in a similar control with an aggregation, you would have to modify the lines highlighted above to get the list control and to get the chart reference and searchterm.
Here’s some more information on our existing Odata services for Analyze Sentiments and some ideas how you can use it in your apps.
Collection | What information it gives out |
SocialMediaChannelsQuery | List of Channels (code and name) |
SocialPostSearchTermsQuery | List of Searchterms (code and name) |
SrchTrmSntmntAnlysInSoclMdaChnlQry | List of (number of mentions, number of positive, negative & neutral mentions, ‘netsentiment value’) for a searchterm given out in daily/weekly/monthly/quarterly/yearly period granularity |
SrchTrmSntmntAnlysSclPstDtlsQry | List of socialposts for a searchterm in a period |
SrchTrmSntmntTrendInSoclMdaChnlQry | Net sentiment trend in percentage for a searchterm over a specified period. |
PS: The last three services retrieves data for all subjects when filter is not applied on searchterms.
Calculations used:
Net sentiment = P - N
P = sum of weights of positive posts. The weight could be +1(good), +2(very good)
N = sum of weights of negative posts. The weight can be -1(bad), -2(very bad)
Net sentiment trend percentage = (Net sentiment in last n days – Net sentiment in previous n days) / Net sentiment in previous n days.
So on the whole, we have the following information:
i) Number of positive, negative, neutral, total mentions about a Subject
ii) Net sentiment about a subject
iii) Net sentiment trend about a subject which is a percentage.
Here are some sample ways in which the external apps can right away start using our Odata assets:
Use | Control that can be used | Collection to be used |
Show the numbers (total, positive, negative neutral mentions or netsentiment) related to a subject | Label | SrchTrmSntmntAnlysInSoclMdaChnlQry |
Show the socialposts related to a subject | Table, list, etc | SrchTrmSntmntAnlysSclPstDtlsQry |
Show the net sentiment trend of a subject | Label | SrchTrmSntmntTrendInSoclMdaChnlQry |
Show chart/graph with the numbers over a period | Chart | SrchTrmSntmntAnlysInSoclMdaChnlQry |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
4 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |