Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding "filter_domains" to streamcorpus_pipeline, see examples/filter…
…_domains.yaml
- Loading branch information
John R. Frank
committed
May 13, 2014
1 parent
f8a2ff8
commit 7844aa7
Showing
4 changed files
with
178 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
kvlayer: &kvlayer | ||
app_name: diffeo | ||
namespace: kba2014 | ||
storage_type: redis | ||
storage_addresses: [ "redis.diffeo.com:6379" ] | ||
username: root | ||
password: secret | ||
|
||
#logging: | ||
# root: | ||
# level: INFO | ||
|
||
## This causes logs to flow into kvlayer, so the `dblogger` | ||
## command-line tool can query them. | ||
logging: | ||
handlers: | ||
dblogger: | ||
class: dblogger.DatabaseLogHandler | ||
storage_config: *kvlayer | ||
root: | ||
handlers: [ console, dblogger ] | ||
level: DEBUG | ||
|
||
streamcorpus_pipeline: | ||
level: DEBUG | ||
|
||
streamcorpus_pipeline: | ||
root_path: /data/trec-kba | ||
|
||
tmp_dir_path: /data/trec-kba/tmp | ||
cleanup_tmp_files: true | ||
|
||
reader: from_s3_chunks | ||
|
||
incremental_transforms: | ||
- filter_domains | ||
|
||
filter_domains: | ||
include_domains_path: bc-wa-domains.txt | ||
|
||
batch_transforms: [] | ||
|
||
## to_local_* must be last, because *moves* the tmp file away | ||
writers: [to_kvlayer] | ||
|
||
from_s3_chunks: | ||
aws_access_key_id_path: keys/trec-aws-s3.aws_access_key_id | ||
aws_secret_access_key_path: keys/trec-aws-s3.aws_secret_access_key | ||
bucket: aws-publicdatasets | ||
s3_path_prefix: trec/kba/kba-streamcorpus-2014-v0_3_0 | ||
tries: 10 | ||
input_format: streamitem | ||
streamcorpus_version: v0_3_0 | ||
gpg_decryption_key_path: keys/trec-kba-rsa.gpg-key.private | ||
|
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,35 @@ | ||
|
||
from streamcorpus import make_stream_item | ||
from streamcorpus_pipeline._filters import filter_domains, domain_name_cleanse, domain_name_left_cuts | ||
|
||
def test_filter_domains(tmpdir): | ||
|
||
domains_path = tmpdir.join('domains_path.txt') | ||
domains_path.write('cats.com\nhttp://birds.com/') | ||
|
||
stage = filter_domains(dict( | ||
include_domains = ['dogs.com'], | ||
include_domains_path = str(domains_path), | ||
)) | ||
|
||
assert stage.domains == set(['dogs.com', 'cats.com', 'birds.com']) | ||
|
||
si = make_stream_item(0, 'http://dogs.com/') | ||
assert stage(si) is not None | ||
|
||
si = make_stream_item(0, 'http://cats.com/') | ||
assert stage(si) is not None | ||
|
||
si = make_stream_item(0, 'http://birds.com/') | ||
assert stage(si) is not None | ||
|
||
si = make_stream_item(0, 'http://things.com/') | ||
assert stage(si) is None | ||
|
||
si = make_stream_item(0, 'http://things.com/') | ||
si.schost = 'https://birds.com' | ||
assert domain_name_cleanse(si.schost) == 'birds.com' | ||
assert stage(si) is not None | ||
|
||
def test_domain_name_left_cuts(): | ||
assert domain_name_left_cuts('www.5.cars.com') == ['www.5.cars.com', '5.cars.com', 'cars.com', 'com'] |