Skip to content

Commit

Permalink
Add bsdetector command-line entry point.
Browse files Browse the repository at this point in the history
- Fix typo
  • Loading branch information
mrs83 committed Mar 19, 2018
1 parent 073eccd commit 986f24c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
21 changes: 21 additions & 0 deletions bsdetector/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import argparse
from bsdetector.bias import get_text_from_article_file, print_feature_data


DESC = "Biased Statement Detection explains why english prose text is biased."


def main():
parser = argparse.ArgumentParser(description=DESC)
parser.add_argument("-i", dest="filename", required=True,
help="Input file", metavar="FILE")
parser.add_argument("-o", dest="output", required=False,
help="Output type", metavar="OUTPUT",
default='json', choices=['tsv', 'json', 'html'])
args = parser.parse_args()
sentence_list = get_text_from_article_file(args.filename).split('\n')
print_feature_data(sentence_list, output_type=args.output)


if __name__ == '__main__':
main()
24 changes: 1 addition & 23 deletions bsdetector/bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def make_dict_output(list_of_sentences):
if len(sent) >= 1:
feature_data = extract_bias_features(sent)
feature_data['text'] = sent
data.insert(0, feature_data)
data.append(feature_data)
return data


Expand Down Expand Up @@ -636,25 +636,3 @@ def enumerate_sentences(fpath='input_text'):
yield(biasq, statement)
else:
print('-- Statement is too short: {}'.format(statement))



if __name__ == '__main__':
# Demo article file
# print(compute_avg_statement_bias_mp(get_text_from_article_file("news_articles/brexit_01.txt"), 4))
'''FPATH = 'input_text'
for bias, stmt in enumerate_sentences(FPATH):
msg = 'Bias: {}\t {}'.format(bias, stmt)
print(msg)
NEWSPATH = "news_articles/brexit_01.txt"
print('loading news article: {}'.format(NEWSPATH), file=sys.stderr)
STATEMENT = get_text_from_article_file(NEWSPATH)
print(compute_avg_statement_bias(STATEMENT))'''

demo_output_types = True
if demo_output_types:
sentence_list = get_text_from_article_file('input_text').split('\n')#[:2]
print_feature_data(sentence_list, output_type='json')
#cstr_summary_terms = get_caster(" ".join(sentence_list))
#print(cstr_summary_terms)
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def run(self):
description="Detects biased statements in online media documents",
url='url',
cmdclass={
'install': PostInstallCommand,
'install': PostInstallCommand
},
entry_points={
'console_scripts': [
'bsdetector = bsdetector.__main__:main'
]
}
)

0 comments on commit 986f24c

Please sign in to comment.