From 85c2034f44580999522059da909eacf9f7a76fb5 Mon Sep 17 00:00:00 2001 From: Michael Baur Date: Fri, 8 Jan 2021 14:39:30 +0100 Subject: [PATCH] Update for yFiles for HTML 2.3.0.4 --- .gitignore | 2 ++ .prettierrc.json | 5 +-- LICENSE | 2 +- README.md | 16 +++++---- app/scripts/app.js | 34 +++++++++--------- app/scripts/knwl.js | 4 +-- app/scripts/lodlabelstyle.js | 2 +- app/scripts/popup.js | 2 +- copy-license.js | 2 +- knwl/index.js | 18 +++++----- knwl/ontology.js | 70 ++++++++++++++++++------------------ knwl/store.js | 54 ++++++++++++++-------------- loadData.js | 2 +- package.json | 4 +-- service.js | 4 +-- test/elements.js | 4 +-- test/knowledge.js | 30 ++++++++-------- test/schema.js | 20 +++++------ test/store.js | 6 ++-- webpack.config.js | 40 ++++++++++----------- 20 files changed, 161 insertions(+), 160 deletions(-) diff --git a/.gitignore b/.gitignore index a8ce706..a87d6d8 100644 --- a/.gitignore +++ b/.gitignore @@ -171,3 +171,5 @@ app/yfiles/ license.json live/ /database +/dist/ +src/assets/yfiles/ diff --git a/.prettierrc.json b/.prettierrc.json index e987452..0d4802b 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,11 +1,8 @@ { "printWidth": 100, "tabWidth": 2, - "endOfLine": "auto", "useTabs": false, "semi": false, "singleQuote": true, - "bracketSpacing": true, - "trailingComma": "none", - "arrowParens": "avoid" + "endOfLine": "auto" } diff --git a/LICENSE b/LICENSE index ed93f9a..92d5057 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 yWorks GmbH +Copyright (c) 2021 yWorks GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index e225ee5..d13e07e 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,11 @@ This repository contains the sample application for the yFiles use case about an [Ontology Visualizer](https://www.yworks.com/use-case/visualizing-an-ontology). The app displays a sample ontology diagram that you can explore. - ## See also -* [Watch the introductory video](https://player.vimeo.com/video/389490579) of this app -* [Read the article](https://www.yworks.com/use-case/visualizing-an-ontology) about an _Ontology Visualizer_ -* [Learn more about yFiles](https://www.yworks.com/products/yfiles), the software library for visualizing, editing, and analyzing graphs +- [Watch the introductory video](https://player.vimeo.com/video/389490579) of this app +- [Read the article](https://www.yworks.com/use-case/visualizing-an-ontology) about an _Ontology Visualizer_ +- [Learn more about yFiles](https://www.yworks.com/products/yfiles), the software library for visualizing, editing, and analyzing graphs If you have any questions or suggestions, send us an email at [consulting@yworks.com](mailto:consulting@yworks.com) or call [+49 7071 9709050](tel:+4970719709050). @@ -27,19 +26,21 @@ Checkout this project, then extract the yFiles for HTML package to a directory n ``` documents |-- ontology-visualizer - |-- yFiles-for-HTML-Complete-2.3.0.2-Evaluation + |-- yFiles-for-HTML-Complete-2.3.0.4-Evaluation ``` Afterwards, enter the `ontology-visualizer` directory and run the usual commands + ``` npm i ``` + followed by + ``` npm start ``` - ## About This application is powered by [yFiles for HTML](https://www.yworks.com/products/yfiles-for-html), the powerful @@ -64,9 +65,10 @@ or call [+49 7071 9709050](tel:+4970719709050). The app shows data from [DBpedia](http://dbpedia.org/ontology/) ## License + The MIT License (MIT) -Copyright (c) 2020 yWorks GmbH +Copyright (c) 2021 yWorks GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/app/scripts/app.js b/app/scripts/app.js index cd82ba6..a5b8556 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -44,7 +44,7 @@ import { TemplateNodeStyle, TextRenderSupport, TextWrapping, - YPoint + YPoint, } from 'yfiles' import lic from '../yfiles/license.json' import { LODLabelStyleRenderer } from './lodlabelstyle' @@ -74,7 +74,7 @@ class GraphOverviewVisualCreator extends GraphOverviewCanvasVisualCreator { ctx.strokeStyle = '#f7f7f7' ctx.beginPath() ctx.moveTo(edge.sourcePort.location.x, edge.sourcePort.location.y) - edge.bends.forEach(bend => { + edge.bends.forEach((bend) => { ctx.lineTo(bend.location.x, bend.location.y) }) ctx.lineTo(edge.targetPort.location.x, edge.targetPort.location.y) @@ -120,7 +120,7 @@ class App { this.graphComponent.graph.edgeDefaults.style = new PolylineEdgeStyle({ stroke: Stroke.WHITE_SMOKE, targetArrow: 'white medium triangle', - smoothingLength: 10 + smoothingLength: 10, }) this.graphComponent.graph.nodeDefaults.labels.style = new DefaultLabelStyle({ @@ -128,7 +128,7 @@ class App { backgroundFill: 'rgba(255,255,255,0.9)', textFill: '#636363', font: `12px ${defaultFontFamily}`, - insets: new Insets(4) + insets: new Insets(4), }) this.graphComponent.graph.nodeDefaults.labels.layoutParameter = FreeNodeLabelModel.INSTANCE.createParameter( new Point(0.5, 1), @@ -139,7 +139,7 @@ class App { this.initializeInputMode() this.initializePopups() this.initializeInteractions() - this.knwl.getSimplifiedOntologyGraph().then(async data => { + this.knwl.getSimplifiedOntologyGraph().then(async (data) => { await this.assembleGraph(data) }) @@ -214,14 +214,14 @@ class App { key: Key.ESCAPE, execute: (command, parameter, source) => { source.currentItem = null - } + }, }) } updateNodePopupContent(nodePopup, /*INode*/ node) { // get business data from node tag const id = node.tag - this.knwl.getClass(id).then(data => { + this.knwl.getClass(id).then((data) => { // get all divs in the pop-up const divs = nodePopup.div.getElementsByTagName('div') for (let i = 0; i < divs.length; i++) { @@ -287,7 +287,7 @@ class App { } return uri } else if (_.isArray(uri)) { - uri.map(u => this.toShortForm(u)) + uri.map((u) => this.toShortForm(u)) } else { return uri.toString() } @@ -314,7 +314,7 @@ class App { const mode = new GraphViewerInputMode({ toolTipItems: GraphItemTypes.NODE, selectableItems: GraphItemTypes.NODE | GraphItemTypes.EDGE, - marqueeSelectableItems: GraphItemTypes.NONE + marqueeSelectableItems: GraphItemTypes.NONE, }) mode.mouseHoverInputMode.toolTipLocationOffset = new Point(10, 10) @@ -337,7 +337,7 @@ class App { if (item) { highlightIndicatorManager.addHighlight(item) if (INode.isInstance(item)) { - this.graphComponent.graph.edgesAt(item).forEach(edge => { + this.graphComponent.graph.edgesAt(item).forEach((edge) => { highlightIndicatorManager.addHighlight(edge) }) } else if (IEdge.isInstance(item)) { @@ -352,7 +352,7 @@ class App { layoutCircular() { return this.runLayout( new CircularLayout({ - partitionStyle: 'disk' + partitionStyle: 'disk', }) ) } @@ -360,7 +360,7 @@ class App { layoutOrganic() { return this.runLayout( new OrganicLayout({ - preferredEdgeLength: 200 + preferredEdgeLength: 200, }) ) } @@ -368,7 +368,7 @@ class App { layoutHierarchic() { return this.runLayout( new HierarchicLayout({ - considerNodeLabels: true + considerNodeLabels: true, }) ) } @@ -443,7 +443,7 @@ class App { $('#navHierarchic').click(() => { this.layoutHierarchic() }) - $('#search-stuff').keypress(e => { + $('#search-stuff').keypress((e) => { if (e.which === 13) { const term = $('#search-stuff').val() $('#search-stuff').val('') @@ -481,7 +481,7 @@ class App { objList.empty() $('#detailsPanel-title').html(this.toShortForm(uri)) if (cls.objectProperties.length > 0) { - cls.objectProperties.forEach(p => { + cls.objectProperties.forEach((p) => { objList.append( `
${p.name}
` ) @@ -494,7 +494,7 @@ class App { const dataList = $('#dataProp-list') dataList.empty() if (cls.dataProperties.length > 0) { - cls.dataProperties.forEach(p => { + cls.dataProperties.forEach((p) => { dataList.append( `
${p.name}
` ) @@ -517,7 +517,7 @@ class CenterPortsLayoutStage extends LayoutStageBase { applyLayout(graph) { this.applyLayoutCore(graph) - graph.edges.forEach(edge => { + graph.edges.forEach((edge) => { graph.getLayout(edge).sourcePoint = YPoint.ORIGIN graph.getLayout(edge).targetPoint = YPoint.ORIGIN }) diff --git a/app/scripts/knwl.js b/app/scripts/knwl.js index 3fa27d5..a36b75e 100644 --- a/app/scripts/knwl.js +++ b/app/scripts/knwl.js @@ -22,7 +22,7 @@ export default class Knwl { url: `${this.url}getClass`, method: 'POST', contentType: 'application/json', - data: JSON.stringify({ name: className, includeProps: includeProps }) + data: JSON.stringify({ name: className, includeProps: includeProps }), }) } @@ -32,7 +32,7 @@ export default class Knwl { getSimplifiedOntologyGraph() { return $.ajax({ url: `${this.url}getSimplifiedOntologyGraph`, - method: 'GET' + method: 'GET', }) } } diff --git a/app/scripts/lodlabelstyle.js b/app/scripts/lodlabelstyle.js index f3e4493..145842a 100644 --- a/app/scripts/lodlabelstyle.js +++ b/app/scripts/lodlabelstyle.js @@ -15,7 +15,7 @@ export class LODLabelStyleRenderer extends DefaultLabelStyleRenderer { if (!(visual instanceof SvgVisualGroup)) { return visual } - const rectVisual = visual.children.find(v => v.svgElement.tagName === 'rect') + const rectVisual = visual.children.find((v) => v.svgElement.tagName === 'rect') rectVisual.svgElement.setAttribute('rx', '7px') return visual } diff --git a/app/scripts/popup.js b/app/scripts/popup.js index 9b04603..73cbef3 100644 --- a/app/scripts/popup.js +++ b/app/scripts/popup.js @@ -5,7 +5,7 @@ import { IModelItem, Point, SimpleLabel, - Size + Size, } from 'yfiles' /** diff --git a/copy-license.js b/copy-license.js index 9bfe6ee..96edd46 100644 --- a/copy-license.js +++ b/copy-license.js @@ -32,7 +32,7 @@ if (!fs.existsSync(destDir)) { fs.mkdirSync(destDir) } -fs.copyFile(licenseFile, path.join(destDir, 'license.json'), err => { +fs.copyFile(licenseFile, path.join(destDir, 'license.json'), (err) => { if (err) { console.log( `\nyFiles license was NOT copied from '${licenseFile}'.` + diff --git a/knwl/index.js b/knwl/index.js index 8ab00cc..803e23f 100644 --- a/knwl/index.js +++ b/knwl/index.js @@ -139,20 +139,20 @@ class Knowledge { if (_.isNil(dataProps) || dataProps.length === 0) { cls.dataProperties = [] } else { - cls.dataProperties = dataProps.map(d => { + cls.dataProperties = dataProps.map((d) => { return { name: schema.toShortForm(this.rootId, d), - uri: d + uri: d, } }) } if (_.isNil(objectProps) || objectProps.length === 0) { cls.objectProperties = [] } else { - cls.objectProperties = objectProps.map(d => { + cls.objectProperties = objectProps.map((d) => { return { name: schema.toShortForm(this.rootId, d), - uri: d + uri: d, } }) } @@ -393,7 +393,7 @@ class OntologyElement { name: null, id: null, label: null, - comment: null + comment: null, } } } @@ -451,7 +451,7 @@ class OntologyClass extends OntologyElement { parentId: null, parentName: null, dataProperties: [], - objectProperties: [] + objectProperties: [], }, super.serializationTemplate ) @@ -495,7 +495,7 @@ class OntologyDataProperty extends OntologyElement { return _.extend( { rangeIds: null, - domainIds: null + domainIds: null, }, super.serializationTemplate ) @@ -540,7 +540,7 @@ class OntologyObjectProperty extends OntologyElement { return _.extend( { rangeIds: null, - domainIds: null + domainIds: null, }, super.serializationTemplate ) @@ -551,5 +551,5 @@ module.exports = { OntologyClass, OntologyDataProperty, OntologyObjectProperty, - Knowledge + Knowledge, } diff --git a/knwl/ontology.js b/knwl/ontology.js index 1730a18..311f511 100644 --- a/knwl/ontology.js +++ b/knwl/ontology.js @@ -13,13 +13,13 @@ QuadType = { Comment: 'Comment', Other: 'Other', Thing: 'Thing', - A: 'A' + A: 'A', } OntologyType = { Class: 'Class', DatatypeProperty: 'DatatypeProperty', ObjectProperty: 'ObjectProperty', - Other: 'Other' + Other: 'Other', } SpecialUri = { @@ -36,7 +36,7 @@ SpecialUri = { comment: 'http://www.w3.org/2000/01/rdf-schema#comment', domain: 'http://www.w3.org/2000/01/rdf-schema#domain', range: 'http://www.w3.org/2000/01/rdf-schema#range', - literal: 'http://www.w3.org/2000/01/rdf-schema#literal' + literal: 'http://www.w3.org/2000/01/rdf-schema#literal', } SpecialNodes = { @@ -53,7 +53,7 @@ SpecialNodes = { comment: namedNode(SpecialUri.comment), domain: namedNode(SpecialUri.domain), range: namedNode(SpecialUri.range), - literal: namedNode(SpecialUri.literal) + literal: namedNode(SpecialUri.literal), } Schema = { @@ -178,7 +178,7 @@ Schema = { this.toUri(rootId, className), this.commentNode, literal(_.isNil(comment) ? '' : comment) - ) + ), ] } else { return [ @@ -197,7 +197,7 @@ Schema = { this.toUri(rootId, className), this.commentNode, literal(_.isNil(comment) ? '' : comment) - ) + ), ] } }, @@ -213,14 +213,14 @@ Schema = { this.toUri(rootUri, propertyName), this.commentNode, literal(_.isNil(comment) ? '' : comment) - ) + ), ] if (_.isString(domain)) { result.push( quad(this.toUri(rootUri, propertyName), this.domainNode, this.toUri(rootUri, domain)) ) } else if (_.isArray(domain)) { - domain.forEach(d => { + domain.forEach((d) => { result.push( quad(this.toUri(rootUri, propertyName), this.domainNode, this.toUri(rootUri, d)) ) @@ -241,14 +241,14 @@ Schema = { this.toUri(rootUri, propertyName), this.commentNode, literal(_.isNil(comment) ? '' : comment) - ) + ), ] if (_.isString(domain)) { result.push( quad(this.toUri(rootUri, propertyName), this.domainNode, this.toUri(rootUri, domain)) ) } else if (_.isArray(domain)) { - domain.forEach(d => { + domain.forEach((d) => { result.push( quad(this.toUri(rootUri, propertyName), this.domainNode, this.toUri(rootUri, d)) ) @@ -259,7 +259,7 @@ Schema = { quad(this.toUri(rootUri, propertyName), this.rangeNode, this.toUri(rootUri, range)) ) } else if (_.isArray(range)) { - range.forEach(r => { + range.forEach((r) => { result.push(quad(this.toUri(rootUri, propertyName), this.rangeNode, this.toUri(rootUri, r))) }) } @@ -269,7 +269,7 @@ Schema = { getClassDetailsFromQuads(rootUri, quadArray) { const OntologyClass = require('./index').OntologyClass const def = OntologyClass.serializationTemplate - let foundQuad = _.find(quadArray, a => a.predicate === this.aNode) + let foundQuad = _.find(quadArray, (a) => a.predicate === this.aNode) if (!_.isNil(foundQuad)) { if (foundQuad.object !== this.owlClassNode) { if (foundQuad.object === this.objectPropertyNode) @@ -283,16 +283,16 @@ Schema = { } else { throw new Error('Given quads do not define an ontology element.') } - foundQuad = _.find(quadArray, a => a.predicate === this.subClassOfNode) + foundQuad = _.find(quadArray, (a) => a.predicate === this.subClassOfNode) if (!_.isNil(foundQuad)) { def.parentId = foundQuad.object.id def.parentName = this.toShortForm(rootUri, foundQuad.object) } - foundQuad = _.find(quadArray, a => a.predicate === this.labelNode) + foundQuad = _.find(quadArray, (a) => a.predicate === this.labelNode) if (!_.isNil(foundQuad)) { def.label = foundQuad.object.value } - foundQuad = _.find(quadArray, a => a.predicate === this.comment) + foundQuad = _.find(quadArray, (a) => a.predicate === this.comment) if (!_.isNil(foundQuad)) { def.label = foundQuad.object.value } @@ -302,7 +302,7 @@ Schema = { getObjectPropertyDetailsFromQuads(rootUri, quadArray) { const OntologyObjectProperty = require('./index').OntologyObjectProperty const def = OntologyObjectProperty.serializationTemplate - let foundQuad = _.find(quadArray, a => a.predicate === this.aNode) + let foundQuad = _.find(quadArray, (a) => a.predicate === this.aNode) if (!_.isNil(foundQuad)) { if (foundQuad.object !== this.objectPropertyNode) { if (foundQuad.object === this.owlClassNode) @@ -319,20 +319,20 @@ Schema = { throw new Error('Given quads do not define an ontology element.') } - foundQuad = _.filter(quadArray, a => a.predicate === this.domainNode) + foundQuad = _.filter(quadArray, (a) => a.predicate === this.domainNode) if (!_.isNil(foundQuad)) { - def.domainIds = foundQuad.map(q => q.object.id) + def.domainIds = foundQuad.map((q) => q.object.id) } - foundQuad = _.filter(quadArray, a => a.predicate === this.rangeNode) + foundQuad = _.filter(quadArray, (a) => a.predicate === this.rangeNode) if (!_.isNil(foundQuad)) { - def.rangeIds = foundQuad.map(q => q.object.id) + def.rangeIds = foundQuad.map((q) => q.object.id) } - foundQuad = _.find(quadArray, a => a.predicate === this.labelNode) + foundQuad = _.find(quadArray, (a) => a.predicate === this.labelNode) if (!_.isNil(foundQuad)) { def.label = foundQuad.object.value } - foundQuad = _.find(quadArray, a => a.predicate === this.comment) + foundQuad = _.find(quadArray, (a) => a.predicate === this.comment) if (!_.isNil(foundQuad)) { def.label = foundQuad.object.value } @@ -342,7 +342,7 @@ Schema = { getDatatypePropertyDetailsFromQuads(rootUri, quadArray) { const OntologyDataProperty = require('./index').OntologyDataProperty const def = OntologyDataProperty.serializationTemplate - let foundQuad = _.find(quadArray, a => a.predicate === this.aNode) + let foundQuad = _.find(quadArray, (a) => a.predicate === this.aNode) if (!_.isNil(foundQuad)) { if (foundQuad.object !== this.datatypePropertyNode) { if (foundQuad.object === this.owlClassNode) @@ -359,16 +359,16 @@ Schema = { throw new Error('Given quads do not define an ontology element.') } - foundQuad = _.filter(quadArray, a => a.predicate === this.domainNode) + foundQuad = _.filter(quadArray, (a) => a.predicate === this.domainNode) if (!_.isNil(foundQuad)) { - def.domainIds = foundQuad.map(q => q.object.id) + def.domainIds = foundQuad.map((q) => q.object.id) } - foundQuad = _.find(quadArray, a => a.predicate === this.labelNode) + foundQuad = _.find(quadArray, (a) => a.predicate === this.labelNode) if (!_.isNil(foundQuad)) { def.label = foundQuad.object.value } - foundQuad = _.find(quadArray, a => a.predicate === this.comment) + foundQuad = _.find(quadArray, (a) => a.predicate === this.comment) if (!_.isNil(foundQuad)) { def.label = foundQuad.object.value } @@ -380,7 +380,7 @@ Schema = { * @param q presumably a quad * @returns {string} */ - getQuadType: function(q) { + getQuadType: function (q) { if (_.isNil(q)) { throw new Error('Missing argument in getQuadType.') } @@ -414,7 +414,7 @@ Schema = { if (!_.isArray(quadArray)) { throw new Error('getOntologyTypeOfQuads argument should be an array of quads.') } - const found = _.filter(quadArray, a => a.predicate === SpecialNodes.a) + const found = _.filter(quadArray, (a) => a.predicate === SpecialNodes.a) if (found.length !== 1) { return OntologyType.Other } @@ -454,7 +454,7 @@ Schema = { } else if (uri instanceof dataFactory.internal.NamedNode) { return this.toShortForm(rootId, uri.id) } else if (_.isArray(uri)) { - uri.map(u => this.toShortForm(u)) + uri.map((u) => this.toShortForm(u)) } else if (uri instanceof dataFactory.internal.Literal) { return uri.value } else { @@ -570,11 +570,11 @@ Schema = { comment: faker.lorem.paragraph(), parentUri: parent.toUri(root, parentName), parentName: parentName, - root: root + root: root, } return { details: def, - quads: parent.getClassQuads(root, def.name, def.parentName, def.label, def.comment) + quads: parent.getClassQuads(root, def.name, def.parentName, def.label, def.comment), } }, get datatypePropertyQuads() { @@ -585,14 +585,14 @@ Schema = { faker.lorem.words(4), faker.lorem.paragraph() ) - } + }, } - } + }, } module.exports = { Schema, SpecialNodes, SpecialUri, QuadType, - OntologyType + OntologyType, } diff --git a/knwl/store.js b/knwl/store.js index 9bf5aff..c8de1f0 100644 --- a/knwl/store.js +++ b/knwl/store.js @@ -63,10 +63,10 @@ class OntologyStore { return new Promise((resolve, reject) => { this.store .removeMatches(null, null, null) - .on('error', err => { + .on('error', (err) => { reject(err) }) - .on('end', q => { + .on('end', (q) => { console.log('The store has been emptied.') resolve() }) @@ -176,7 +176,7 @@ class OntologyStore { result.push({ uri: k, from: from, - to: to + to: to, }) } } @@ -242,12 +242,12 @@ class OntologyStore { const domainQuads = await this.getQuads({ subject: node, predicate: SpecialNodes.domain }) let domains = [] if (!_.isNil(domainQuads)) { - domains = domainQuads.map(q => q.object.id) + domains = domainQuads.map((q) => q.object.id) } const rangeQuads = await this.getQuads({ subject: node, predicate: SpecialNodes.range }) let ranges = [] if (!_.isNil(rangeQuads)) { - ranges = rangeQuads.map(q => q.object.id) + ranges = rangeQuads.map((q) => q.object.id) } const label = includeCommentAndLabel ? await this.getFirstLabel(node) : null const comment = includeCommentAndLabel ? await this.getFirstComment(node) : null @@ -275,7 +275,7 @@ class OntologyStore { const domainQuads = await this.getQuads({ subject: node, predicate: SpecialNodes.domain }) let domains = [] if (!_.isNil(domainQuads)) { - domains = domainQuads.map(q => q.object.id) + domains = domainQuads.map((q) => q.object.id) } const label = includeCommentAndLabel ? await this.getFirstLabel(node) : null const comment = includeCommentAndLabel ? await this.getFirstComment(node) : null @@ -333,7 +333,7 @@ class OntologyStore { if (_.isNil(domQuads)) { continue } - domQuads.forEach(q => { + domQuads.forEach((q) => { if (q.object.id === classId) { classProps.add(propUri) } @@ -370,7 +370,7 @@ class OntologyStore { if (_.isNil(domQuads)) { continue } - domQuads.forEach(q => { + domQuads.forEach((q) => { if (q.object.id === classId) { classProps.add(propUri) } @@ -384,12 +384,12 @@ class OntologyStore { return new Promise(async (resolve, reject) => { const quads = await this.getQuads({ predicate: SpecialNodes.a, - object: SpecialNodes.owlDatatypeProperty + object: SpecialNodes.owlDatatypeProperty, }) if (_.isNil(quads)) { resolve([]) } else { - resolve(quads.map(q => q.subject.id)) + resolve(quads.map((q) => q.subject.id)) } }) } @@ -398,12 +398,12 @@ class OntologyStore { return new Promise(async (resolve, reject) => { const quads = await this.getQuads({ predicate: SpecialNodes.a, - object: SpecialNodes.owlObjectProperty + object: SpecialNodes.owlObjectProperty, }) if (_.isNil(quads)) { resolve([]) } else { - resolve(quads.map(q => q.subject.id)) + resolve(quads.map((q) => q.subject.id)) } }) } @@ -496,13 +496,13 @@ class OntologyStore { const found = [] this.store .match(node, SpecialNodes.a, SpecialNodes.owlClass) - .on('error', err => { + .on('error', (err) => { reject(err) }) - .on('data', quad => { + .on('data', (quad) => { found.push(quad) }) - .on('end', q => { + .on('end', (q) => { resolve(found.length > 0) }) }) @@ -515,13 +515,13 @@ class OntologyStore { const found = [] this.store .match(node, SpecialNodes.a, SpecialNodes.owlObjectProperty) - .on('error', err => { + .on('error', (err) => { reject(err) }) - .on('data', quad => { + .on('data', (quad) => { found.push(quad) }) - .on('end', q => { + .on('end', (q) => { resolve(found.length > 0) }) }) @@ -534,13 +534,13 @@ class OntologyStore { const found = [] this.store .match(node, SpecialNodes.a, SpecialNodes.owlDatatypeProperty) - .on('error', err => { + .on('error', (err) => { reject(err) }) - .on('data', quad => { + .on('data', (quad) => { found.push(quad) }) - .on('end', q => { + .on('end', (q) => { resolve(found.length > 0) }) }) @@ -570,13 +570,13 @@ class OntologyStore { const found = [] this.store .match(uri, SpecialNodes.a, null) - .on('error', err => { + .on('error', (err) => { reject(err) }) - .on('data', quad => { + .on('data', (quad) => { found.push(quad) }) - .on('end', q => { + .on('end', (q) => { switch (found.length) { case 0: resolve(null) @@ -600,20 +600,20 @@ class OntologyStore { if (onlyConnected) { const links = await this.getSimplifiedObjectProperties(onlyOwn) const nodes = new Set() - links.forEach(l => { + links.forEach((l) => { nodes.add(l.from) nodes.add(l.to) }) return { nodes: Array.from(nodes), - links: links + links: links, } } else { const nodes = await this.getClassUris(onlyOwn) const links = await this.getSimplifiedObjectProperties(onlyOwn) return { nodes: nodes, - links: links + links: links, } } } diff --git a/loadData.js b/loadData.js index b6c2bed..fdb65d7 100644 --- a/loadData.js +++ b/loadData.js @@ -4,7 +4,7 @@ const Knowledge = knwl.Knowledge const knowledge = new Knowledge('http://dbpedia.org/ontology/') knowledge.clear().then(() => { knowledge.loadData(path.join(__dirname, './data/DbPedia.ttl')).then(() => { - knowledge.countTriples().then(count => { + knowledge.countTriples().then((count) => { console.log('DbPedia ontology loaded.') console.log(`There are now ${count} triples in the store.`) }) diff --git a/package.json b/package.json index 1363f1f..8973a03 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "version": "1.0.0", "private": true, "scripts": { - "preinstall": "cd ../yFiles-for-HTML-Complete-2.3.0.2-Evaluation/ && npm pack lib/es-modules/", + "preinstall": "cd ../yFiles-for-HTML-Complete-2.3.0.4-Evaluation/ && npm pack lib/es-modules/", "postinstall": "node copy-license.js", "loadData": "node loadData", "service": "node ./service", @@ -35,7 +35,7 @@ "prettier": "^1.19.1", "regenerator-runtime": "^0.13.7", "quadstore": "^5.2.0", - "yfiles": "../yFiles-for-HTML-Complete-2.3.0.2-Evaluation/yfiles-23.0.2-eval.tgz" + "yfiles": "../yFiles-for-HTML-Complete-2.3.0.4-Evaluation/yfiles-23.0.4-eval.tgz" }, "devDependencies": { "@babel/core": "^7.10.5", diff --git a/service.js b/service.js index cf53c1a..fb86e18 100644 --- a/service.js +++ b/service.js @@ -16,11 +16,11 @@ const port = 3001 app.get('/', (req, res) => res.send('This is the ontology visualizer REST backend.')) app.use('/api', api) // catch 404 and forward to error handler -app.use(function(req, res, next) { +app.use(function (req, res, next) { next(createError(404)) }) // error handler -app.use(function(err, req, res, next) { +app.use(function (err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message res.locals.error = req.app.get('env') === 'development' ? err : {} diff --git a/test/elements.js b/test/elements.js index 739be37..34e6d3d 100644 --- a/test/elements.js +++ b/test/elements.js @@ -13,10 +13,10 @@ const schema = require('../knwl/ontology').Schema const rootId = faker.internet.url() const knowledge = new Knowledge(rootId) -describe('Elements', function() { +describe('Elements', function () { this.timeout(15000) describe('OntologyClass', () => { - it('serialize', async function() { + it('serialize', async function () { const className = faker.lorem.word() const cl = new OntologyClass(rootId, className) const obj = cl.toJson() diff --git a/test/knowledge.js b/test/knowledge.js index 8ba5475..8e0bc54 100644 --- a/test/knowledge.js +++ b/test/knowledge.js @@ -12,10 +12,10 @@ const schema = require('../knwl/ontology').Schema const rootId = faker.internet.url() const knowledge = new Knowledge(rootId) -describe('Knowledge', function() { +describe('Knowledge', function () { this.timeout(150000) describe('addClass', () => { - it('should add a class', async function() { + it('should add a class', async function () { const className = faker.random.uuid() const classId = schema.toUri(rootId, className) const cls = await knowledge.addClass(className) @@ -29,7 +29,7 @@ describe('Knowledge', function() { }) describe('addObjectProperty', () => { - it('should add a new property', async function() { + it('should add a new property', async function () { const propertyName = faker.random.uuid() const domainName = faker.random.uuid() const rangeName = faker.random.uuid() @@ -37,7 +37,7 @@ describe('Knowledge', function() { const def = { name: propertyName, domain: domainName, - range: rangeName + range: rangeName, } const prop1 = await knowledge.addObjectProperty(def) @@ -53,14 +53,14 @@ describe('Knowledge', function() { }) describe('addDatatypeProperty', () => { - it('should add a new property', async function() { + it('should add a new property', async function () { const propertyName = faker.random.uuid() const domainName = faker.random.uuid() const rangeName = faker.random.uuid() const propId = schema.toUri(rootId, propertyName) const def = { name: propertyName, - domain: domainName + domain: domainName, } const prop1 = await knowledge.addDatatypeProperty(def) @@ -76,7 +76,7 @@ describe('Knowledge', function() { }) describe('getClass', () => { - it('should get the class', async function() { + it('should get the class', async function () { const className = faker.random.uuid() const classId = schema.toUri(rootId, className) const cl1 = await knowledge.addClass(className) @@ -88,7 +88,7 @@ describe('Knowledge', function() { }) describe('getAllClassUris', () => { - it('should get only own classes', async function() { + it('should get only own classes', async function () { const className = faker.random.uuid() const classId = schema.toUri(rootId, className) // add in-namespace class @@ -100,18 +100,18 @@ describe('Knowledge', function() { const all = await knowledge.getAllClassUris(false) const own = await knowledge.getAllClassUris(true) - let found = _.find(own, s => s === classId.id) + let found = _.find(own, (s) => s === classId.id) should(found).be.ok() // external should not be there - found = _.find(own, s => s === node.id) + found = _.find(own, (s) => s === node.id) should(found).not.be.ok() // but should be in the full collection - found = _.filter(all, s => s === node.id) + found = _.filter(all, (s) => s === node.id) should(found.length).be.exactly(1) }) }) describe('loadData', () => { - it('should import DbPedia', async function() { + it('should import DbPedia', async function () { await knowledge.clear() let count = await knowledge.countTriples() should(count).be.exactly(0) @@ -123,7 +123,7 @@ describe('Knowledge', function() { }) describe('getSimplifiedObjectProperties', () => { - it('should return the DbPedia object props', async function() { + it('should return the DbPedia object props', async function () { // let's take dbpedia since the testing namespace might not have any const ns = knowledge.rootId knowledge.rootId = 'http://dbpedia.org/' @@ -135,7 +135,7 @@ describe('Knowledge', function() { }) describe('getDataPropertyUrisOfClass', () => { - it('should return the data props', async function() { + it('should return the data props', async function () { // let's take dbpedia since the testing namespace might not have any const ns = knowledge.rootId knowledge.rootId = 'http://dbpedia.org/' @@ -147,7 +147,7 @@ describe('Knowledge', function() { }) }) describe('getObjectPropertyUrisOfClass', () => { - it('should return the object props', async function() { + it('should return the object props', async function () { // let's take dbpedia since the testing namespace might not have any const ns = knowledge.rootId knowledge.rootId = 'http://dbpedia.org/' diff --git a/test/schema.js b/test/schema.js index f3f15a5..4f98efa 100644 --- a/test/schema.js +++ b/test/schema.js @@ -11,56 +11,56 @@ const n3 = require('n3') const dataFactory = n3.DataFactory const { quad, namedNode, literal, defaultGraph } = dataFactory -describe('Schema', function() { +describe('Schema', function () { describe('toUri', () => { - it('should return root when no args are given', async function() { + it('should return root when no args are given', async function () { const uri = schema.toUri('http://abc/') should(uri).instanceOf(n3.DataFactory.internal.NamedNode) should(uri.id).be.equal('http://abc/') }) - it('should fix the trailing slash', async function() { + it('should fix the trailing slash', async function () { const uri = schema.toUri('http://wat.com') should(uri.id).be.equal('http://wat.com/') }) - it('should concat args', async function() { + it('should concat args', async function () { const uri = schema.toUri('http://wat.com', 'a', 'b') should(uri.id).be.equal('http://wat.com/a/b') }) - it('should recognize the named node root', async function() { + it('should recognize the named node root', async function () { const uri = schema.toUri(namedNode('http://qa.com'), 'a', 'b') should(uri.id).be.equal('http://qa.com/a/b') }) }) describe('quadType', () => { - it('should return a class type', async function() { + it('should return a class type', async function () { const q = quad(schema.random.uri, nodes.owlClass, schema.random.uri) const type = schema.getQuadType(q) should(type).be.equal(QuadType.Class) }) - it('should return an other type', async function() { + it('should return an other type', async function () { const q = quad(schema.random.uri, schema.random.uri, schema.random.uri) const type = schema.getQuadType(q) should(type).be.equal(QuadType.Other) }) }) describe('getOntologyTypeOfQuads', () => { - it('should return a class ', async function() { + it('should return a class ', async function () { const q = schema.random.classQuads const type = schema.getOntologyTypeOfQuads(q) should(type).be.equal(OntologyType.Class) }) - it('should return a property ', async function() { + it('should return a property ', async function () { const q = schema.random.datatypePropertyQuads const type = schema.getOntologyTypeOfQuads(q) should(type).be.equal(OntologyType.DatatypeProperty) }) }) describe('getClassDetailsFromQuads', () => { - it('should return all info ', async function() { + it('should return all info ', async function () { const { details, quads } = schema.random.classQuadsAndDetails const def = schema.getClassDetailsFromQuads(details.root, quads) should(def.id).be.equal(details.uri.id) diff --git a/test/store.js b/test/store.js index d5c04dc..42aa090 100644 --- a/test/store.js +++ b/test/store.js @@ -4,9 +4,9 @@ const OntologyStore = require('../knwl/store') const faker = require('faker') const store = new OntologyStore(faker.internet.url()) const schema = require('../knwl/ontology').Schema -describe('OntologyStore', function() { +describe('OntologyStore', function () { describe('addClass', () => { - it('should add a class', async function() { + it('should add a class', async function () { const className = faker.random.uuid() const parentClassName = faker.lorem.word() await store.addClass(className, parentClassName) @@ -17,7 +17,7 @@ describe('OntologyStore', function() { }) describe('getObjectPropertyQuads', () => { - it('should get the shipCrew quads', async function() { + it('should get the shipCrew quads', async function () { // getting the shipCrew props from dbpedia const ns = store.rootId store.rootId = 'http://dbpedia.org' diff --git a/webpack.config.js b/webpack.config.js index 12bb210..79adbd6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,13 +6,13 @@ const yWorksOptimizer = require('@yworks/optimizer/webpack-plugin') const config = { entry: { - app: ['core-js/stable', 'regenerator-runtime/runtime', path.resolve('app/scripts/app.js')] + app: ['core-js/stable', 'regenerator-runtime/runtime', path.resolve('app/scripts/app.js')], }, output: { path: path.resolve(__dirname, 'app/dist/'), publicPath: 'dist', - filename: '[name].js' + filename: '[name].js', }, module: { @@ -22,19 +22,19 @@ const config = { exclude: /(node_modules|bower_components|lib)/, loader: 'babel-loader', options: { - presets: ['@babel/preset-env'] - } + presets: ['@babel/preset-env'], + }, }, { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'], - sideEffects: true + sideEffects: true, }, { test: /\.(png|svg|jpg|gif)$/, - use: ['file-loader'] - } - ] + use: ['file-loader'], + }, + ], }, optimization: { splitChunks: { @@ -42,32 +42,32 @@ const config = { lib: { test: /([\\/]lib)|([\\/]node_modules[\\/])/, name: 'lib', - chunks: 'all' - } - } - } + chunks: 'all', + }, + }, + }, }, plugins: [ // https://stackoverflow.com/questions/28969861/managing-jquery-plugin-dependency-in-webpack new webpack.ProvidePlugin({ $: 'jquery', - jQuery: 'jquery' + jQuery: 'jquery', }), new MiniCssExtractPlugin({ filename: '[name].css', - chunkFilename: '[id].css' - }) - ] + chunkFilename: '[id].css', + }), + ], } -module.exports = function(env, options) { +module.exports = function (env, options) { console.log('Running webpack...') if (options.mode === 'development') { config.devServer = { contentBase: [path.join(__dirname, './app')], compress: true, - port: 9003 + port: 9003, } // don't add the default SourceMapDevToolPlugin config config.devtool = false @@ -75,7 +75,7 @@ module.exports = function(env, options) { new webpack.SourceMapDevToolPlugin({ filename: '[file].map', // add source maps for non-library code to enable convenient debugging - exclude: ['lib.js'] + exclude: ['lib.js'], }) ) } @@ -85,7 +85,7 @@ module.exports = function(env, options) { config.plugins.unshift( new yWorksOptimizer({ logLevel: 'info', - blacklist: [] + blacklist: [], }) ) }