소스 검색

Add ontology/ request

jmacura 4 년 전
부모
커밋
71d96578cd
2개의 변경된 파일20개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      index.js
  2. 10 0
      nuts-data.js

+ 10 - 0
index.js

@@ -17,6 +17,7 @@ const _clusteringEuModifiedFilePath = 'data/clustering/input_modified.csv';
 const _clusteringCzModifiedFilePath = 'data/cz/input_modified.csv';
 const _clustersEuFilePath = 'data/clustering/out_file.csv';
 const _clustersCzFilePath = 'data/cz/out_file_cz.csv';
+const _ontologyFilePath = 'data/rural_attractiveness.owl.json';
 var _datasetsEU = undefined;
 var _datasetsCZ = undefined;
 var _ruralDataEU = undefined;
@@ -155,6 +156,15 @@ app.post('/:aoi?/clusters/', async (req, res, next) => {
   }
 });
 
+/*
+ * Reads the ontology file and sends its content
+ * This ensures that both backend and frontend are using the same version of the ontology
+*/
+app.get('/ontology/', async (req, res, next) => {
+  const onto = await nutsData.loadOntology(_ontologyFilePath)
+  helpers.formatResponse(onto, req, res)
+});
+
 app.get('/georeport/:nuts', async (req, res, next) => {
   if (!_datasetsEU) { // datasets must be loaded prior to data loading
     try {

+ 10 - 0
nuts-data.js

@@ -84,6 +84,16 @@ module.exports.loadRuralData = async function (filePath, datasets) {
     })
 }
 
+module.exports.loadOntology = async function(filePath) {
+    return new Promise((resolve, reject) => {
+        fs.readFile(filePath, (err, data) => {
+            if (err) reject(err)
+            const ontology = JSON.parse(data)
+            resolve(ontology)
+        })
+    })
+}
+
 /**
  * Resolves with an array representing rows of CSV file
  * @param {string} inputFileName path to the CSV file with input data for clustering calculation