output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
Removes results rows for which the n - gram is not present in at least one text in each labelled set of texts.
Make a summary of the following Python 3 code def reciprocal_remove(self): self._logger.info( 'Removing n-grams that are not attested in all labels') self._matches = self._reciprocal_remove(self._matches)
As a python code expert, you are capable of creating scripts from specifications.
def reduce(self): """Removes results rows whose n-grams are contained in larger n-grams.""" self._logger.info('Reducing the n-grams') # This does not make use of any pandas functionality; it # probably could, and if so ought to. data = {} labels = {} # Der...
Can you create a Python 3 function that removes rows whose n - grams are contained in larger n - grams.
You are a Python code architect, reviewing and designing scalable and efficient code
def _reduce_by_ngram(self, data, ngram): """Lowers the counts of all n-grams in `data` that are substrings of `ngram` by `ngram`\'s count. Modifies `data` in place. :param data: row data dictionary for the current text :type data: `dict` :param ngram: n-gram being reduc...
Implement a Python 3 function for reducing the counts of all n - grams in data by the count of n - grams of ngram.
You are a Python code architect, reviewing and designing scalable and efficient code
Relabels results rows according to catalogue.
Given the following Python 3 function, write the documentation def relabel(self, catalogue): for work, label in catalogue.items(): self._matches.loc[self._matches[constants.WORK_FIELDNAME] == work, constants.LABEL_FIELDNAME] = label
You are a Python code analyst, evaluating scripts for potential improvements.
Removes all results rows associated with label.
Here you have a function in Python 3, explain what it does def remove_label(self, label): self._logger.info('Removing label "{}"'.format(label)) count = self._matches[constants.LABEL_FIELDNAME].value_counts().get( label, 0) self._matches = self._matches[ self._matches[con...
As a Python code composer, you craft elegant and concise scripts.
Sorts all results rows.
Explain what the following Python 3 code does def sort(self): self._matches.sort_values( by=[constants.SIZE_FIELDNAME, constants.NGRAM_FIELDNAME, constants.COUNT_FIELDNAME, constants.LABEL_FIELDNAME, constants.WORK_FIELDNAME, constants.SIGLUM_FIELDNAME], a...
You are a Python code generator, capable of creating scripts from specifications.
def zero_fill(self, corpus): """Adds rows to the results to ensure that, for every n-gram that is attested in at least one witness, every witness for that text has a row, with added rows having a count of zero. :param corpus: corpus containing the texts appearing in the results ...
Write a Python 3 function for adding rows to the results to ensure that every n - gram that is attested in at least one witness for that text is not present in at least one witness for that text.
As a Python code analyst, you investigate and solve complex coding mysteries
Setup logging output defaults
Can you generate the documentation for the following Python 3 function def get_logger(): # Grab the logger if not hasattr(get_logger, 'logger'): # Setup the default logging config get_logger.logger = logging.getLogger('chains') format_str = '%(asctime)s [%(levelname)s] - %(module)s: %(...
As a python code expert, you are capable of creating scripts from specifications.
def read_interface(self): """Read Packets from the packet capture interface""" # Spin up the packet capture if self._iface_is_file(): self.pcap = pcapy.open_offline(self.iface_name) else: try: # self.pcap = pcap.pcap(name=self.iface_name, promisc=...
Write a Python 3 function for reading Packets from the packet capture interface.
You are a Python code analyst, evaluating scripts for potential improvements.
Generates a parser configured with sub - commands and arguments.
How would you explain what the following Python 3 function does def generate_parser(): parser = argparse.ArgumentParser( description=constants.TACL_DESCRIPTION, formatter_class=ParagraphFormatter) subparsers = parser.add_subparsers(title='subcommands') generate_align_subparser(subparsers) ...
You are a Python code architect, reviewing and designing scalable and efficient code
Adds a sub - command parser to subparsers to generate aligned sequences from a set of results.
Given the following Python 3 function, write the documentation def generate_align_subparser(subparsers): parser = subparsers.add_parser( 'align', description=constants.ALIGN_DESCRIPTION, epilog=constants.ALIGN_EPILOG, formatter_class=ParagraphFormatter, help=constants.ALIGN_HELP) parser....
As a Python code translator, you convert algorithms and pseudocode into Python.
Generates and saves a catalogue file.
Can you generate a brief explanation for the following Python 3 code def generate_catalogue(args, parser): catalogue = tacl.Catalogue() catalogue.generate(args.corpus, args.label) catalogue.save(args.catalogue)
You are a Python code architect, reviewing and designing scalable and efficient code
def generate_catalogue_subparser(subparsers): """Adds a sub-command parser to `subparsers` to generate and save a catalogue file.""" parser = subparsers.add_parser( 'catalogue', description=constants.CATALOGUE_DESCRIPTION, epilog=constants.CATALOGUE_EPILOG, formatter_class=ParagraphF...
Create a Python 3 function to add a sub - command parser to subparsers to generate and save a catalogue file.
As a Python code translator, you convert algorithms and pseudocode into Python.
def generate_counts_subparser(subparsers): """Adds a sub-command parser to `subparsers` to make a counts query.""" parser = subparsers.add_parser( 'counts', description=constants.COUNTS_DESCRIPTION, epilog=constants.COUNTS_EPILOG, formatter_class=ParagraphFormatter, help=constants.CO...
Create a Python 3 function for adding a sub - command parser to subparsers to make a counts query.
You are a Python code architect, reviewing and designing scalable and efficient code
Adds a sub - command parser to subparsers to make a diff query.
Here you have a function in Python 3, explain what it does def generate_diff_subparser(subparsers): parser = subparsers.add_parser( 'diff', description=constants.DIFF_DESCRIPTION, epilog=constants.DIFF_EPILOG, formatter_class=ParagraphFormatter, help=constants.DIFF_HELP) parser.set_defau...
You are a Python code analyst, evaluating scripts for potential improvements.
def generate_excise_subparser(subparsers): """Adds a sub-command parser to `subparsers` to excise n-grams from witnesses.""" parser = subparsers.add_parser( 'excise', description=constants.EXCISE_DESCRIPTION, help=constants.EXCISE_HELP) parser.set_defaults(func=excise) utils.add_comm...
Write a Python 3 function for adding a sub - command parser to subparsers to excise n - grams from witnesses.
As a Python code analyst, you investigate and solve complex coding mysteries
Adds a sub - command parser to subparsers to highlight a witness' text with its matches in a result.
Can you generate a brief explanation for the following Python 3 code def generate_highlight_subparser(subparsers): parser = subparsers.add_parser( 'highlight', description=constants.HIGHLIGHT_DESCRIPTION, epilog=constants.HIGHLIGHT_EPILOG, formatter_class=ParagraphFormatter, help=constants.H...
As a python code expert, you are capable of creating scripts from specifications.
def generate_intersect_subparser(subparsers): """Adds a sub-command parser to `subparsers` to make an intersection query.""" parser = subparsers.add_parser( 'intersect', description=constants.INTERSECT_DESCRIPTION, epilog=constants.INTERSECT_EPILOG, formatter_class=ParagraphFormatter, ...
Can you write a function in Python 3 where it adds a sub - command parser to subparsers to make an intersection query.
You are a Python code architect, reviewing and designing scalable and efficient code
Adds a sub - command parser to subparsers to make a lifetime report.
Can you generate the documentation for the following Python 3 function def generate_lifetime_subparser(subparsers): parser = subparsers.add_parser( 'lifetime', description=constants.LIFETIME_DESCRIPTION, epilog=constants.LIFETIME_EPILOG, formatter_class=ParagraphFormatter, help=constants.LIF...
As a python code expert, you are capable of creating scripts from specifications.
def generate_ngrams(args, parser): """Adds n-grams data to the data store.""" store = utils.get_data_store(args) corpus = utils.get_corpus(args) if args.catalogue: catalogue = utils.get_catalogue(args) else: catalogue = None store.add_ngrams(corpus, args.min_size, args.max_size, ...
Create a Python 3 function to add n - grams data to the data store.
As a Python code translator, you convert algorithms and pseudocode into Python.
def generate_ngrams_subparser(subparsers): """Adds a sub-command parser to `subparsers` to add n-grams data to the data store.""" parser = subparsers.add_parser( 'ngrams', description=constants.NGRAMS_DESCRIPTION, epilog=constants.NGRAMS_EPILOG, formatter_class=ParagraphFormatter, he...
Create a Python 3 function to add a sub - command parser to subparsers to add n - grams data to the data store.
You are a Python code generator, capable of creating scripts from specifications.
def generate_prepare_subparser(subparsers): """Adds a sub-command parser to `subparsers` to prepare source XML files for stripping.""" parser = subparsers.add_parser( 'prepare', description=constants.PREPARE_DESCRIPTION, epilog=constants.PREPARE_EPILOG, formatter_class=ParagraphFormatter, ...
How would you implement a function in Python 3 that adds a sub - command parser to subparsers to prepare source XML files for stripping.
You are a Python code generator, capable of creating scripts from specifications.
def generate_results_subparser(subparsers): """Adds a sub-command parser to `subparsers` to manipulate CSV results data.""" parser = subparsers.add_parser( 'results', description=constants.RESULTS_DESCRIPTION, epilog=constants.RESULTS_EPILOG, formatter_class=ParagraphFormatter, help=...
Can you write a function in Python 3 where it adds a sub - command parser to manipulate CSV results data.
As a python code expert, you are capable of creating scripts from specifications.
Adds a sub - command parser to subparsers to generate search results for a set of n - grams.
Can you tell what is the following Python 3 function doing def generate_search_subparser(subparsers): parser = subparsers.add_parser( 'search', description=constants.SEARCH_DESCRIPTION, epilog=constants.SEARCH_EPILOG, formatter_class=ParagraphFormatter, help=constants.SEARCH_HELP) parser...
As a Python code translator, you convert algorithms and pseudocode into Python.
def generate_statistics_subparser(subparsers): """Adds a sub-command parser to `subparsers` to generate statistics from a set of results.""" parser = subparsers.add_parser( 'stats', description=constants.STATISTICS_DESCRIPTION, formatter_class=ParagraphFormatter, help=constants.STATISTICS_HE...
Can you write a function in Python 3 where it adds a sub - command parser to subparsers to generate statistics from a set of results.
As a Python code translator, you convert algorithms and pseudocode into Python.
def generate_strip_subparser(subparsers): """Adds a sub-command parser to `subparsers` to process prepared files for use with the tacl ngrams command.""" parser = subparsers.add_parser( 'strip', description=constants.STRIP_DESCRIPTION, epilog=constants.STRIP_EPILOG, formatter_class=Paragraph...
How would you code a function in Python 3 to add a sub - command parser to subparsers to process prepared files for use with the tacl ngrams command.
As a Python code analyst, you investigate and solve complex coding mysteries
Adds a sub - command parser to subparsers to run a diff query using the supplied results sets.
Can you tell what is the following Python 3 function doing def generate_supplied_diff_subparser(subparsers): parser = subparsers.add_parser( 'sdiff', description=constants.SUPPLIED_DIFF_DESCRIPTION, epilog=constants.SUPPLIED_DIFF_EPILOG, formatter_class=ParagraphFormatter, help=constants.SUP...
As a Python code composer, you craft elegant and concise scripts.
Adds a sub - command parser to subparsers to run an intersect query on the supplied results sets.
Can you generate a brief explanation for the following Python 3 code def generate_supplied_intersect_subparser(subparsers): parser = subparsers.add_parser( 'sintersect', description=constants.SUPPLIED_INTERSECT_DESCRIPTION, epilog=constants.SUPPLIED_INTERSECT_EPILOG, formatter_class=Paragrap...
As a Python code composer, you craft elegant and concise scripts.
Outputs the result of highlighting a text.
Can you generate the documentation for the following Python 3 function def highlight_text(args, parser): tokenizer = utils.get_tokenizer(args) corpus = utils.get_corpus(args) output_dir = os.path.abspath(args.output) if os.path.exists(output_dir): parser.exit(status=3, message='Output directory ...
As a Python code composer, you craft elegant and concise scripts.
Generates a lifetime report.
Make a summary of the following Python 3 code def lifetime_report(args, parser): catalogue = utils.get_catalogue(args) tokenizer = utils.get_tokenizer(args) results = tacl.Results(args.results, tokenizer) output_dir = os.path.abspath(args.output) os.makedirs(output_dir, exist_ok=True) report = t...
As a Python code translator, you convert algorithms and pseudocode into Python.
Outputs the results of performing a counts query.
Can you generate the documentation for the following Python 3 function def ngram_counts(args, parser): store = utils.get_data_store(args) corpus = utils.get_corpus(args) catalogue = utils.get_catalogue(args) store.validate(corpus, catalogue) store.counts(catalogue, sys.stdout)
As a Python code analyst, you investigate and solve complex coding mysteries
def ngram_diff(args, parser): """Outputs the results of performing a diff query.""" store = utils.get_data_store(args) corpus = utils.get_corpus(args) catalogue = utils.get_catalogue(args) tokenizer = utils.get_tokenizer(args) store.validate(corpus, catalogue) if args.asymmetric: sto...
Implement a Python 3 function for outputting the results of performing a diff query.
You are a Python code architect, reviewing and designing scalable and efficient code
Outputs the results of performing an intersection query.
Make a summary of the following Python 3 code def ngram_intersection(args, parser): store = utils.get_data_store(args) corpus = utils.get_corpus(args) catalogue = utils.get_catalogue(args) store.validate(corpus, catalogue) store.intersection(catalogue, sys.stdout)
As a Python code composer, you craft elegant and concise scripts.
Prepares XML files for stripping.
Can you generate a brief explanation for the following Python 3 code def prepare_xml(args, parser): if args.source == constants.TEI_SOURCE_CBETA_GITHUB: corpus_class = tacl.TEICorpusCBETAGitHub else: raise Exception('Unsupported TEI source option provided') corpus = corpus_class(args.input, ...
You are a Python code generator, capable of creating scripts from specifications.
def search_texts(args, parser): """Searches texts for presence of n-grams.""" store = utils.get_data_store(args) corpus = utils.get_corpus(args) catalogue = utils.get_catalogue(args) store.validate(corpus, catalogue) ngrams = [] for ngram_file in args.ngrams: ngrams.extend(utils.get_...
Create a Python 3 function for searching texts for presence of n - grams.
As a Python code translator, you convert algorithms and pseudocode into Python.
def strip_files(args, parser): """Processes prepared XML files for use with the tacl ngrams command.""" stripper = tacl.Stripper(args.input, args.output) stripper.strip_files()
Implement a function in Python 3 to process prepared XML files for use with the tacl ngrams command.
You are a Python code architect, reviewing and designing scalable and efficient code
Pull out the application metadata for each flow in the input_stream and yield the flow data as a generator of the flow data.
How would you explain what the following Python 3 function does def http_meta_data(self): # For each flow process the contents for flow in self.input_stream: # Client to Server if flow['direction'] == 'CTS': try: request = dpkt.http.Request(f...
As a python code expert, you are capable of creating scripts from specifications.
Yields the metadata for each packet in the input_stream
Here you have a function in Python 3, explain what it does def transport_meta_data(self): # For each packet in the pcap process the contents for item in self.input_stream: # Get the transport data and type trans_data = item['packet']['data'] trans_type = self._get_t...
You are a Python code generator, capable of creating scripts from specifications.
Generates and writes a CSV file in output_dir the data used to get the breakdown chart.
Can you tell what is the following Python 3 function doing def _create_breakdown_chart(self, data, work, output_dir): chart_data = data.loc[work].sort_values(by=SHARED, ascending=False)[ [SHARED, UNIQUE, COMMON]] csv_path = os.path.join(output_dir, 'breakdown_{}.csv'.format( work...
As a Python code composer, you craft elegant and concise scripts.
Generates and writes a file in output_dir the data used to display a chord chart.
Explain what the following Python 3 code does def _create_chord_chart(self, data, works, output_dir): matrix = [] chord_data = data.unstack(BASE_WORK)[SHARED] for index, row_data in chord_data.fillna(value=0).iterrows(): matrix.append([value / 100 for value in row_data]) colo...
You are a Python code analyst, evaluating scripts for potential improvements.
def _create_matrix_chart(self, data, works, output_dir): """Generates and writes to a file in `output_dir` the data used to display a matrix chart. :param data: data to derive the matrix data from :type data: `pandas.DataFrame` :param works: works to display :type works:...
How would you code a function in Python 3 to generate and writes a JSON file that contains the data used to display a matrix chart.
As a python code expert, you are capable of creating scripts from specifications.
Generates and writes a CSV file in output_dir the data used to be shown for each maybe work that is shared with the maybe work.
Here you have a function in Python 3, explain what it does def _create_related_chart(self, data, work, output_dir): chart_data = data[work].dropna().sort_values(by=SHARED_RELATED_WORK, ascending=False) csv_path = os.path.join(output_dir, 'related_{}.c...
You are a Python code architect, reviewing and designing scalable and efficient code
def _drop_no_label_results(self, results, fh): """Writes `results` to `fh` minus those results associated with the 'no' label. :param results: results to be manipulated :type results: file-like object :param fh: output destination :type fh: file-like object """ ...
Implement a Python 3 function for writing the results to fh minus those results associated with the no label.
You are a Python code architect, reviewing and designing scalable and efficient code
def _generate_statistics(self, out_path, results_path): """Writes a statistics report for the results at `results_path` to `out_path`. Reuses an existing statistics report if one exists at `out_path`. :param out_path: path to output statistics report to :type out_path: ...
How would you code a function in Python 3 to write a statistics report for the results at results_path to out_path.
As a Python code analyst, you investigate and solve complex coding mysteries
def _process_diff(self, yes_work, maybe_work, work_dir, ym_results_path, yn_results_path, stats): """Returns statistics on the difference between the intersection of `yes_work` and `maybe_work` and the intersection of `yes_work` and "no" works. :param yes_work: nam...
Implement a Python 3 function for processing the diff between two sets of yes_work and maybe_work and returns the statistics on the difference between the intersection of yes_work and maybe_work and the intersection of ym_results_path and yn_results_path.
You are a Python code analyst, evaluating scripts for potential improvements.
def _process_intersection(self, yes_work, maybe_work, work_dir, ym_results_path, stats): """Returns statistics on the intersection between `yes_work` and `maybe_work`. :param yes_work: name of work for which stats are collected :type yes_work: `str` ...
How would you code a function in Python 3 to return statistics on the intersection between yes_work and maybe_work.
You are a Python code architect, reviewing and designing scalable and efficient code
Processes the maybe_work and maybe_work and returns statistics of how the yes_work compares with maybe_work.
How would you explain what the following Python 3 function does def _process_maybe_work(self, yes_work, maybe_work, work_dir, yn_results_path, stats): """Returns statistics of how `yes_work` compares with `maybe_work`. :param yes_work: name of work for which stats are collec...
You are a Python code analyst, evaluating scripts for potential improvements.
def _process_works(self, maybe_works, no_works, output_dir): """Collect and return the data of how each work in `maybe_works` relates to each other work. :param maybe_works: :type maybe_works: `list` of `str` :param no_works: :type no_works: `list` of `str` :para...
Write a Python 3 function for collecting and return the data of how each work in maybe_works relates to each other work.
You are a Python code analyst, evaluating scripts for potential improvements.
def _process_yes_work(self, yes_work, no_catalogue, maybe_works, output_dir): """Returns statistics of how `yes_work` compares with the other works in `no_catalogue` and the "maybe" works. :param yes_work: name of work being processed :type yes_work: `str` ...
Write a Python 3 script for processing a yes_work and maybe_work and returns a dictionary of how the yes_work compares with the other works in no_catalogue and the maybe_works.
As a python code expert, you are capable of creating scripts from specifications.
def _run_query(self, path, query, query_args, drop_no=True): """Runs `query` and outputs results to a file at `path`. If `path` exists, the query is not run. :param path: path to output results to :type path: `str` :param query: query to run :type query: `method` ...
Write a Python 3 script for running a query and outputs results to a file at path.
As a python code expert, you are capable of creating scripts from specifications.
def _add_indices(self): """Adds the database indices relating to n-grams.""" self._logger.info('Adding database indices') self._conn.execute(constants.CREATE_INDEX_TEXTNGRAM_SQL) self._logger.info('Indices added')
Implement a Python 3 function for adding the indices relating to n - grams.
You are a Python code analyst, evaluating scripts for potential improvements.
def add_ngrams(self, corpus, minimum, maximum, catalogue=None): """Adds n-gram data from `corpus` to the data store. :param corpus: corpus of works :type corpus: `Corpus` :param minimum: minimum n-gram size :type minimum: `int` :param maximum: maximum n-gram size ...
Can you implement a function in Python 3 that adds n - gram data from a corpus to the data store.
As a Python code translator, you convert algorithms and pseudocode into Python.
Adds n - grams to a temporary table.
How would you explain what the following Python 3 function does def _add_temporary_ngrams(self, ngrams): # Remove duplicate n-grams, empty n-grams, and non-string n-grams. ngrams = [ngram for ngram in ngrams if ngram and isinstance(ngram, str)] # Deduplicate while preserving or...
As a python code expert, you are capable of creating scripts from specifications.
Adds the results to a temporary table with label.
Make a summary of the following Python 3 code def _add_temporary_results(self, results, label): NGRAM, SIZE, NAME, SIGLUM, COUNT, LABEL = constants.QUERY_FIELDNAMES reader = csv.DictReader(results) data = [(row[NGRAM], row[SIZE], row[NAME], row[SIGLUM], row[COUNT], label) for ro...
As a Python code analyst, you investigate and solve complex coding mysteries
Adds n - gram data from witness to the data store.
Explain what the following Python 3 code does def _add_text_ngrams(self, witness, minimum, maximum): text_id = self._get_text_id(witness) self._logger.info('Adding n-grams ({} <= n <= {}) for {}'.format( minimum, maximum, witness.get_filename())) skip_sizes = [] for size in r...
You are a Python code architect, reviewing and designing scalable and efficient code
Adds a Text record for witness.
Given the following Python 3 function, write the documentation def _add_text_record(self, witness): filename = witness.get_filename() name, siglum = witness.get_names() self._logger.info('Adding record for text {}'.format(filename)) checksum = witness.get_checksum() token_count =...
You are a Python code generator, capable of creating scripts from specifications.
def _add_text_size_ngrams(self, text_id, size, ngrams): """Adds `ngrams`, that are of size `size`, to the data store. The added `ngrams` are associated with `text_id`. :param text_id: database ID of text associated with `ngrams` :type text_id: `int` :param size: size of n-grams...
Write a Python 3 function that can add n - grams that are of size to the data store.
As a Python code analyst, you investigate and solve complex coding mysteries
def _analyse(self, table=''): """Analyses the database, or `table` if it is supplied. :param table: optional name of table to analyse :type table: `str` """ self._logger.info('Starting analysis of database') self._conn.execute(constants.ANALYSE_SQL.format(table)) ...
Write a Python 3 function for analysing the database or table.
You are a Python code analyst, evaluating scripts for potential improvements.
Checks the n - grams in a result row and updates the count of the n - grams that compose it.
Can you tell what is the following Python 3 function doing def _check_diff_result(row, matches, tokenize, join): ngram_tokens = tokenize(row[constants.NGRAM_FIELDNAME]) sub_ngram1 = join(ngram_tokens[:-1]) sub_ngram2 = join(ngram_tokens[1:]) count = constants.COUNT_FIELDNAME disc...
As a Python code analyst, you investigate and solve complex coding mysteries
def counts(self, catalogue, output_fh): """Returns `output_fh` populated with CSV results giving n-gram counts of the witnesses of the works in `catalogue`. :param catalogue: catalogue matching filenames to labels :type catalogue: `Catalogue` :param output_fh: object to output r...
Write a Python 3 script for returning output_fh populated with CSV results giving n - gram counts of the witnesses of the works in catalogue.
You are a Python code analyst, evaluating scripts for potential improvements.
Writes the rows of cursor in CSV format to output_fh and returns it.
How would you explain what the following Python 3 function does def _csv(self, cursor, fieldnames, output_fh): self._logger.info('Finished query; outputting results in CSV format') # Specify a lineterminator to avoid an extra \r being added on # Windows; see # https://stackoverflow.com/q...
You are a Python code generator, capable of creating scripts from specifications.
def _csv_temp(self, cursor, fieldnames): """Writes the rows of `cursor` in CSV format to a temporary file and returns the path to that file. :param cursor: database cursor containing data to be output :type cursor: `sqlite3.Cursor` :param fieldnames: row headings :type f...
Implement a Python 3 function for writing the rows of cursor in CSV format and returns the path to that file.
You are a Python code architect, reviewing and designing scalable and efficient code
Deletes all n - grams associated with text_id from the data store.
Here you have a function in Python 3, explain what it does def _delete_text_ngrams(self, text_id): with self._conn: self._conn.execute(constants.DELETE_TEXT_NGRAMS_SQL, [text_id]) self._conn.execute(constants.DELETE_TEXT_HAS_NGRAMS_SQL, [text_id])
As a Python code composer, you craft elegant and concise scripts.
Returns output_fh with diff results that have been reduced.
Make a summary of the following Python 3 code def _diff(self, cursor, tokenizer, output_fh): temp_path = self._csv_temp(cursor, constants.QUERY_FIELDNAMES) output_fh = self._reduce_diff_results(temp_path, tokenizer, output_fh) try: os.remove(temp_path) except OSError as e: ...
As a Python code analyst, you investigate and solve complex coding mysteries
Returns output_fh populated with CSV results giving the n - grams that are unique to each set of works in catalogue.
Can you tell what is the following Python 3 function doing def diff(self, catalogue, tokenizer, output_fh): labels = self._sort_labels(self._set_labels(catalogue)) if len(labels) < 2: raise MalformedQueryError( constants.INSUFFICIENT_LABELS_QUERY_ERROR) label_placehol...
You are a Python code generator, capable of creating scripts from specifications.
def diff_asymmetric(self, catalogue, prime_label, tokenizer, output_fh): """Returns `output_fh` populated with CSV results giving the difference in n-grams between the witnesses of labelled sets of works in `catalogue`, limited to those works labelled with `prime_label`. :param ...
Can you create a Python 3 function that returns an output_fh populated with CSV results giving the difference in n - grams between the witnesses of labelled sets of works in catalogue with prime_label.
As a Python code analyst, you investigate and solve complex coding mysteries
Returns output_fh populated with CSV results giving the n - grams that are unique to each set of works in results_sets and the n - grams that are unique to each set of works in results_sets.
Can you tell what is the following Python 3 function doing def diff_supplied(self, results_filenames, labels, tokenizer, output_fh): self._add_temporary_results_sets(results_filenames, labels) query = constants.SELECT_DIFF_SUPPLIED_SQL self._logger.info('Running supplied diff query') sel...
As a Python code composer, you craft elegant and concise scripts.
Drops the database indices relating to n - grams.
Make a summary of the following Python 3 code def _drop_indices(self): self._logger.info('Dropping database indices') self._conn.execute(constants.DROP_TEXTNGRAM_INDEX_SQL) self._logger.info('Finished dropping database indices')
You are a Python code generator, capable of creating scripts from specifications.
def _get_text_id(self, witness): """Returns the database ID of the Text record for `witness`. This may require creating such a record. If `text`\'s checksum does not match an existing record's checksum, the record's checksum is updated and all associated TextNGram and TextHasNG...
Write a Python 3 function that can return the database ID of the Text record for witness.
As a Python code composer, you craft elegant and concise scripts.
Returns True if a text has existing records for n - grams of size size.
How would you explain what the following Python 3 function does def _has_ngrams(self, text_id, size): if self._conn.execute(constants.SELECT_HAS_NGRAMS_SQL, [text_id, size]).fetchone() is None: return False return True
You are a Python code analyst, evaluating scripts for potential improvements.
Creates the database schema.
Given the following Python 3 function, write the documentation def _initialise_database(self): self._logger.info('Creating database schema, if necessary') self._conn.execute(constants.CREATE_TABLE_TEXT_SQL) self._conn.execute(constants.CREATE_TABLE_TEXTNGRAM_SQL) self._conn.execute(const...
As a Python code analyst, you investigate and solve complex coding mysteries
Returns output_fh populated with CSV results giving the intersection in n - grams of the witnesses of labelled sets of works in catalogue.
Given the following Python 3 function, write the documentation def intersection(self, catalogue, output_fh): labels = self._sort_labels(self._set_labels(catalogue)) if len(labels) < 2: raise MalformedQueryError( constants.INSUFFICIENT_LABELS_QUERY_ERROR) label_placeho...
As a python code expert, you are capable of creating scripts from specifications.
def intersection_supplied(self, results_filenames, labels, output_fh): """Returns `output_fh` populated with CSV results giving the n-grams that are common to witnesses in every set of works in `results_sets`, using the labels in `labels`. :param results_filenames: list of results to be...
Write a Python 3 function for returning output_fh populated with CSV results giving the n - grams that are common to witnesses in every set of works in results_sets with the labels in labels.
You are a Python code analyst, evaluating scripts for potential improvements.
def _reduce_diff_results(self, matches_path, tokenizer, output_fh): """Returns `output_fh` populated with a reduced set of data from `matches_fh`. Diff results typically contain a lot of filler results that serve only to hide real differences. If one text has a single extra toke...
Create a Python 3 function for reducing the diff results from one set of n - grams to another.
You are a Python code analyst, evaluating scripts for potential improvements.
def search(self, catalogue, ngrams, output_fh): """Returns `output_fh` populated with CSV results for each n-gram in `ngrams` that occurs within labelled witnesses in `catalogue`. If `ngrams` is empty, include all n-grams. :param catalogue: catalogue matching filenames to labels ...
Write a Python 3 script for returning output_fh populated with CSV results for each n - gram inn - gram inn - gram in catalogue that occurs within labelled witnesses in catalogue.
As a Python code analyst, you investigate and solve complex coding mysteries
def _set_labels(self, catalogue): """Returns a dictionary of the unique labels in `catalogue` and the count of all tokens associated with each, and sets the record of each Text to its corresponding label. Texts that do not have a label specified are set to the empty string. ...
How would you code a function in Python 3 to return a dictionary of the unique labels in catalogue and the count of all tokens associated with each Text.
As a python code expert, you are capable of creating scripts from specifications.
Returns the labels in label_data sorted in descending order according to the size of their token counts.
Can you generate the documentation for the following Python 3 function def _sort_labels(label_data): labels = list(label_data) labels.sort(key=label_data.get, reverse=True) return labels
As a Python code analyst, you investigate and solve complex coding mysteries
def _update_text_record(self, witness, text_id): """Updates the record with `text_id` with `witness`\'s checksum and token count. :param withness: witness to update from :type witness: `WitnessText` :param text_id: database ID of Text record :type text_id: `int` ...
Can you implement a function in Python 3 that updates the record with the given text_id with the given witness.
You are a Python code analyst, evaluating scripts for potential improvements.
Returns True if all of the files labelled in catalogue are up - to - date in the database.
Make a summary of the following Python 3 code def validate(self, corpus, catalogue): is_valid = True for name in catalogue: count = 0 # It is unfortunate that this creates WitnessText objects # for each work, since that involves reading the file. for witne...
You are a Python code generator, capable of creating scripts from specifications.
def _format_alignment(self, a1, a2): """Returns `a1` marked up with HTML spans around characters that are also at the same index in `a2`. :param a1: text sequence from one witness :type a1: `str` :param a2: text sequence from another witness :type a2: `str` :rtyp...
Implement a Python 3 function for formatting the alignment a1 with HTML spans around characters that are also at the same index in a2.
As a Python code analyst, you investigate and solve complex coding mysteries
def render(self): """Returns a tuple of HTML fragments rendering each element of the sequence.""" f1 = self._format_alignment(self._alignment[0], self._alignment[1]) f2 = self._format_alignment(self._alignment[1], self._alignment[0]) return f1, f2
How would you implement a function in Python 3 that returns a tuple of HTML fragments rendering each element of the sequence.
You are a Python code analyst, evaluating scripts for potential improvements.
def generate(self, output_dir, minimum_size): """Generates sequence reports and writes them to the output directory. :param output_dir: directory to output reports to :type output_dir: `str` :param minimum_size: minimum size of n-grams to create sequences for :type minimum_size:...
Write a Python 3 script for generating sequences for the n - grams in the n - grams of the n - grams in the n - grams of the n - grams in the n - grams of the n - grams in the n - grams of the n - grams in the n - grams of the n - grams in the n - grams of the n - grams in the n - grams of the n - grams in the n - gram...
You are a Python code architect, reviewing and designing scalable and efficient code
Returns an aligned sequence between extract t1_span and extract t2_span of witness text t1 and extract t2_span of witness text t2.
Can you generate the documentation for the following Python 3 function def _generate_sequence(self, t1, t1_span, t2, t2_span, context_length, covered_spans): """Returns an aligned sequence (or None) between extract `t1_span` of witness text `t1` and extract `t2_span` of witnes...
You are a Python code generator, capable of creating scripts from specifications.
def _generate_sequences(self, primary_label, secondary_label, ngrams): """Generates aligned sequences between each witness labelled `primary_label` and each witness labelled `secondary_label`, based around `ngrams`. :param primary_label: label for one side of the pairs of ...
Implement a Python 3 function for generating aligned sequences between each witness labelled primary_label and each witness labelled secondary_label based around ngrams.
You are a Python code architect, reviewing and designing scalable and efficient code
def _generate_sequences_for_ngram(self, t1, t2, ngram, covered_spans): """Generates aligned sequences for the texts `t1` and `t2`, based around `ngram`. Does not generate sequences that occur within `covered_spans`. :param t1: text content of first witness :type t1: `str` ...
Write a Python 3 function that can generate aligned sequences for the texts t1 and t2 based on the n - gram ngram.
You are a Python code architect, reviewing and designing scalable and efficient code
def _generate_sequences_for_texts(self, l1, t1, l2, t2, ngrams): """Generates and outputs aligned sequences for the texts `t1` and `t2` from `ngrams`. :param l1: label of first witness :type l1: `str` :param t1: text content of first witness :type t1: `str` :para...
Create a Python 3 function to generate and outputs aligned sequences for the texts t1 and t2 from ngrams.
As a Python code composer, you craft elegant and concise scripts.
Returns the text content of text with all multi - character tokens replaced with a single character. Substitutions are recorded xid in self. _substitutes.
Make a summary of the following Python 3 code def _get_text(self, text): tokens = text.get_tokens() for i, token in enumerate(tokens): if len(token) > 1: char = chr(self._char_code) substitute = self._substitutes.setdefault(token, char) if subs...
You are a Python code analyst, evaluating scripts for potential improvements.
def _get_text_sequence(self, text, span, context_length): """Returns the subset of `text` encompassed by `span`, plus `context_length` characters before and after. :param text: text to extract the sequence from :type text: `str` :param span: start and end indices within `text` ...
Implement a Python 3 function for returning the text encompassed by span plus context_length characters before and after the text.
You are a Python code generator, capable of creating scripts from specifications.
def _is_inside(self, span1, span2, covered_spans): """Returns True if both `span1` and `span2` fall within `covered_spans`. :param span1: start and end indices of a span :type span1: 2-`tuple` of `int` :param span2: start and end indices of a span :type span2: 2-`tuple` ...
Write a Python 3 script to return True if both span1 and span2 fall within covered_spans.
You are a Python code generator, capable of creating scripts from specifications.
Returns True if span falls within covered_spans.
Here you have a function in Python 3, explain what it does def _is_span_inside(self, span, covered_spans): start = span[0] end = span[1] for c_start, c_end in covered_spans: if start >= c_start and end <= c_end: return True return False
As a Python code analyst, you investigate and solve complex coding mysteries
Adds common arguments for commands making use of a corpus to parser.
How would you explain what the following Python 3 function does def add_corpus_arguments(parser): add_tokenizer_argument(parser) parser.add_argument('corpus', help=constants.DB_CORPUS_HELP, metavar='CORPUS')
As a python code expert, you are capable of creating scripts from specifications.
Adds common arguments for the database sub - commands to parser.
How would you explain what the following Python 3 function does def add_db_arguments(parser, db_option=False): parser.add_argument('-m', '--memory', action='store_true', help=constants.DB_MEMORY_HELP) parser.add_argument('-r', '--ram', default=3, help=constants.DB_RAM_HELP, ...
As a Python code composer, you craft elegant and concise scripts.
def add_supplied_query_arguments(parser): """Adds common arguments for supplied query sub-commands to `parser`.""" parser.add_argument('-l', '--labels', help=constants.SUPPLIED_LABELS_HELP, nargs='+', required=True) parser.add_argument('-s', '--supplied', ...
How would you code a function in Python 3 to add common arguments for supplied query sub - commands to parser.
As a python code expert, you are capable of creating scripts from specifications.
Configures the logging used.
Make a summary of the following Python 3 code def configure_logging(verbose, logger): if not verbose: log_level = logging.WARNING elif verbose == 1: log_level = logging.INFO else: log_level = logging.DEBUG logger.setLevel(log_level) ch = colorlog.StreamHandler() ch.setLev...
As a Python code composer, you craft elegant and concise scripts.
def get_catalogue(args): """Returns a `tacl.Catalogue`.""" catalogue = tacl.Catalogue() catalogue.load(args.catalogue) return catalogue
Write a Python 3 function that can return a tacl. Catalogue object.
As a python code expert, you are capable of creating scripts from specifications.
def get_corpus(args): """Returns a `tacl.Corpus`.""" tokenizer = get_tokenizer(args) return tacl.Corpus(args.corpus, tokenizer)
Write a Python 3 function that can return a tacl. Corpus object.
You are a Python code analyst, evaluating scripts for potential improvements.
def get_data_store(args): """Returns a `tacl.DataStore`.""" return tacl.DataStore(args.db, args.memory, args.ram)
Implement a function in Python 3 to return a tacl. DataStore.
As a Python code translator, you convert algorithms and pseudocode into Python.
Returns a list of n - grams read from the file at path.
Can you tell what is the following Python 3 function doing def get_ngrams(path): with open(path, encoding='utf-8') as fh: ngrams = [ngram.strip() for ngram in fh.readlines()] return ngrams
As a python code expert, you are capable of creating scripts from specifications.
Returns the token content of this text with every occurrence of each n - gram in ngrams replaced with replacement.
How would you explain what the following Python 3 function does def excise(self, ngrams, replacement): content = self.get_token_content() ngrams.sort(key=len, reverse=True) for ngram in ngrams: content = content.replace(ngram, replacement) return content
As a python code expert, you are capable of creating scripts from specifications.
Returns a generator that yields the n - grams for this text.
How would you explain what the following Python 3 function does def get_ngrams(self, minimum, maximum, skip_sizes=None): skip_sizes = skip_sizes or [] tokens = self.get_tokens() for size in range(minimum, maximum + 1): if size not in skip_sizes: ngrams = collections.C...
You are a Python code analyst, evaluating scripts for potential improvements.