-
Notifications
You must be signed in to change notification settings - Fork 89
Open
Labels
enhancementsome suggestions to improve Scholiasome suggestions to improve ScholiaqleverIssues related to how Scholia interacts with QLeverIssues related to how Scholia interacts with QLever
Description
Is your feature request related to a problem? Please describe.
I want to run multiple scholia instances on a single server using different backends
Describe the solution you'd like
--config to select a config file
Describe alternatives you've considered
run multiple dockerized versions
Additional context
Implementation proposal (Clause Sonnet 4.5)
main
"""query.
Usage:
scholia arxiv-to-quickstatements [options] <arxiv>
scholia orcid-to-q <orcid>
scholia string-to-type <string>
scholia run [--config=<config_file>]
Options:
-o --output=file Output filename, default output to stdout
--config=<config_file> Path to configuration file
Examples
--------
$ python -m scholia orcid-to-q 0000-0001-6128-3356
Q20980928
$ python -m scholia run --config=/etc/scholia-qlever.ini
References
----------
https://wikidata-todo.toolforge.org/quick_statements.php
"""
from __future__ import absolute_import, division, print_function
import os
from . import arxiv
from .qs import paper_to_quickstatements
from .query import orcid_to_qs
from .utils import string_to_type
def main():
"""Handle command-line interface."""
from docopt import docopt
arguments = docopt(__doc__)
if arguments['--output']:
output_filename = arguments['--output']
output_file = os.open(output_filename, os.O_RDWR | os.O_CREAT)
else:
# stdout
output_file = 1
output_encoding = 'utf-8'
if arguments['arxiv-to-quickstatements']:
arxiv_id = arguments['<arxiv>']
metadata = arxiv.get_metadata(arxiv_id)
quickstatements = paper_to_quickstatements(metadata)
os.write(output_file, quickstatements.encode(output_encoding))
elif arguments['orcid-to-q']:
qs = orcid_to_qs(arguments['<orcid>'])
if len(qs) > 0:
print(qs[0])
elif arguments['string-to-type']:
type = string_to_type(arguments['<string>'])
print(type)
elif arguments['run']:
# Set config file path if provided
if arguments['--config']:
os.environ['SCHOLIA_CONFIG'] = arguments['--config']
from .app import create_app
app = create_app(
text_to_topic_q_text_enabled=False,
third_parties_enabled=True,
)
app.config['APPLICATION_ROOT'] = '/'
app.run(debug=True, port=8100)
if __name__ == '__main__':
main()config.py
"""config.
Usage:
scholia.config
"""
import configparser
import os
from io import StringIO
from os.path import exists, expanduser
CONFIG_FILENAMES = [
'scholia.ini',
'~/etc/scholia.ini',
'~/scholia.ini']
DEFAULTS = """
[query-server]
sparql_endpoint = https://query-legacy-full.wikidata.org/sparql
sparql_editurl = https://query-legacy-full.wikidata.org/#
sparql_embedurl = https://query-legacy-full.wikidata.org/embed.html#
sparql_endpoint_name = WDQS legacy-full-graph
frontend_port=8100
[requests]
user_agent = Scholia
"""
config = configparser.ConfigParser()
config.read_file(StringIO(DEFAULTS))
# Check if a config file is specified via environment variable
config_from_env = os.environ.get('SCHOLIA_CONFIG')
if config_from_env:
full_filename = expanduser(config_from_env)
if exists(full_filename):
config.read(full_filename)
else:
raise FileNotFoundError(f"Config file not found: {full_filename}")
else:
# Use default config file search
for filename in CONFIG_FILENAMES:
full_filename = expanduser(filename)
if exists(full_filename):
config.read(full_filename)
break
if __name__ == '__main__':
for section in config.sections():
print(f"[{section}]")
for key in config[section]:
print(f"{key} = {config[section].get(key)}")
print()Metadata
Metadata
Assignees
Labels
enhancementsome suggestions to improve Scholiasome suggestions to improve ScholiaqleverIssues related to how Scholia interacts with QLeverIssues related to how Scholia interacts with QLever