Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
fix(ld+json): reenable jsonld now that dataset perfs are good enough
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Oct 28, 2019
1 parent da82a44 commit 5e862f7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 90 deletions.
47 changes: 14 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.1.1",
"eslint-plugin-cypress": "^2.2.0",
"eslint-plugin-import": "^2.15.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.1.3",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
Expand Down
81 changes: 40 additions & 41 deletions pages/fallback.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import rdf from 'rdf-ext'
import _get from 'lodash/get'
// https://zulip.zazuko.com/#narrow/stream/11-rdfjs/subject/jsonld.20serializer/near/4899
// import JsonLdSerializer from 'rdf-serializer-jsonld'
import JsonLdSerializer from 'rdf-serializer-jsonld'
import Structure from '@/components/fallback/Structure'
import ObjectDetails from '@/components/fallback/ObjectDetails'
Expand All @@ -107,33 +107,32 @@ export default {
let iriDataset = rdf.dataset()
let jsonld = ''
// try {
// jsonld = await new Promise((resolve, reject) => {
// iriDataset = matched(store, iri)
// if (!iriDataset) {
// resolve()
// }
// const quadStream = rdf.graph(iriDataset).toStream()
//
// const serializer = new JsonLdSerializer({ outputFormat: 'string', compact: true })
//
// const jsonStream = serializer.import(quadStream)
//
// jsonStream.on('error', (err) => {
// reject(err)
// })
// jsonStream.on('data', (jsonld) => {
// resolve(jsonld)
// })
// jsonStream.on('end', () => {
// resolve()
// })
// })
// }
// catch (err) {
// console.error(err)
// this.$sentry.captureException(err)
// }
try {
jsonld = await new Promise((resolve, reject) => {
iriDataset = matched(store, iri)
if (!iriDataset) {
resolve()
}
const quadStream = rdf.graph(iriDataset).toStream()
const serializer = new JsonLdSerializer({ outputFormat: 'string', compact: true })
const jsonStream = serializer.import(quadStream)
jsonStream.on('error', (err) => {
reject(err)
})
jsonStream.on('data', (jsonld) => {
resolve(jsonld)
})
jsonStream.on('end', () => {
resolve()
})
})
}
catch (err) {
console.error(err)
}
return {
iri,
Expand Down Expand Up @@ -270,17 +269,17 @@ export default {
}
}
// function matched (store, iri) {
// const subject = rdf.namedNode(iri)
//
// const ontologyGraph = store.getters['graph/ontologyGraph']
// const structureGraph = store.getters['graph/structureGraph']
//
// const foundInOntology = ontologyGraph.match(null, null, null, subject)
// if (foundInOntology.toArray().length) {
// return foundInOntology
// }
// const foundInStructure = structureGraph.match(null, null, null, subject)
// return foundInStructure
// }
function matched (store, iri) {
const subject = rdf.namedNode(iri)
const ontologyGraph = store.getters['graph/ontologyGraph']
const structureGraph = store.getters['graph/structureGraph']
const foundInOntology = ontologyGraph.match(null, null, null, subject)
if (foundInOntology.toArray().length) {
return foundInOntology
}
const foundInStructure = structureGraph.match(null, null, null, subject)
return foundInStructure
}
</script>
6 changes: 3 additions & 3 deletions store/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import rdf from 'rdf-ext'
import DatasetExt from 'rdf-ext/lib/Dataset'
import N3Parser from 'rdf-parser-n3'
import { Readable } from 'readable-stream'
// import resourcesToGraph from 'rdf-utils-dataset/resourcesToGraph'
import resourcesToGraph from 'rdf-utils-dataset/resourcesToGraph'
import { serialize, buildTree } from '@/libs/utils'
import { buildSearchIndex } from '@/libs/rdf'
import { DESERIALIZE, RELOAD_DATASET } from '@/store/action-types'
Expand Down Expand Up @@ -48,12 +48,12 @@ export const mutations = {
ontologyInit (state, ontologyDataset) {
state.ontologySerialized = serialize(ontologyDataset)
state.ontology = ontologyDataset
// state.ontologyGraph = resourcesToGraph(ontologyDataset)
state.ontologyGraph = resourcesToGraph(ontologyDataset)
},
structureInit (state, structureDataset) {
state.structureSerialized = serialize(structureDataset)
state.structure = structureDataset
// state.structureGraph = resourcesToGraph(structureDataset)
state.structureGraph = resourcesToGraph(structureDataset)
state.structureTree = buildTree(structureDataset, state.ontology)
},
clientReady (state) {
Expand Down
2 changes: 1 addition & 1 deletion test/.env
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CLASS_BASE_URL=http://example.com/schema/
PROPERTY_BASE_URL=http://example.com/schema/
CONTAINERS_NESTING_PREDICATE=http://schema.org/hasPart
ONTOLOGY_RAW_URL=file:./test/repo/ontology.nt
STRUCTURE_RAW_URL=./test/repo/structure.nt
STRUCTURE_RAW_URL=file:./test/repo/structure.nt

# optional
# DEBUG=graphile-build-pg,graphile-build-pg:sql,graphile-build-pg:warn,graphile-builder,graphql-parse-resolve-info,postgraphile:cli,postgraphile:graphql,postgraphile:postgres,postgraphile:postgres:error,postgraphile:request
Expand Down
18 changes: 9 additions & 9 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`basic dev Renders IRI from dataset wrt Accept header html for nt 1`] = `
"<http://localhost:3000/pouch/CargoHandlersPouch> <http://purl.org/dc/terms/modified> \\"2017-11-16\\"^^<http://www.w3.org/2001/XMLSchema#date> .
<http://localhost:3000/pouch/CargoHandlersPouch> <http://schema.org/hasPart> <http://localhost:3000/schema/Boat> .
"<http://localhost:3000/pouch/CargoHandlersPouch> <http://schema.org/hasPart> <http://localhost:3000/schema/Boat> .
<http://localhost:3000/pouch/CargoHandlersPouch> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/CreativeWork> .
<http://localhost:3000/pouch/CargoHandlersPouch> <http://www.w3.org/2000/01/rdf-schema#comment> \\"A pouch is an entity we use to logically group data elements together for the role in the logistics chain that predominantly would provide the data. It is intended to enably a quick access to schema needed. For the Cargo Handlers Pouch, you will find data typically from the following documents; TBD.\\" .
<http://localhost:3000/pouch/CargoHandlersPouch> <http://www.w3.org/2000/01/rdf-schema#label> \\"Cargo Handlers Pouch\\" .
<http://localhost:3000/pouch/CargoHandlersPouch> <http://purl.org/dc/terms/modified> \\"2017-11-16\\"^^<http://www.w3.org/2001/XMLSchema#date> .
"
`;

Expand All @@ -22,13 +22,6 @@ Array [

exports[`basic dev Renders IRI from dataset wrt Accept header jsonld in html 1`] = `
"[
{
\\"@id\\": \\"http://localhost:3000/pouch/CargoHandlersPouch\\",
\\"http://purl.org/dc/terms/modified\\": {
\\"@type\\": \\"http://www.w3.org/2001/XMLSchema#date\\",
\\"@value\\": \\"2017-11-16\\"
}
},
{
\\"@id\\": \\"http://localhost:3000/pouch/CargoHandlersPouch\\",
\\"http://schema.org/hasPart\\": {
Expand All @@ -46,6 +39,13 @@ exports[`basic dev Renders IRI from dataset wrt Accept header jsonld in html 1`]
{
\\"@id\\": \\"http://localhost:3000/pouch/CargoHandlersPouch\\",
\\"http://www.w3.org/2000/01/rdf-schema#label\\": \\"Cargo Handlers Pouch\\"
},
{
\\"@id\\": \\"http://localhost:3000/pouch/CargoHandlersPouch\\",
\\"http://purl.org/dc/terms/modified\\": {
\\"@type\\": \\"http://www.w3.org/2001/XMLSchema#date\\",
\\"@value\\": \\"2017-11-16\\"
}
}
"
`;
3 changes: 1 addition & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ describe('basic dev', () => {
expect(result.data.toLowerCase()).toContain('<!doctype html>')
})

// code generating this jsonld was removed for perf reasons
test.skip('jsonld in html', async () => {
test('jsonld in html', async () => {
const result = await getHTML('/pouch/CargoHandlersPouch')

expect(result.status).toBe(200)
Expand Down

0 comments on commit 5e862f7

Please sign in to comment.