Commit 1a04ff67 authored by tobinski's avatar tobinski
Browse files

Updated tests for geofilter

parent ddb039de
......@@ -5,7 +5,7 @@ import {Transform} from 'stream';
*/
class WikidataGeofilterTransformer extends Transform {
/**
* All valid instances iof a geographical entity
* All valid instances q-numbers of a geographical entity
*/
private geoInstances: string[];
......@@ -25,7 +25,8 @@ class WikidataGeofilterTransformer extends Transform {
// check if instance of exists
let obj;
try {
obj = JSON.parse(chunk.toString());
const data = Buffer.from(chunk.parsed.data).toString('utf8');
obj = JSON.parse(data);
} catch (err) {
return callback(null);
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,15 +2,8 @@ import chai = require('chai');
import chaiAsPromised = require('chai-as-promised');
import fs = require('fs');
import Core, {InterfaceCore} from 'geolinker-common/dist/core';
import ReporterCounter from 'geolinker-common/dist/stream/reporter-counter';
import converter from 'julian-gregorian';
import {describe, it} from 'mocha';
import nconf = require('nconf');
import WikidataNormalizerTransformer from '../src/wikidata-normalizer-transformer';
import {timeToDate, wikidataTimePropertiesLoader} from '../src/wikidata-utils';
import MockReadable from './mock-readable';
import MockReporter from './mock-reporter';
import MockWriteable from './mock-writeable';
import WikidataAnalyserTransformer from '../src/wikidata-analyser-transformer';
process.env['log-dir'] = '/tmp';
process.env.reporter_url = 'localhost:9999';
......
import chai = require('chai');
import {assert} from 'chai';
import fs = require('fs');
import {describe, it} from 'mocha';
import WikidataGeofilterTransformer from '../src/wikidata-geofilter-transformer';
process.env.NODE_ENV = 'test';
describe('Test wikidata-geofilter-transformer', () => {
before((done) => {
chai.should();
done();
});
it('Try to successfully identify a location', (done) => {
const mock = fs.readFileSync(__dirname + '/fixtures/place.json');
// build chunk
const chunk = {
parsed: {
data: Buffer.from(mock),
},
};
// Q1840161 = commune of chile a subclass of location
const geoInstances = ['Q1840161'];
const options = {
objectMode: true,
geoInstances,
};
const filter = new WikidataGeofilterTransformer(options);
// listener to check output
filter.on('data', (data) => {
data.should.be.deep.equal(chunk);
done();
});
filter.write(chunk);
});
it('Try to filter out a non location item (person)', (done) => {
const mock = fs.readFileSync(__dirname + '/fixtures/person.json');
// build chunk
const chunk = {
parsed: {
data: Buffer.from(mock),
},
};
// Q1840161 = commune of chile a subclass of location
const geoInstances = ['Q1840161'];
const options = {
objectMode: true,
geoInstances,
};
const filter = new WikidataGeofilterTransformer(options);
// listener to check output
filter.on('data', () => {
// all data are filtered no info here
assert.isTrue(false);
});
filter.on('end', () => {
done();
});
filter.write(chunk);
filter.end();
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment