/
citationxpert
executable file
·149 lines (119 loc) · 5.91 KB
/
citationxpert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
#
# Copyright 2016 Rafael Ferreira da Silva
# http://www.rafaelsilva.com/tools
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
__author__ = "Rafael Ferreira da Silva"
import logging
import sys
from optparse import OptionParser, OptionGroup
from operations import author
from operations import author_map
from operations import citations
from operations import h_index
from operations import self_reference
# from operations import area_interest
from tools import utils
log = logging.getLogger(__name__)
VERSION = "CitationXpert 1.1.0"
def option_parser(usage):
"""
Parse the command line options.
:param usage: tool usage string
:return: parsed options and arguments
"""
parser = OptionParser(usage="usage: %s" % usage, version=VERSION,
description="CitationXpert: an open-source citation analysis tool based on Google Scholar",
epilog="Documentation and releases are available at: "
"http://www.rafaelsilva.com/tools/citationxpert")
parser.add_option("-c", "--citations", dest="pub_titles", action="append", type="string",
default=None, help="Get all citations for a publication")
parser.add_option("-i", "--input", dest="input_file", action="append",
help="Citations or Authors file (required by most analyses). Can be used multiple times")
parser.add_option("-o", "--output", action="store", type="string",
dest="output", default=None, help="Output file name")
parser.add_option("-p", "--plot", dest="plot", action="store_true",
default=False, help="Plot graph(s)")
analysis_group = OptionGroup(parser, "Analysis Options")
analysis_group.add_option("-s", "--self", dest="analysis_self", action="store_true", default=False,
help="Analysis of the number of self- and external references (requires at least one "
"citations file)")
analysis_group.add_option("-H", "--hindex", dest="analysis_hindex", action="store_true", default=False,
help="Analysis of the publication-h-index (requires at least one citations file)")
analysis_group.add_option("-a", "--author", dest="analysis_author", action="store_true", default=False,
help="Analysis of authors citing the publication (requires at least one citations file)")
analysis_group.add_option("-m", "--authors-map", dest="analysis_authorm", action="store_true", default=False,
help="Create a map of authors (requires at least one authors file generated with '-a')")
analysis_group.add_option("-A", "--area", dest="analysis_area", action="store_true", default=False,
help="Analysis of authors' area of interest (requires at least one authors file "
"generated with '-a')")
parser.add_option_group(analysis_group)
logging_group = OptionGroup(parser, "Logging Options")
logging_group.add_option("-d", "--debug", dest="debug", action="store_true",
default=False, help="Turn on debugging")
logging_group.add_option("-v", "--verbose", dest="verbose", action="store_true",
default=False, help="Show progress messages")
parser.add_option_group(logging_group)
fn = parser.parse_args
def parse(*args, **kwargs):
options, args = fn(*args, **kwargs)
if options.debug:
utils.configure_logging(level=logging.DEBUG)
elif options.verbose:
utils.configure_logging(level=logging.INFO)
else:
utils.configure_logging(logging.WARNING)
return options, args
parser.parse_args = parse
return parser
def main():
args = sys.argv[1:]
parser = option_parser("citationxpert [OPTIONS]")
options, args = parser.parse_args(args)
if options.output:
output_file = open(options.output, 'w')
log.info("Writing entries to '%s'." % options.output)
else:
output_file = None
if options.pub_titles:
# Get citations
citations.process(options.pub_titles, output=output_file)
elif options.analysis_self:
# Self- and external references
self_reference.process(_check_input_file(options.input_file), output=output_file, plot=options.plot)
elif options.analysis_hindex:
# Publication h-index
h_index.process(_check_input_file(options.input_file), output=output_file, plot=options.plot)
elif options.analysis_author:
# Analysis of authors
author.process(_check_input_file(options.input_file), output=output_file, plot=options.plot)
elif options.analysis_authorm:
# Create authors map
author_map.process(_check_input_file(options.input_file), output=output_file)
# elif options.analysis_area:
# area_interest.process(_check_input_file(options.input_file), output=output_file, plot=options.plot)
else:
parser.print_help()
exit(1)
if output_file:
print "The analysis output was written to: %s" % options.output
def _check_input_file(input_file):
if not input_file:
log.error("This option requires an input file. Please, specify one or multiple input files using the '-i' "
"option.")
exit(1)
return input_file
if __name__ == '__main__':
main()