Skip to content
Snippets Groups Projects
Commit 109f93c8 authored by Erkan Karabulut's avatar Erkan Karabulut
Browse files

change "taxonomy" to "ontology"

parent a3a0e3a0
No related branches found
No related tags found
No related merge requests found
Taxonomy:
Domain:
Health:
Hospital:
- Hospital
Nursing Home:
- Nursing Home
Private Home:
- Private Home
Logistics:
Warehouse:
- Warehouse
Transport:
- Transport
Agriculture:
Irrigation:
- Irrigation
Livestock:
- Livestock
Crop:
- Crop
Smart City:
Public Building:
- Public Building
Mobility:
- Mobility
Green Space:
- Green Space
Environment:
- Environment
Energy:
- Energy
Building Management:
Hospitality:
- Hospitality
Private Home:
- Private Home
Offices:
- Offices
Retail:
- Retail
Manufacturing:
Facility:
- Facility
Equipment:
- Equipment
Monitoring Aspect:
Objects/Things:
Human:
- Human
Animal:
- Animal
Plant:
- Plant
Goods:
- Goods
Electrical Devices:
- Electrical Devices
Transport:
- Transport
Place:
Infrastructure:
- Infrastructure
Space:
- Space
Energy:
- Energy
Environment:
- Environment
Measurement Type:
Motion:
Movement:
- Movement
Velocity:
- Velocity
Inertia:
- Inertia
Vibration:
- Vibration
Acceleration:
- Acceleration
Occupancy:
- occupancy
- people
- headcount
- person
Rotation:
- Rotation
Destination:
- Destination
Position:
Orientation:
- Orientation
Inclination:
- Inclination
Proximity:
- Proximity
Presence:
- Presence
Location:
- Location
Layout:
- Layout
Distance:
- Distance
Level:
- Level
Energy:
Energy Consumption:
- Energy Consumption
Energy Production:
- Energy Production
Energy Storage:
- Energy Storage
Environment:
Temperature:
- temperature
- heat
- climate
Humidity:
- humidity
- water
- moisture
- wetness
- dampness
- moistness
Luminance:
- Luminance
Acoustic:
- Acoustic
Radiation:
- Radiation
Gas:
- gas
- air
- CO2
- purity
- pollutant
Magnetic Field:
- Magnetic Field
Chemical:
- particulate
- air quality
- pm
- particulate matter
Electrical:
- Electrical
Color:
- Color
Machine Vision:
- Machine Vision
Electromagnetic Field:
- Electromagnetic Field
Mass:
Volume:
- volume
- sound
Pressure:
- pressure
Density:
- Density
Deformation:
- Deformation
Viscosity:
- Viscosity
Flow:
- Flow
Load:
- Load
Shock:
- Shock
Moisture:
- Moisture
Contact:
- Contact
Strain:
- Strain
Corrosion:
- Corrosion
Electrical Conductivity:
- Electrical Conductivity
Oxygen:
- Oxygen
Biosensor:
Brain Electrical Activity:
- Brain Electrical Activity
Eye Movement:
- Eye Movement
Heart Electrical Activity:
- Heart Electrical Activity
Heart Rate:
- Heart Rate
Respiratory Flow:
- Respiratory Flow
Imaging:
- Imaging
Height:
- Height
Weight:
- Weight
Fat:
- Fat
Muscle Mass:
- Muscle Mass
Bone Density:
- Bone Density
Ground Reaction Force:
- Ground Reaction Force
Gait:
- Gait
Joint Torque:
- Joint Torque
Posture:
- Posture
Skeletal Muscles Activity:
- Skeletal Muscles Activity
Body Temperature:
- Body Temperature
Glucose Level:
- Glucose Level
pH:
- pH
Blood Pressure:
- Blood Pressure
SpO2:
- SpO2
Sodium and Conductivity:
- Sodium and Conductivity
Blood Vessel Stiffness:
- Blood Vessel Stiffness
Microbial Structure:
- Microbial Structure
Cell Structure:
- Cell Structure
......@@ -2,11 +2,11 @@
* Copyright (C) 2021 fortiss GmbH
* @author Jorge de Lime Tostes – "tostes@fortiss.org"
* @version 1.2
* Sensor taxonomy as json object
* Sensor ontology as json object
*/
taxonomy = {
'taxonomy': {
ontology = {
'ontology': {
'domain': {
'health': [
'nursing home',
......@@ -148,4 +148,4 @@ taxonomy = {
}
};
module.exports = taxonomy;
module.exports = ontology;
......@@ -7,7 +7,7 @@
import React from 'react';
import store from "../config/store";
import {View, Text, SafeAreaView, TextInput, Image, FlatList, TouchableOpacity, Modal} from 'react-native';
import {View, Text, SafeAreaView, TextInput, FlatList, TouchableOpacity, Modal} from 'react-native';
import {connect} from 'react-redux';
import EStyleSheet from 'react-native-extended-stylesheet';
import BottomNavigation from "../component/BottomNavigation";
......
......@@ -6,7 +6,8 @@
*/
import React from "react";
import Icon from "react-native-vector-icons/Entypo";
import Entypo from "react-native-vector-icons/Entypo";
import Ionicons from "react-native-vector-icons/Ionicons";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import store from "../config/store";
import * as Colors from '../constant/string/Colors';
......@@ -22,17 +23,19 @@ export default class DeviceService {
*/
static getDeviceIconByType(name) {
if (name.toLowerCase().includes("temperature")) {
return <Icon color={Colors.blue} name="thermometer" size={50}/>;
return <Entypo color={Colors.blue} name="thermometer" size={50}/>;
} else if (name.toLowerCase().includes("humidity")) {
return <Icon color={Colors.blue} name="water" size={50}/>;
return <Entypo color={Colors.blue} name="water" size={50}/>;
} else if (name.toLowerCase().includes("sound")) {
return <Icon color={Colors.blue} name="sound" size={50}/>;
return <Entypo color={Colors.blue} name="sound" size={50}/>;
} else if (name.toLowerCase().includes("co2")) {
return <Icon color={Colors.blue} name="air" size={50}/>;
return <Entypo color={Colors.blue} name="air" size={50}/>;
} else if (name.toLowerCase().includes("particulate")) {
return <MaterialCommunityIcons color={Colors.blue} name="air-filter" size={50}/>
} else if (name.toLowerCase().includes("occupancy")) {
return <Ionicons color={Colors.blue} name="people" size={50}/>
} else {
return <Icon name="help" size={50}/>;
return <Entypo name="help" size={50}/>;
}
}
......
......@@ -150,9 +150,11 @@ export default class MQTTClientService {
let topic = message.destinationName;
let payload = JSON.parse(message.payloadString);
console.log("message published");
// handle the message according to it's topic
switch (topic) {
case Constants.constants.DISCOVERY_TOPIC:
console.log("Sensor discovered: ", payload);
DeviceService.storeDevice(payload);
break;
case Constants.constants.DEADVERTISE_TOPIC:
......
......@@ -127,18 +127,18 @@ export default class ServiceRequestParser {
return obj.$.name === noprefixMessageInput;
})
let taxonomy = resultElement[0]['xsd:complexType'][0]['xsd:sequence'][0]['xsd:element'].filter(obj => {
return obj.$.ref === 'Taxonomy';
let ontology = resultElement[0]['xsd:complexType'][0]['xsd:sequence'][0]['xsd:element'].filter(obj => {
return obj.$.ref === 'ontology';
})[0]['xsd:element'];
let QoS = resultElement[0]['xsd:complexType'][0]['xsd:sequence'][0]['xsd:element'].filter(obj => {
return obj.$.ref === 'QoS';
})[0]['xsd:element'];
for (let k = 0; k < taxonomy.length; k++) {
if (Object.keys(taxonomy[j]['xsd:element'][0]['xsd:element'][0].$).includes('name')) {
input.push([taxonomy[j].$.ref, taxonomy[j]['xsd:element'][0].$.ref, taxonomy[j]['xsd:element'][0]['xsd:element'][0].$.name])
for (let k = 0; k < ontology.length; k++) {
if (Object.keys(ontology[j]['xsd:element'][0]['xsd:element'][0].$).includes('name')) {
input.push([ontology[j].$.ref, ontology[j]['xsd:element'][0].$.ref, ontology[j]['xsd:element'][0]['xsd:element'][0].$.name])
} else {
input.push([taxonomy[j].$.ref, taxonomy[j]['xsd:element'][0].$.ref, taxonomy[j]['xsd:element'][0]['xsd:element'][0]['xsd:element'][0].$.name])
input.push([ontology[j].$.ref, ontology[j]['xsd:element'][0].$.ref, ontology[j]['xsd:element'][0]['xsd:element'][0]['xsd:element'][0].$.name])
}
}
......@@ -164,9 +164,9 @@ export default class ServiceRequestParser {
for (let j = 0; j < inputs[i].length; j++) {
if (inputs[i][j][0].replace(/_|-/g, ' ').toLowerCase().trim() === 'domain') {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['domain']) {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['domain']) {
request["domain"] = inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim();
let element = config['taxonomy']['domain'][request["domain"]];
let element = config['ontology']['domain'][request["domain"]];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim())) {
request["domainDetail"] = inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim();
......@@ -185,12 +185,12 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Domain used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Domain used in the input ${i + 1} is not included in the ontology \n`;
}
} else if (inputs[i][j][0].replace(/_|-/g, ' ').toLowerCase().trim() === 'monitoring aspects') {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['monitoring aspect']) {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['monitoring aspect']) {
request["monitoringAspect"] = inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim();
let element = config['taxonomy']['monitoring aspect'][request["monitoringAspect"]];
let element = config['ontology']['monitoring aspect'][request["monitoringAspect"]];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim())) {
request["monitoringAspectDetail"] = inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim();
......@@ -209,11 +209,11 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Monitoring Aspect used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Monitoring Aspect used in the input ${i + 1} is not included in the ontology \n`;
}
} else if (inputs[i][j][0].replace(/_|-/g, ' ').toLowerCase().trim() === 'measurement types') {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['measurement type']) {
let element = config['taxonomy']['measurement type'][inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim()];
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['measurement type']) {
let element = config['ontology']['measurement type'][inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim()];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim())) {
request["featureOfInterest"] = inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim();
......@@ -232,7 +232,7 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Measurement Type used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Measurement Type used in the input ${i + 1} is not included in the ontology \n`;
}
}
}
......@@ -272,18 +272,18 @@ export default class ServiceRequestParser {
return obj.$.name === noprefixOperationInput;
})
let taxonomy = resultElement[0]['xsd:complexType'][0]['xsd:sequence'][0]['xsd:element'].filter(obj => {
return obj.$.ref === 'Taxonomy';
let ontology = resultElement[0]['xsd:complexType'][0]['xsd:sequence'][0]['xsd:element'].filter(obj => {
return obj.$.ref === 'ontology';
})[0]['xsd:element'];
let QoS = resultElement[0]['xsd:complexType'][0]['xsd:sequence'][0]['xsd:element'].filter(obj => {
return obj.$.ref === 'QoS';
})[0]['xsd:element'];
for (let j = 0; j < taxonomy.length; j++) {
if (Object.keys(taxonomy[j]['xsd:element'][0]['xsd:element'][0].$).includes('name')) {
input.push([taxonomy[j].$.ref, taxonomy[j]['xsd:element'][0].$.ref, taxonomy[j]['xsd:element'][0]['xsd:element'][0].$.name])
for (let j = 0; j < ontology.length; j++) {
if (Object.keys(ontology[j]['xsd:element'][0]['xsd:element'][0].$).includes('name')) {
input.push([ontology[j].$.ref, ontology[j]['xsd:element'][0].$.ref, ontology[j]['xsd:element'][0]['xsd:element'][0].$.name])
} else {
input.push([taxonomy[j].$.ref, taxonomy[j]['xsd:element'][0].$.ref, taxonomy[j]['xsd:element'][0]['xsd:element'][0]['xsd:element'][0].$.name])
input.push([ontology[j].$.ref, ontology[j]['xsd:element'][0].$.ref, ontology[j]['xsd:element'][0]['xsd:element'][0]['xsd:element'][0].$.name])
}
}
......@@ -308,9 +308,9 @@ export default class ServiceRequestParser {
for (let j = 0; j < inputs[i].length; j++) {
if (inputs[i][j][0].replace(/_|-/g, ' ').toLowerCase().trim() === 'domain') {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['domain']) {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['domain']) {
request["domain"] = inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim();
let element = config['taxonomy']['domain'][request["domain"]];
let element = config['ontology']['domain'][request["domain"]];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim())) {
request["domainDetail"] = inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim();
......@@ -329,12 +329,12 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Domain used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Domain used in the input ${i + 1} is not included in the ontology \n`;
}
} else if (inputs[i][j][0].replace(/_|-/g, ' ').toLowerCase().trim() === 'monitoring aspects') {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['monitoring aspect']) {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['monitoring aspect']) {
request["monitoringAspect"] = inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim();
let element = config['taxonomy']['monitoring aspect'][request["monitoringAspect"]];
let element = config['ontology']['monitoring aspect'][request["monitoringAspect"]];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim())) {
request["monitoringAspectDetail"] = inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim();
......@@ -353,11 +353,11 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Monitoring Aspect used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Monitoring Aspect used in the input ${i + 1} is not included in the ontology \n`;
}
} else if (inputs[i][j][0].replace(/_|-/g, ' ').toLowerCase().trim() === 'measurement types') {
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['measurement type']) {
let element = config['taxonomy']['measurement type'][inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim()];
if (inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['measurement type']) {
let element = config['ontology']['measurement type'][inputs[i][j][1].replace(/_|-/g, ' ').toLowerCase().trim()];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim())) {
request["featureOfInterest"] = inputs[i][j][2].replace(/_|-/g, ' ').toLowerCase().trim();
......@@ -376,7 +376,7 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Measurement Type used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Measurement Type used in the input ${i + 1} is not included in the ontology \n`;
}
}
}
......@@ -399,7 +399,7 @@ export default class ServiceRequestParser {
static async owlParsing(parsedObject) {
let xmlns = parsedObject[Object.keys(parsedObject)].$['xmlns'];
let taxonomyPrefix = parsedObject[Object.keys(parsedObject)].$['xmlns:Taxonomy'];
let ontologyPrefix = parsedObject[Object.keys(parsedObject)].$['xmlns:ontology'];
let matched = Object.keys(parsedObject[Object.keys(parsedObject)].$).filter(function (key) {
return parsedObject[Object.keys(parsedObject)].$[key] === xmlns;
......@@ -451,16 +451,16 @@ export default class ServiceRequestParser {
inputPrefix = `${serviceName}:`;
} else if (typeof (inputIndividual[0][`hasDomain`]) !== 'undefined') {
} else if (taxonomyPrefix === "http://www.semanticweb.org/tostes/ontologies/2021/6/Taxonomy#") {
inputPrefix = 'Taxonomy:'
} else if (ontologyPrefix === "http://www.semanticweb.org/tostes/ontologies/2021/6/ontology#") {
inputPrefix = 'ontology:'
} else {
return 'Unknown Prefix for input inside OWL file'
}
let domain = inputIndividual[0][`${inputPrefix}hasDomain`][0].$['rdf:resource'].split('#')[1];
if (domain.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['domain']) {
if (domain.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['domain']) {
input["domain"] = domain.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim();
let element = config['taxonomy']['domain'][input["domain"]];
let element = config['ontology']['domain'][input["domain"]];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(domain.split(':')[1].replace(/_|-/g, ' ').toLowerCase().trim())) {
......@@ -480,12 +480,12 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Domain used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Domain used in the input ${i + 1} is not included in the ontology \n`;
}
let measurementType = inputIndividual[0][`${inputPrefix}hasMeasurementType`][0].$['rdf:resource'].split('#')[1];
if (measurementType.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['measurement type']) {
let element = config['taxonomy']['measurement type'][measurementType.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim()];
if (measurementType.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['measurement type']) {
let element = config['ontology']['measurement type'][measurementType.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim()];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(measurementType.split(':')[1].replace(/_|-/g, ' ').toLowerCase().trim())) {
......@@ -505,13 +505,13 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Measurement Type used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Measurement Type used in the input ${i + 1} is not included in the ontology \n`;
}
let monitoringAspect = inputIndividual[0][`${inputPrefix}hasMonitoringAspect`][0].$['rdf:resource'].split('#')[1];
if (monitoringAspect.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim() in config['taxonomy']['monitoring aspect']) {
if (monitoringAspect.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim() in config['ontology']['monitoring aspect']) {
input["monitoringAspect"] = monitoringAspect.split(':')[0].replace(/_|-/g, ' ').toLowerCase().trim();
let element = config['taxonomy']['monitoring aspect'][input["monitoringAspect"]];
let element = config['ontology']['monitoring aspect'][input["monitoringAspect"]];
if (typeof (element[Object.keys(element)[0]]) != 'object') {
if (element.includes(monitoringAspect.split(':')[1].replace(/_|-/g, ' ').toLowerCase().trim())) {
......@@ -531,7 +531,7 @@ export default class ServiceRequestParser {
}
}
} else {
error += `The Monitoring Aspect used in the input ${i + 1} is not included in the Taxonomy \n`;
error += `The Monitoring Aspect used in the input ${i + 1} is not included in the ontology \n`;
}
input['domain'] = (await ServiceRequestParser.titleCase(input['domain']));
......
File moved
......@@ -8,15 +8,15 @@
import * as natural from "natural";
import * as stringSimilarity from "string-similarity";
import {TaxonomyRepository} from "../shared/repository/TaxonomyRepository";
import {OntologyRepository} from "../shared/repository/OntologyRepository";
import {DbContext} from "@coaty/core/db";
// grouping based on the functionality required by the service request e.g. temperature, pressure ...
export function matchBasedOnStringSimilarity(taxonomyNode, deviceDescriptionList: any[]) {
export function matchBasedOnStringSimilarity(ontologyNode, deviceDescriptionList: any[]) {
const results = [];
for (const deviceDescription of deviceDescriptionList) {
if (stringSimilarity.compareTwoStrings(taxonomyNode, deviceDescription.sensor.properties.observedProperty_name) > 0.5) {
if (stringSimilarity.compareTwoStrings(ontologyNode, deviceDescription.sensor.properties.observedProperty_name) > 0.5) {
results.push(deviceDescription);
}
}
......@@ -24,7 +24,7 @@ export function matchBasedOnStringSimilarity(taxonomyNode, deviceDescriptionList
}
/**
* find the respective measurement type of a service request in our taxonomy
* find the respective measurement type of a service request in our ontology
* using tf-idf method
* @param serviceDescription
* @param dbContext
......@@ -33,7 +33,7 @@ export function findMeasurementType(serviceDescription, dbContext: DbContext) {
const TfIdf = natural.TfIdf;
const tfidf = new TfIdf();
let val = "non";
let taxonomyNodeList = [
let ontologyNodeList = [
"Temperature",
"Humidity",
"Headcount",
......@@ -45,10 +45,10 @@ export function findMeasurementType(serviceDescription, dbContext: DbContext) {
tfidf.addDocument(serviceDescription.FeatureOfInterest.toString());
return new Promise<any>((resolve, reject) => {
// get list of synonyms for each of the taxonomy nodes listed above
TaxonomyRepository.getListOfSynonyms(taxonomyNodeList, dbContext).then(result => {
// get list of synonyms for each of the ontology nodes listed above
OntologyRepository.getListOfSynonyms(ontologyNodeList, dbContext).then(result => {
result.forEach(item => {
// calculate the tf-idf score for each of the synonym with the taxonomy nodes listed above
// calculate the tf-idf score for each of the synonym with the ontology nodes listed above
tfidf.tfidfs(item._fields[1].join(" "), (i, measure) => {
if (measure >= 0.2) {
val = item._fields[0];
......
......@@ -88,11 +88,11 @@ export class TaskController extends ObjectCacheController<ServiceTaskRequest> {
// grouping is not possible case
if (Object.keys(grouping).length === 0) {
console.warn("Grouping is not possible: ", serviceDescription.objectId);
// create relations to taxonomy nodes
// create relations to ontology nodes
this.dbContext.callExtension("runQuery",
`match (r:Request {objectId: $requestObjectId})
match (t1:Taxonomy {name: $measurementAspect})
match (t2:Taxonomy {name: $domain})
match (t1:Ontology {name: $measurementAspect})
match (t2:Ontology {name: $domain})
set r.isProcessed=true
merge (r)-[:INFLUENCED_BY]->(t1)
merge (r)-[:INFLUENCED_BY]->(t2)`, {
......@@ -100,7 +100,7 @@ export class TaskController extends ObjectCacheController<ServiceTaskRequest> {
measurementAspect: serviceDescription.monitoringAspectDetail,
domain: serviceDescription.domainDetail,
}).then(result => {
console.info(`Created relation between taxonomy nodes and request ${serviceDescription.objectId}.`);
console.info(`Created relation between ontology nodes and request ${serviceDescription.objectId}.`);
})
Events._advertiseDatabaseChange(this.communicationManager, this.runtime.newUuid());
} else {
......@@ -131,13 +131,13 @@ export class TaskController extends ObjectCacheController<ServiceTaskRequest> {
aggregationId++;
}
// create relations between service request and taxonomy nodes
// create relations between service request and ontology nodes
console.info(`Grouping is successful! Relations between sensors and request ${serviceDescription.objectId} is created.`);
this.dbContext.callExtension("runQuery",
`match (r:Request {objectId: $requestObjectId})
match (t1:Taxonomy {name: $measurementType})
match (t2:Taxonomy {name: $measurementAspect})
match (t3:Taxonomy {name: $domain})
match (t1:Ontology {name: $measurementType})
match (t2:Ontology {name: $measurementAspect})
match (t3:Ontology {name: $domain})
merge (r)-[:INFLUENCED_BY]->(t1)
merge (r)-[:INFLUENCED_BY]->(t2)
merge (r)-[:INFLUENCED_BY]->(t3)`, {
......@@ -146,7 +146,7 @@ export class TaskController extends ObjectCacheController<ServiceTaskRequest> {
measurementAspect: serviceDescription.monitoringAspectDetail,
domain: serviceDescription.domainDetail,
}).then(result => {
console.info(`Created relation between taxonomy nodes and request ${serviceDescription.objectId}.`);
console.info(`Created relation between ontology nodes and request ${serviceDescription.objectId}.`);
});
}
});
......
......@@ -73,46 +73,46 @@ export class Neo4jAdapter extends DbAdapterBase {
await this.createConstraints();
await this.createIndexes();
const taxonomy = jsyaml.load(fs.readFileSync(__dirname + '/../../taxonomy.yaml', 'utf8'));
await this.createTaxonomy(taxonomy);
const ontology = jsyaml.load(fs.readFileSync(__dirname + '/../../ontology.yaml', 'utf8'));
await this.createOntology(ontology);
NodeUtils.logInfo("Database initialization is done!");
}
/**
* Create predefined taxonomy using taxonomy.yaml file in the root folder
* Create predefined ontology using ontology.yaml file in the root folder
*/
async createTaxonomy(taxonomy: {}, parent: string = null) {
for (let element in taxonomy) {
async createOntology(ontology: {}, parent: string = null) {
for (let element in ontology) {
if (parent == null) {
await this.runQuery(`merge (parent: Taxonomy {name: $name})`, {
await this.runQuery(`merge (parent: Ontology {name: $name})`, {
name: element
});
await this.createTaxonomy(taxonomy[element], element);
await this.createOntology(ontology[element], element);
} else {
if (typeof taxonomy[element] == "object") {
if (typeof ontology[element] == "object") {
await this.runQuery(
`merge (parent:Taxonomy {name: $parentName})
merge (child:Taxonomy {name: $childName})
`merge (parent:Ontology {name: $parentName})
merge (child:Ontology {name: $childName})
merge (child)-[:ASSOCIATED_WITH]->(parent)`, {
childName: element,
parentName: parent
});
await this.createTaxonomy(taxonomy[element], element);
await this.createOntology(ontology[element], element);
} else {
await this.runQuery(
`match (parent:Taxonomy {name: $parentName})
`match (parent:Ontology {name: $parentName})
where parent.synonyms is not null
and all(item in parent.synonyms where toLower(item) <> toLower($synonym))
set parent.synonyms = parent.synonyms + $synonym`, {
synonym: taxonomy[element],
synonym: ontology[element],
parentName: parent
});
await this.runQuery(
`match (parent:Taxonomy {name: $parentName})
`match (parent:Ontology {name: $parentName})
where parent.synonyms is null
set parent += {synonyms: [$synonym]}`, {
synonym: taxonomy[element],
synonym: ontology[element],
parentName: parent
});
......
......@@ -2,25 +2,25 @@
* Copyright (C) 2021 fortiss GmbH
* @author Erkan Karabulut – {@link "karabulut@fortiss.org"}
* @version 1.1
* Db operations related with the sensor taxonomy
* Db operations related with the sensor ontology
*/
import {DbContext} from "@coaty/core/db";
/**
* Db operations related with the sensor taxonomy
* Db operations related with the sensor ontology
*/
export class TaxonomyRepository {
export class OntologyRepository {
/**
* Get the array of similar words for a given node list
* @param taxonomyNodeList
* @param ontologyNodeList
* @param dbContext
*/
public static getListOfSynonyms(taxonomyNodeList, dbContext: DbContext): Promise<any> {
public static getListOfSynonyms(ontologyNodeList, dbContext: DbContext): Promise<any> {
return dbContext.callExtension("runQuery",
`match (s:Taxonomy) where any(item in $taxonomyNodeList where item = s.name)
`match (s:Taxonomy) where any(item in $ontologyNodeList where item = s.name)
return s.name, s.synonyms`, {
taxonomyNodeList: taxonomyNodeList
ontologyNodeList: ontologyNodeList
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment