Skip to content

Commit d68af40

Browse files
author
Andreas Eisenkolb
committed
restyling of the result list
1 parent 6206ea1 commit d68af40

2 files changed

Lines changed: 261 additions & 38 deletions

File tree

Code.gs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/* Copyright 2014 University of Passau
2-
32
Licensed under the Apache License, Version 2.0 (the "License");
43
you may not use this file except in compliance with the License.
54
You may obtain a copy of the License at
6-
75
http://www.apache.org/licenses/LICENSE-2.0
8-
96
Unless required by applicable law or agreed to in writing, software
107
distributed under the License is distributed on an "AS IS" BASIS,
118
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -39,17 +36,12 @@ function onInstall(e) {
3936
onOpen(e);
4037
}
4138

42-
function onEdit(event)
43-
{
44-
Logger.log("Last modified: " + (new Date()));
45-
}
46-
4739
/**
4840
* Opens a sidebar in the document containing the add-on's user interface.
4941
*/
5042
function showSidebar() {
5143
var ui = HtmlService.createHtmlOutputFromFile('Sidebar')
52-
.setTitle('EEXCESS');
44+
.setTitle('Recommendations');
5345
DocumentApp.getUi().showSidebar(ui);
5446
}
5547

@@ -61,9 +53,11 @@ function showSidebar() {
6153
*/
6254
function getSelectedText() {
6355
var selection = DocumentApp.getActiveDocument().getSelection();
56+
6457
if (selection) {
6558
var text = [];
6659
var elements = selection.getRangeElements();
60+
6761
for (var i = 0; i < elements.length; i++) {
6862
if (elements[i].isPartial()) {
6963
var element = elements[i].getElement().asText();
@@ -94,15 +88,34 @@ function getSelectedText() {
9488
}
9589
}
9690

91+
/**
92+
* Gets the recommendations from the entered text.
93+
*
94+
* @param {String} text The text entered by the user.
95+
*
96+
* @return {String} The response as JSON string.
97+
*/
98+
function getRecommandationsFromInput(text) {
99+
return callProxy(getTerms([text]));
100+
}
101+
97102
/**
98103
* Gets the recommendations from the selected user text.
99104
*
100105
* @return {String} The response as JSON string.
101106
*/
102107
function getRecommendations() {
103-
104-
var text = getSelectedText();
105-
108+
return callProxy(getTerms(getSelectedText()));
109+
}
110+
111+
/**
112+
* Gets the recommendations from the selected user text.
113+
*
114+
* @param {Array<String>} text The text entered by the user as array.
115+
*
116+
* @return {Array<String>} The terms as an array.
117+
*/
118+
function getTerms(text) {
106119
var terms = [];
107120

108121
// Split the text into terms
@@ -113,14 +126,25 @@ function getRecommendations() {
113126
terms.push(tmp[i].replace(/\s/g, "").replace(/[\.,#-\/!$%\^&\*;:{}=\-_`~()]/g,""));
114127
}
115128
}
129+
130+
return terms;
131+
}
132+
133+
/**
134+
* Calls the privacy proxy
135+
*
136+
* @param {Array<String>} terms The single terms.
137+
*
138+
* @return {String} The response as JSON string.
139+
*/
140+
function callProxy(terms) {
116141
// privacy proxy URL
117142
var url = "http://eexcess.joanneum.at/eexcess-privacy-proxy/api/v1/recommend";
118143
// federated recommender
119144
//var url = "http://eexcess.joanneum.at/eexcess-federated-recommender-web-service-1.0-SNAPSHOT/recommender/recommend";
120145

121146
// POST payload
122147
var data = { "numResults" : 60, "contextKeywords" : [] };
123-
124148

125149
// Fill the context array
126150
for(i in terms) {
@@ -137,11 +161,11 @@ function getRecommendations() {
137161
},
138162
"payload" : JSON.stringify(data)
139163
};
140-
141164
try {
142165
var response = UrlFetchApp.fetch(url, options);
143166
return response.getContentText();
144167
} catch(err) {
145168
throw err;
146169
}
147-
}
170+
171+
}

0 commit comments

Comments
 (0)