-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSettings.gs
207 lines (171 loc) · 7.97 KB
/
Settings.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// OntoMaton is a component of the ISA software suite (http://www.isa-tools.org)
//
// License:
// OntoMaton is licensed under the Common Public Attribution License version 1.0 (CPAL)
//
// EXHIBIT A. CPAL version 1.0
// “The contents of this file are subject to the CPAL version 1.0 (the “License”);
// you may not use this file except in compliance with the License. You may obtain a
// copy of the License at http://isatab.sf.net/licenses/OntoMaton-license.html.
// The License is based on the Mozilla Public License version 1.1 but Sections
// 14 and 15 have been added to cover use of software over a computer network and
// provide for limited attribution for the Original Developer. In addition, Exhibit
// A has been modified to be consistent with Exhibit B.
//
// Software distributed under the License is distributed on an “AS IS” basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
// the specific language governing rights and limitations under the License.
//
// The Original Code is OntoMaton.
// The Original Developer is the Initial Developer. The Initial Developer of the
// Original Code is the ISA Team (Eamonn Maguire, [email protected];
// Philippe Rocca-Serra, [email protected]; Susanna-Assunta Sansone, [email protected]; Alejandra Gonzalez-Beltran, [email protected]
// http://www.isa-tools.org). All portions of the code written by the ISA Team are
// Copyright (c) 2007-2020 ISA Team. All Rights Reserved.
//
// EXHIBIT B. Attribution Information
// Attribution Copyright Notice: Copyright (c) 2007-2020 ISA Team
// Attribution Phrase: Developed by the ISA Team
// Attribution URL: http://www.isa-tools.org
// Graphic Image provided in the Covered Code as file: http://isatab.sf.net/assets/img/tools/ontomaton-part-of-isatools.png
// Display of Attribution Information is required in Larger Works which are defined in the CPAL as a work which combines Covered Code or portions thereof with code not governed by the terms of the CPAL.
function showSettings() {
var html = HtmlService.createHtmlOutputFromFile('Settings-Template').setTitle('OntoMaton - Ontology Search & Tagging').setWidth(300);
createSettingsTab();
SpreadsheetApp.getUi().showSidebar(html);
}
function loadOntologies() {
return {
'BioPortal': getBioPortalOntologies(),
'LOV': getLinkedOpenVocabularies(),
'OLS': getOLSOntologies()
}
}
function createSettingsTab() {
var settingsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Settings");
if (settingsSheet == undefined) {
var activeSheet = SpreadsheetApp.getActiveSheet();
settingsSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet("Settings");
settingsSheet.getRange("A1").setValue("insertTermInOneColumn");
settingsSheet.getRange("B1").setValue(true);
SpreadsheetApp.getActiveSpreadsheet().setActiveSheet(activeSheet);
}
}
function viewRestrictionHandler() {
var restrictionSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Restrictions");
if (restrictionSheet == undefined) {
UiApp.getActiveApplication().getElementById("status").setText("Restriction sheet doesn't exist yet. Add a restriction and it will be created automatically.");
return UiApp.getActiveApplication();
} else {
SpreadsheetApp.getActiveSpreadsheet().setActiveSheet(restrictionSheet);
}
}
function loadPreferences() {
var settingsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Settings");
if (settingsSheet != undefined) {
var settingsValue = settingsSheet.getRange("B1").getValue();
return settingsValue;
}
return true;
}
function addRestrictionHandler(params) {
var ontology = params.ontology.trim();
var columnName = params.columnName.trim();
var service = params.service.trim();
var restrictionSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Restrictions");
if (restrictionSheet == undefined) {
var activeSheet = SpreadsheetApp.getActiveSheet();
restrictionSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet("Restrictions");
restrictionSheet.getRange("A1").setValue("Column Name");
restrictionSheet.getRange("B1").setValue("Ontology");
restrictionSheet.getRange("C1").setValue("Branch");
restrictionSheet.getRange("D1").setValue("Version");
restrictionSheet.getRange("E1").setValue("Ontology Name");
restrictionSheet.getRange("F1").setValue("Service");
SpreadsheetApp.getActiveSpreadsheet().setActiveSheet(activeSheet);
}
if(columnName !== "") {
var nextBlankRow = findNextBlankRow(restrictionSheet);
restrictionSheet.getRange(nextBlankRow, 1).setValue(columnName);
restrictionSheet.getRange(nextBlankRow, 2).setValue(ontology.substring(0, ontology.indexOf(" - ")));
restrictionSheet.getRange(nextBlankRow, 5).setValue(ontology.substring(ontology.indexOf(" - ") + 3));
restrictionSheet.getRange(nextBlankRow, 6).setValue(service);
return "Restriction for " + columnName + " Added"
}
return "Column name cannot be empty."
}
function setOntologyInsertionPreference(insertSingleColumn) {
var settingsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Settings");
settingsSheet.getRange("B1").setValue(insertSingleColumn);
}
function getBioPortalOntologies() {
var searchString = "http://data.bioontology.org/ontologies?apikey=fd88ee35-6995-475d-b15a-85f1b9dd7a42&display_links=false&display_context=false";
// we cache results and try to retrieve them on every new execution.
var cache = CacheService.getPrivateCache();
var text;
if (cache.get("bioportal_fragments") == null) {
text = UrlFetchApp.fetch(searchString).getContentText();
splitResultAndCache(cache, "bioportal_fragments", text);
} else {
text = getCacheResultAndMerge(cache, "bioportal_fragments");
}
var doc = JSON.parse(text);
var ontologies = doc;
var ontologyDictionary = {};
for (ontologyIndex in doc) {
var ontology = doc[ontologyIndex];
ontologyDictionary[ontology.acronym] = {"name":ontology.name, "uri":ontology["@id"]};
}
return ontologyDictionary;
}
function getLinkedOpenVocabularies(){
var vocabsURL = "http://lov.okfn.org/dataset/lov/api/v2/vocabulary/list";
var cache = CacheService.getPrivateCache();
if (cache.get("lov_fragments") == null) {
var vocabsResponse = UrlFetchApp.fetch(vocabsURL);
var text = vocabsResponse.getContentText();
splitResultAndCache(cache, "lov", text);
} else {
text = getCacheResultAndMerge(cache, "lov");
}
vocabularies = JSON.parse(text);
var vocabularyDictionary = {};
for (vocabularyIndex in vocabularies) {
var vocabulary = vocabularies[vocabularyIndex];
vocabularyDictionary[vocabulary.prefix] = {"name":vocabulary.titles[0].value, "uri":vocabulary.uri};
}
return vocabularyDictionary;
}
/**
* @method
* @name getOLSOntologies
* @description gets all the ontologies from OLS
* @return{Object}
*/
function getOLSOntologies() {
var ontologiesUri = OLS_API_BASE_URI + "/ontologies?size=" + OLS_PAGINATION_SIZE;
var cache = CacheService.getPrivateCache(), res, text, json, ontologies = [];
if (cache.get("ols") == null) {
do {
res = UrlFetchApp.fetch(ontologiesUri);
text = res.getContentText('utf-8');
json = JSON.parse(text);
ontologies = ontologies.concat(json._embedded.ontologies);
ontologiesUri = json._links && json._links.next && json._links.next.href;
}
while (ontologiesUri);
// store into cache the result as plain text
splitResultAndCache(cache, "ols", JSON.stringify(ontologies));
} else {
ontologies = JSON.parse(getCacheResultAndMerge(cache, "ols"));
}
var ontologyDict = {};
ontologies.forEach(function(ontology) {
var config = ontology.config || {};
ontologyDict[ontology.ontologyId] = {
name: config.title,
uri: config.id
};
});
return ontologyDict;
}