def both(request): retrieve_and_rank = RetrieveAndRankV1( username='******', password='******') solr_clusters = retrieve_and_rank.list_solr_clusters() print(json.dumps(solr_clusters, indent=2)) solr_cluster_id = 'scff9ea129_c91c_46d2_ad7e_036880c59805' status = retrieve_and_rank.get_solr_cluster_status( solr_cluster_id=solr_cluster_id) print(json.dumps(status, indent=2)) configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id) print(json.dumps(configs, indent=2)) if len(configs['solr_configs']) > 0: collections = retrieve_and_rank.list_collections( solr_cluster_id=solr_cluster_id) pysolr_client = retrieve_and_rank.get_pysolr_client( solr_cluster_id, collections['collections'][0]) ranker = retrieve_and_rank.list_rankers()['rankers'][0] ranker_id = str(ranker['ranker_id'].decode('utf-8')) query = '*' + request + '*' results = pysolr_client.search(q=query, search_handler='/fcselect', kwargs={'ranker_id': ranker_id}) print('{0} documents found'.format(len(results.docs))) return results.docs
def getWatsonConnection(): retrieve_and_rank = RetrieveAndRankV1( username='******', password='******') solr_clusters = retrieve_and_rank.list_solr_clusters() print(json.dumps(solr_clusters, indent=2)) solr_cluster_id = 'scff9ea129_c91c_46d2_ad7e_036880c59805' status = retrieve_and_rank.get_solr_cluster_status( solr_cluster_id=solr_cluster_id) print(json.dumps(status, indent=2)) configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id) print(json.dumps(configs, indent=2)) if len(configs['solr_configs']) > 0: collections = retrieve_and_rank.list_collections( solr_cluster_id=solr_cluster_id) print(json.dumps(collections, indent=2)) pysolr_client = retrieve_and_rank.get_pysolr_client( solr_cluster_id, collections['collections'][0]) return pysolr_client
def _handle_exception(self, ex, num_attempts, message): if num_attempts < self._MAX_RETRIES: self.logger.warn("%s. Retrying." % message) # re-initiating the connection sometimes does the trick self.bluemix_connection = RetrieveAndRankV1(url=self.bluemix_url, username=self.bluemix_user, password=self.bluemix_password) else: raise RuntimeError("%s. Giving up on re-attempts, last failure reason: %s" % (message, ex)) from ex
def rrQuery(query, cluster, col): retrieve_and_rank = RetrieveAndRankV1(username=cred.RRUSER, password=cred.RRPASS) results = {} try: pysolr_client = retrieve_and_rank.get_pysolr_client(cluster, col) results = pysolr_client.search(query).docs except: results = {} return results
def initialize_ranker_connection(credentials_file): """ Initializes and returns a RetrieveAndRankV1 object to use for the experiment based on the credentials in the credentials file :param File credentials_file: :return: RetrieveAndRankV1 object initialized with the provided credentials :rtype: RetrieveAndRankV1 """ bluemix_url, user, password = parse_credentials(credentials_file) return RetrieveAndRankV1(url=bluemix_url, username=user, password=password)
def hello(request): retrieve_and_rank = RetrieveAndRankV1( username=cred.RRUSER, password=cred.RRPASS) context = { 'greeting':'Hello World!', 'status': helpers.WatsonStatus() } return render(request, 'Migr8/index.html', context)
def __init__(self, config=load_config(), logger=initialize_logger(logging.INFO, 'BluemixServiceProxy')): """ :param ConfigParser config: for access to credentials :param logging.Logger logger: for logging """ self.logger = logger self.config = config self.bluemix_url, self.bluemix_user, self.bluemix_password = get_rnr_credentials(config) self.bluemix_connection = RetrieveAndRankV1(url=self.bluemix_url, username=self.bluemix_user, password=self.bluemix_password)
def check_status(credentials): #check the status of the ranker RANKER_ID = credentials['ranker_id'] USERNAME = credentials['username'] PASSWORD = credentials['password'] retrieve_and_rank = RetrieveAndRankV1(username=USERNAME, password=PASSWORD) #Running command that checks the status of a ranker output = retrieve_and_rank.get_ranker_status(RANKER_ID) status = output['status'] ranker_id = output['ranker_id'] print(status) return status, ranker_id
def retrieveRank(question, topic): with open('rr-config.json') as credentials_file: credentials = json.load(credentials_file) retrieve_and_rank = RetrieveAndRankV1( username=credentials['credentials']['username'], password=credentials['credentials']['password']) # Replace with your own solr_cluster_id solr_clusters = retrieve_and_rank.list_solr_clusters() solr_cluster_id = solr_clusters['clusters'][0]['solr_cluster_id'] pysolr_client = retrieve_and_rank.get_pysolr_client( solr_cluster_id, topic.upper()) # Can also refer to config by name # Example search results = pysolr_client.search(question) #print results.docs #return results.docs return results.docs[0]['body'][0]
def retrain_ranker(TRAINING_DATA, credentials, ranker_id, CSV): delete_result = delete_old_ranker(credentials, ranker_id) BASEURL = credentials['url'] SOLRURL = BASEURL + "solr_clusters/" RANKER_URL = BASEURL + "rankers" USERNAME = credentials['username'] PASSWORD = credentials['password'] SOLR_CLUSTER_ID = credentials['cluster_id'] COLLECTION_NAME = credentials['collection_name'] #TRAIN_FILE_PATH='' GROUND_TRUTH_FILE = './static/Historic_Data/' + CSV RANKER_NAME = "travel_ranker" retrieve_and_rank = RetrieveAndRankV1(username=USERNAME, password=PASSWORD) #Running command that trains a ranker cmd = 'python train.py -u %s:%s -i %s -c %s -x %s -n %s' %\ (USERNAME, PASSWORD, GROUND_TRUTH_FILE, SOLR_CLUSTER_ID, COLLECTION_NAME,RANKER_NAME ) try: process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) output = process.communicate()[0] output = output.decode("utf-8") print(output) except: print('Command:') print(cmd) print('Response:') print(output) # creat ranker with open(TRAINING_DATA, 'r') as training_data: ranker_output = retrieve_and_rank.create_ranker( training_data=training_data, name=RANKER_NAME) try: print(json.dumps(ranker_output, sort_keys=True, indent=4)) credentials['ranker_id'] = ranker_output['ranker_id'] except: print('Command:') print(cmd) print('Response:') print(ranker_output) return credentials
def find_document(question): """ user rank and retrieve to find the appropriate document and return the answer to the users question """ retrieve_and_rank = RetrieveAndRankV1( username=app.config['RAR_WATSON_USERNAME'], password=app.config['RAR_WATSON_PASSWORD']) pysolr_client = retrieve_and_rank.get_pysolr_client( app.config['RAR_WATSON_CLUSTER_ID'], app.config['RAR_WATSON_COLLECTION_NAME']) results = pysolr_client.search(question) if (len(results.docs) > 0): return results.docs[0]['body'][0] # no results found # TODO better error handling but this is due tomorrow.. return "I am sorry I was unable to find an answer to your question"
def WatsonStatus(): retrieve_and_rank = RetrieveAndRankV1(username=cred.RRUSER, password=cred.RRPASS) nlc = NaturalLanguageClassifierV1(username=cred.NLCUSER, password=cred.NLCPASS) status = {} status2 = {} timeout = eventlet.Timeout(3, True) try: status2 = nlc.status(cred.NLCCLUSTER) status = retrieve_and_rank.get_solr_cluster_status( solr_cluster_id=cred.CLUSTERID) except: status = { "solr_cluster_status": "Retrieve and Rank Unable to be Reached." } status2 = { "status_description": "Natural Language Classifier Unable to be reached" } finally: timeout.cancel() return status["solr_cluster_status"], status2["status_description"]
def retrieveRankFunction(inp): # 4 spaces retrieve_and_rank = RetrieveAndRankV1(username='******', password='******') # checking out our clusters solr_clusters = retrieve_and_rank.list_solr_clusters() #print(json.dumps(solr_clusters, indent=2)) # Replace with your own solr_cluster_id solr_cluster_id = 'sce8bd4302_0e95_4499_9dbf_f97d52b0cba4' #changing to our cluster #status = retrieve_and_rank.get_solr_cluster_status(solr_cluster_id=solr_cluster_id) #print(json.dumps(status, indent=2)) configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id) #print(json.dumps(configs, indent=2)) if len(configs['solr_configs']) > 0: collections = retrieve_and_rank.list_collections(solr_cluster_id=solr_cluster_id) pysolr_client = retrieve_and_rank.get_pysolr_client(solr_cluster_id, collections['collections'][0]) #search_for = input("Was soll ich übersetzen?: ") search_for = inp if search_for == 'NG312' or search_for == 'SE1201'or search_for == 'SF6142'or search_for == 'NN400'or search_for == 'NW811': info2 = 'Keine Information vorhanden. ' else: results = pysolr_client.search(search_for) resultingString = str(results.docs) description = re.search('</td><td><p dir="ltr">(.+?)</p></td></tr> <tr><td>',resultingString) info = description.group(1) info2 = re.sub('<.*?>', '', info) #print(description.group(1)) #print(info) return(info2) return
try: opts, args = getopt.getopt(sys.argv[1:],'hdi:',['cluster_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-i', '---cluster_id'): cluster_id = arg elif opt == '-d': DEBUG = True if not cluster_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr config retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.get_solr_cluster_status(cluster_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
try: opts, args = getopt.getopt(sys.argv[1:],'hdi:',['cluster_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-i', '---cluster_id'): cluster_id = arg elif opt == '-d': DEBUG = True if not cluster_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr config retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.list_configs(cluster_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
opts, args = getopt.getopt(sys.argv[1:], 'hdi:', ['cluster_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-i', '---cluster_id'): cluster_id = arg elif opt == '-d': DEBUG = True if not cluster_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr config retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.list_configs(cluster_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
def get_retrieve_and_rank(username, password): retrieve_and_rank = RetrieveAndRankV1(username=username, password=password) return retrieve_and_rank
def usage(): print( 'rnrListRankers.py -d [enable debug output for script] -v [enable verbose output for curl]' ) try: opts, args = getopt.getopt(sys.argv[1:], "hd", []) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt == '-d': DEBUG = True try: # list Solr cluster retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.list_rankers() sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
opts, args = getopt.getopt(sys.argv[1:], 'hdi:', ['cluster_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-i', '---cluster_id'): cluster_id = arg elif opt == '-d': DEBUG = True if not cluster_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr config retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.delete_solr_cluster(cluster_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
from watson_developer_cloud import RetrieveAndRankV1 as RetrieveAndRank DEBUG=False VERBOSE=False def usage(): print('rnrListSolrClusters.py -d [enable debug output for script] -v [enable verbose output for curl]') try: opts, args = getopt.getopt(sys.argv[1:],"hd",[]) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt == '-d': DEBUG = True try: # list Solr cluster retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.list_solr_clusters() sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
def retrieve_and_rank(query): retrieve_and_rank = RetrieveAndRankV1( username='******', password='******') # Solr clusters solr_clusters = retrieve_and_rank.list_solr_clusters() print(json.dumps(solr_clusters, indent=2)) # created_cluster = retrieve_and_rank.create_solr_cluster(cluster_name='Test Cluster', cluster_size='1') # print(json.dumps(created_cluster, indent=2)) # Replace with your own solr_cluster_id solr_cluster_id = 'sc02724585_eb06_46f4_892b_d188f15ea615' status = retrieve_and_rank.get_solr_cluster_status( solr_cluster_id=solr_cluster_id) print(json.dumps(status, indent=2)) # Solr cluster config # with open('../resources/solr_config.zip', 'rb') as config: # config_status = retrieve_and_rank.create_config(solr_cluster_id, 'test-config', config) # print(json.dumps(config_status, indent=2)) # deleted_response = retrieve_and_rank.delete_config(solr_cluster_id, 'test-config') # print(json.dumps(deleted_response, indent=2)) configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id) print(json.dumps(configs, indent=2)) # collection = retrieve_and_rank.create_collection(solr_cluster_id, 'test-collection', 'test-config') # print(json.dumps(collection, indent=2)) if len(configs['solr_configs']) > 0: collections = retrieve_and_rank.list_collections( solr_cluster_id=solr_cluster_id) print(json.dumps(collections, indent=2)) pysolr_client = retrieve_and_rank.get_pysolr_client( solr_cluster_id, collections['collections'][0]) # Can also refer to config by name results = pysolr_client.search('*' + query + '*') print('{0} documents found'.format(len(results.docs))) return results.docs # Rankers # rankers = retrieve_and_rank.list_rankers() # print(json.dumps(rankers, indent=2)) # create a ranker # with open('../resources/ranker_training_data.csv', 'rb') as training_data: # print(json.dumps(retrieve_and_rank.create_ranker(training_data=training_data, name='Ranker Test'), indent=2)) # replace YOUR RANKER ID # status = retrieve_and_rank.get_ranker_status('42AF7Ex10-rank-47') # print(json.dumps(status, indent=2)) # delete_results = retrieve_and_rank.delete_ranker('YOUR RANKER ID') # print(json.dumps(delete_results)) # replace '42AF7Ex10-rank-47' with your ranker_id # with open('../resources/ranker_answer_data.csv', 'rb') as answer_data: # ranker_results = retrieve_and_rank.rank('42AF7Ex10-rank-47', answer_data) # print(json.dumps(ranker_results, indent=2))
try: opts, args = getopt.getopt(sys.argv[1:],'hdr:',['ranker_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-r', '---ranker_id'): ranker_id = arg elif opt == '-d': DEBUG = True if not ranker_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr cluster retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.delete_ranker(ranker_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
opts, args = getopt.getopt(sys.argv[1:], 'hdr:', ['ranker_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-r', '---ranker_id'): ranker_id = arg elif opt == '-d': DEBUG = True if not ranker_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr cluster retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.delete_ranker(ranker_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
import json from watson_developer_cloud import RetrieveAndRankV1 as RetrieveAndRank retrieve_and_rank = RetrieveAndRank(username='******', password='******') # Solr clusters solr_clusters = retrieve_and_rank.list_solr_clusters() print(json.dumps(solr_clusters, indent=2)) # created_cluster = retrieve_and_rank.create_solr_cluster(cluster_name='Test Cluster', cluster_size='1') # print(json.dumps(created_cluster, indent=2)) # Replace with your own solr_cluster_id solr_cluster_id = 'sc31a30e84_9094_4af2_93af_a8751257d4cc' status = retrieve_and_rank.get_solr_cluster_status( solr_cluster_id=solr_cluster_id) print(json.dumps(status, indent=2)) # Solr cluster config # with open('../resources/solr_config.zip', 'rb') as config: # config_status = retrieve_and_rank.create_config(solr_cluster_id, 'test-config', config) # print(json.dumps(config_status, indent=2)) configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id) print(json.dumps(configs, indent=2)) # collection = retrieve_and_rank.create_collection(solr_cluster_id, 'test-collection', 'test-config') # print(json.dumps(collection, indent=2))
from ibmcloudenv import IBMCloudEnv from watson_developer_cloud import RetrieveAndRankV1 retrieve_and_rank = RetrieveAndRankV1( username=IBMCloudEnv.getString('watson_retrieve_and_rank_username'), password=IBMCloudEnv.getString('watson_retrieve_and_rank_password')) <% if (bluemix.backendPlatform.toLowerCase() === 'python') { %> def getService(app): return 'watson-retrieve-and-rank', retrieve_and_rank <% } else { %> def getService(): return 'watson-retrieve-and-rank', retrieve_and_rank <% } %>
opts, args = getopt.getopt(sys.argv[1:], 'hdi:', ['cluster_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-i', '---cluster_id'): cluster_id = arg elif opt == '-d': DEBUG = True if not cluster_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr config retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.get_solr_cluster_status(cluster_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
SHOW_DEFAULT_RANKER = os.getenv('SHOW_DEFAULT_RANKER') # disable file logging #setup_file_logger() url = os.getenv('RETRIEVE_AND_RANK_BASE_URL') username = os.getenv('RETRIEVE_AND_RANK_USERNAME') password = os.getenv('RETRIEVE_AND_RANK_PASSWORD') cluster_id = os.getenv('SOLR_CLUSTER_ID') collection_name = os.getenv('SOLR_COLLECTION_NAME') feature_json_file = os.getenv('FEATURE_FILE') answer_directory = os.getenv('ANSWER_DIRECTORY') # custom scorer custom_scorers = Scorers(feature_json_file) app.scorers = FcSelect(custom_scorers, url, username, password, cluster_id, collection_name, answer_directory) # Retrieve and Rank retrieve_and_rank = RetrieveAndRankV1(url=url, username=username, password=password) app.pysolr_client = retrieve_and_rank.get_pysolr_client( cluster_id, collection_name) # Start the server print( 'Starting with SHOW_DEFAULT_RANKER set to %s on port: %d on host : %s' % (SHOW_DEFAULT_RANKER, PORT_NUMBER, HOST_NAME)) app.run(host=HOST_NAME, port=PORT_NUMBER, debug=False) print('Listening on %s:%d' % (HOST_NAME, PORT_NUMBER))
from watson_developer_cloud import RetrieveAndRankV1 as RetrieveAndRank DEBUG=False VERBOSE=False def usage(): print('rnrListRankers.py -d [enable debug output for script] -v [enable verbose output for curl]') try: opts, args = getopt.getopt(sys.argv[1:],"hd",[]) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt == '-d': DEBUG = True try: # list Solr cluster retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.list_rankers() sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
import sys import numpy as np import re import json from watson_developer_cloud import RetrieveAndRankV1 retrieve_and_rank = RetrieveAndRankV1( username='******', password='******') solr_clusters = retrieve_and_rank.list_solr_clusters() print(json.dumps(solr_clusters, indent=2)) solr_cluster_id = 'sc8cceb75a_943a_4fdf_8a9e_bfaa1ddc9f70' status = retrieve_and_rank.get_solr_cluster_status(solr_cluster_id=solr_cluster_id) print(json.dumps(status, indent=2)) configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id) print(json.dumps(configs, indent=2)) from xlrd import open_workbook wb = open_workbook('/Users/vincent/Downloads/Mapping.xls') for s in wb.sheets(): values = [] for row in range(s.nrows): col_value = [] for col in range(s.ncols): value = (s.cell(row,col).value)
opts, args = getopt.getopt(sys.argv[1:], 'hdr:', ['ranker_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-r', '---ranker_id'): ranker_id = arg elif opt == '-d': DEBUG = True if not ranker_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr cluster retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.get_ranker_status(ranker_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
try: opts, args = getopt.getopt(sys.argv[1:],'hdr:',['ranker_id=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-r', '---ranker_id'): ranker_id = arg elif opt == '-d': DEBUG = True if not ranker_id: print('Required argument missing.') usage() sys.exit(2) try: # list Solr cluster retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.get_ranker_status(ranker_id) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
import json from watson_developer_cloud import RetrieveAndRankV1 retrieve_and_rank = RetrieveAndRankV1(username='******', password='******') # Solr clusters solr_clusters = retrieve_and_rank.list_solr_clusters() print(json.dumps(solr_clusters, indent=2)) # created_cluster = retrieve_and_rank.create_solr_cluster(cluster_name='Test Cluster', cluster_size='1') # print(json.dumps(created_cluster, indent=2)) # Replace with your own solr_cluster_id solr_cluster_id = 'sc1264f746_d0f7_4840_90be_07164e6ed04b' status = retrieve_and_rank.get_solr_cluster_status( solr_cluster_id=solr_cluster_id) print(json.dumps(status, indent=2)) # Solr cluster config # with open('../resources/solr_config.zip', 'rb') as config: # config_status = retrieve_and_rank.create_config(solr_cluster_id, 'test-config', config) # print(json.dumps(config_status, indent=2)) # deleted_response = retrieve_and_rank.delete_config(solr_cluster_id, 'test-config') # print(json.dumps(deleted_response, indent=2)) configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id) print(json.dumps(configs, indent=2))
print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-n', '---cluster_name'): cluster_name = arg elif opt in ('-s', '---cluster_size'): cluster_size = arg elif opt == '-d': DEBUG = True if not cluster_name: print('Required argument missing.') usage() sys.exit(2) try: # list Solr config retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.create_solr_cluster(cluster_name, cluster_size) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)
import json from watson_developer_cloud import RetrieveAndRankV1 as RetrieveAndRank retrieve_and_rank = RetrieveAndRank(username='******', password='******') # Solr clusters solr_clusters = retrieve_and_rank.list_solr_clusters() print(json.dumps(solr_clusters, indent=2)) # created_cluster = retrieve_and_rank.create_solr_cluster(cluster_name='Test Cluster', cluster_size='1') # print(json.dumps(created_cluster, indent=2)) # Replace with your own solr_cluster_id solr_cluster_id = 'sc31a30e84_9094_4af2_93af_a8751257d4cc' status = retrieve_and_rank.get_solr_cluster_status(solr_cluster_id=solr_cluster_id) print(json.dumps(status, indent=2)) # Solr cluster config # with open('../resources/solr_config.zip', 'rb') as config: # config_status = retrieve_and_rank.create_config(solr_cluster_id, 'test-config', config) # print(json.dumps(config_status, indent=2)) configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id) print(json.dumps(configs, indent=2)) # collection = retrieve_and_rank.create_collection(solr_cluster_id, 'test-collection', 'test-config') # print(json.dumps(collection, indent=2))
opts, args = getopt.getopt(sys.argv[1:],'hdn:s:',['cluster_name=','cluster_size=']) except getopt.GetoptError as err: print(str(err)) print(usage()) sys.exit(2) for opt, arg in opts: if opt == '-h': usage() sys.exit() elif opt in ('-n', '---cluster_name'): cluster_name = arg elif opt in ('-s', '---cluster_size'): cluster_size = arg elif opt == '-d': DEBUG = True if not cluster_name: print('Required argument missing.') usage() sys.exit(2) try: # list Solr config retrieve_and_rank = RetrieveAndRank(url=rnrConstants.getUrl(), username=rnrConstants.getUsername(), password=rnrConstants.getPassword()) res = retrieve_and_rank.create_solr_cluster(cluster_name, cluster_size) sys.stdout.write('Response: \n%s\n' % json.dumps(res, indent=2)) except Exception as e: sys.stdout.write(str(e)) exit(1)