Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
histhub
wikidata-lib
Commits
1a04ff67
Commit
1a04ff67
authored
Oct 10, 2019
by
tobinski
Browse files
Updated tests for geofilter
parent
ddb039de
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/wikidata-geofilter-transformer.ts
View file @
1a04ff67
...
...
@@ -5,7 +5,7 @@ import {Transform} from 'stream';
*/
class
WikidataGeofilterTransformer
extends
Transform
{
/**
* All valid instances
i
of 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
);
}
...
...
test/fixtures/person.json
0 → 100644
View file @
1a04ff67
This source diff could not be displayed because it is too large. You can
view the blob
instead.
test/wikidata-analyser-transformer.spec.ts
View file @
1a04ff67
...
...
@@ -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
'
;
...
...
test/wikidata-geofilter-transformer.spec.ts
0 → 100644
View file @
1a04ff67
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
();
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment