text
stringlengths 0
828
|
---|
max_rank = rank
|
return matching_corpus_index"
|
274,"def process_corpus(self):
|
""""""Q.process_corpus() -- processes the queries defined by us,
|
by tokenizing, stemming, and removing stop words.
|
""""""
|
for doc in self.corpus_list:
|
doc = wt(doc)
|
sentence = []
|
for word in doc:
|
if word not in self.stop_words and word not in self.punctuation:
|
word = self.stemmer.stem(word)
|
sentence.append(word)
|
self.processed_corpus.append(sentence)"
|
275,"def process_query(self):
|
""""""Q.process_query() -- processes the user query,
|
by tokenizing and stemming words.
|
""""""
|
self.query = wt(self.query)
|
self.processed_query = []
|
for word in self.query:
|
if word not in self.stop_words and word not in self.punctuation:
|
self.processed_query.append(self.stemmer.stem(word))"
|
276,"def query(self, query):
|
""""""Q.query(query string) -> category string -- return the matched
|
category for any user query
|
""""""
|
self.query = query
|
self.process_query()
|
matching_corpus_index = self.match_query_to_corpus()
|
return self.category_list[matching_corpus_index].strip()"
|
277,"def load_manifest(raw_manifest, namespace=None, **kwargs):
|
"""""" wrapper method which generates the manifest from various sources """"""
|
if isinstance(raw_manifest, configparser.RawConfigParser):
|
return Manifest(raw_manifest)
|
manifest = create_configparser()
|
if not manifest.has_section('config'):
|
manifest.add_section('config')
|
_load_manifest_interpret_source(manifest,
|
raw_manifest,
|
**kwargs)
|
return Manifest(manifest, namespace=namespace)"
|
278,"def _load_manifest_interpret_source(manifest, source, username=None, password=None, verify_certificate=True, do_inherit=True):
|
"""""" Interpret the <source>, and load the results into <manifest> """"""
|
try:
|
if isinstance(source, string_types):
|
if source.startswith(""http""):
|
# if manifest is a url
|
_load_manifest_from_url(manifest, source,
|
verify_certificate=verify_certificate,
|
username=username, password=password)
|
else:
|
_load_manifest_from_file(manifest, source)
|
if not manifest.has_option('config', 'source'):
|
manifest.set('config', 'source', str(source))
|
else:
|
# assume source is a file pointer
|
manifest.readfp(source)
|
if manifest.has_option('config', 'extends') and do_inherit:
|
parent_manifest = configparser.RawConfigParser()
|
_load_manifest_interpret_source(parent_manifest,
|
manifest.get('config', 'extends'),
|
username=username,
|
password=password,
|
verify_certificate=verify_certificate)
|
for s in parent_manifest.sections():
|
for k, v in parent_manifest.items(s):
|
if not manifest.has_option(s, k):
|
manifest.set(s, k, v)
|
except configparser.Error:
|
logger.debug("""", exc_info=True)
|
error_message = sys.exc_info()[1]
|
raise ManifestException(""Unable to parse manifest!: {0}"".format(error_message))"
|
279,"def _load_manifest_from_url(manifest, url, verify_certificate=True, username=None, password=None):
|
"""""" load a url body into a manifest """"""
|
try:
|
if username and password:
|
manifest_file_handler = StringIO(lib.authenticated_get(username, password, url,
|
verify=verify_certificate).decode(""utf-8""))
|
else:
|
manifest_file_handler = StringIO(lib.cleaned_request(
|
'get', url, verify=verify_certificate
|
).text)
|
manifest.readfp(manifest_file_handler)
|
except requests.exceptions.RequestException:
|
logger.debug("""", exc_info=True)
|
error_message = sys.exc_info()[1]
|
raise ManifestException(""There was an error retrieving {0}!\n {1}"".format(url, str(error_message)))"
|
280,"def _load_manifest_from_file(manifest, path):
|
"""""" load manifest from file """"""
|
path = os.path.abspath(os.path.expanduser(path))
|
if not os.path.exists(path):
|
raise ManifestException(""Manifest does not exist at {0}!"".format(path))
|
manifest.read(path)
|
if not manifest.has_option('config', 'source'):
|
manifest.set('config', 'source', str(path))"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.