mirror of
https://github.com/adulau/napkin-text-analysis.git
synced 2024-11-22 01:47:06 +00:00
chg: [output] make readable table-like with bold headers
Official request from @C00kie-
This commit is contained in:
parent
2c295e79cf
commit
98a8d8275e
2 changed files with 9 additions and 7 deletions
|
@ -37,7 +37,7 @@ optional arguments:
|
|||
-f F file to analyse
|
||||
-t T maximum value for the top list (default is 100) -1 is no limit
|
||||
-s display the overall statistics (default is False)
|
||||
-o O output format (default is csv), json
|
||||
-o O output format (default is csv), json, readable
|
||||
-l L language used for the analysis (default is en)
|
||||
--verbatim Don't use the lemmatized form, use verbatim. (default is the
|
||||
lematized form)
|
||||
|
|
|
@ -7,6 +7,7 @@ from spacy_langdetect import LanguageDetector
|
|||
import argparse
|
||||
import sys
|
||||
import simplejson as json
|
||||
from tabulate import tabulate
|
||||
|
||||
parser = argparse.ArgumentParser(description="Extract statistical analysis of text")
|
||||
parser.add_argument('-v', help="verbose output")
|
||||
|
@ -120,9 +121,8 @@ for anal in analysis:
|
|||
if args.o == "csv":
|
||||
print()
|
||||
elif args.o == "readable":
|
||||
print("")
|
||||
print("+++++ Top {} of {} +++++".format(args.t, anal))
|
||||
print("")
|
||||
header = ["\033[1mTop {} of {}\033[0m".format(args.t, anal)]
|
||||
readable_table = []
|
||||
elif args.o == "json":
|
||||
output_json.update({anal:[]})
|
||||
for a in x:
|
||||
|
@ -132,13 +132,15 @@ for anal in analysis:
|
|||
if previous_value is None:
|
||||
previous_value = a[1]
|
||||
elif previous_value == a[1]:
|
||||
print(" - {}".format(a[0]))
|
||||
readable_table.append(["{}".format(a[0])])
|
||||
elif a[1] < previous_value:
|
||||
previous_value = a[1]
|
||||
print(" ### {} occurences".format(a[1]))
|
||||
print(" - {}".format(a[0]))
|
||||
readable_table.append(["{} occurences".format(a[1])])
|
||||
readable_table.append(["{}".format(a[0])])
|
||||
elif args.o == "json":
|
||||
output_json[anal].append(a)
|
||||
if args.o == "readable":
|
||||
print(tabulate(readable_table, header, tablefmt="fancy_grid"))
|
||||
if args.o == "csv":
|
||||
print("#")
|
||||
|
||||
|
|
Loading…
Reference in a new issue