-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7abbe6b
commit ee35529
Showing
14 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { Writable } from 'stream'; | ||
import type * as RDF from '@rdfjs/types'; | ||
import { DataFactory } from 'rdf-data-factory'; | ||
import type { IEnhancementContext } from './IEnhancementContext'; | ||
import type { IEnhancementHandler } from './IEnhancementHandler'; | ||
|
||
const DF = new DataFactory(); | ||
|
||
/** | ||
* Generates vocabulary information. | ||
*/ | ||
export class EnhancementHandlerVocabulary implements IEnhancementHandler { | ||
public async generate(writeStream: RDF.Stream & Writable, context: IEnhancementContext): Promise<void> { | ||
const rdf_type = DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'); | ||
const rdfs_property = DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#Property'); | ||
const rdfs_class = DF.namedNode('http://www.w3.org/2000/01/rdf-schema#Class'); | ||
|
||
// Write predicates | ||
for (const predicate of context.predicates) { | ||
writeStream.write(DF.quad(predicate, rdf_type, rdfs_property)); | ||
} | ||
// Write classes | ||
for (const clazz of context.classes) { | ||
writeStream.write(DF.quad(clazz, rdf_type, rdfs_class)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { PassThrough } from 'stream'; | ||
import { DataFactory } from 'rdf-data-factory'; | ||
import { RdfObjectLoader } from 'rdf-object'; | ||
import { Enhancer } from '../../lib/Enhancer'; | ||
import { EnhancementHandlerVocabulary } from '../../lib/handlers/EnhancementHandlerVocabulary'; | ||
import type { IEnhancementContext } from '../../lib/handlers/IEnhancementContext'; | ||
import { DataSelectorSequential } from '../selector/DataSelectorSequential'; | ||
import 'jest-rdf'; | ||
|
||
const arrayifyStream = require('arrayify-stream'); | ||
const DF = new DataFactory(); | ||
|
||
describe('EnhancementHandlerVocabulary', () => { | ||
let handler: EnhancementHandlerVocabulary; | ||
let stream: PassThrough; | ||
let rdfObjectLoader: RdfObjectLoader; | ||
let context: IEnhancementContext; | ||
|
||
beforeEach(async() => { | ||
handler = new EnhancementHandlerVocabulary(); | ||
stream = new PassThrough({ objectMode: true }); | ||
rdfObjectLoader = new RdfObjectLoader({ context: Enhancer.CONTEXT_LDBC_SNB }); | ||
context = { | ||
rdfObjectLoader, | ||
dataSelector: new DataSelectorSequential(), | ||
people: [], | ||
peopleLocatedInCities: {}, | ||
peopleKnownBy: {}, | ||
peopleKnows: {}, | ||
posts: [], | ||
comments: [], | ||
cities: [], | ||
predicates: [ | ||
DF.namedNode('ex:p1'), | ||
DF.namedNode('ex:p2'), | ||
DF.namedNode('ex:p3'), | ||
DF.namedNode('ex:p4'), | ||
], | ||
classes: [ | ||
DF.namedNode('ex:C1'), | ||
DF.namedNode('ex:C2'), | ||
DF.namedNode('ex:C3'), | ||
DF.namedNode('ex:C4'), | ||
], | ||
}; | ||
await context.rdfObjectLoader.context; | ||
}); | ||
|
||
describe('generate', () => { | ||
it('should handle for no predicates and classes', async() => { | ||
context = { ...context, predicates: [], classes: []}; | ||
await handler.generate(stream, context); | ||
stream.end(); | ||
expect(await arrayifyStream(stream)).toBeRdfIsomorphic(rdfObjectLoader.createCompactedResource({}).toQuads()); | ||
}); | ||
|
||
it('should handle', async() => { | ||
await handler.generate(stream, context); | ||
stream.end(); | ||
expect(await arrayifyStream(stream)).toBeRdfIsomorphic(rdfObjectLoader.createCompactedResources([ | ||
{ | ||
'@id': `ex:p1`, | ||
type: 'rdf:Property', | ||
}, | ||
{ | ||
'@id': `ex:p2`, | ||
type: 'rdf:Property', | ||
}, | ||
{ | ||
'@id': `ex:p3`, | ||
type: 'rdf:Property', | ||
}, | ||
{ | ||
'@id': `ex:p4`, | ||
type: 'rdf:Property', | ||
}, | ||
{ | ||
'@id': `ex:C1`, | ||
type: 'rdfs:Class', | ||
}, | ||
{ | ||
'@id': `ex:C2`, | ||
type: 'rdfs:Class', | ||
}, | ||
{ | ||
'@id': `ex:C3`, | ||
type: 'rdfs:Class', | ||
}, | ||
{ | ||
'@id': `ex:C4`, | ||
type: 'rdfs:Class', | ||
}, | ||
]).flatMap(resource => resource.toQuads())); | ||
}); | ||
}); | ||
}); |