benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf f08eb3b6-27cc-5eb4-b022-aa8a878eb7a3
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import re
import json
import os
def task_func(file_path: str, regex_pattern=r'
\(.+?\)|\w') -> dict:
"""
Extracts matches from a JSON file based on a predefined regular pattern.
The default regular expression pattern is designed to extract any content between parentheses
as a single match and any individual character outside the parentheses as a separate match.
Parameters:
- file_path (str): The path to the JSON file. The JSON file should contain key-value pairs
where the values are strings to be matched against the regex pattern.
Returns:
- dict: A dictionary with the JSON file name as the key and a list of matches as values.
The format is: {filename: [match1, match2, ...]}.
Requirements:
- The function makes use of the following libraries/modules: re, json, os.
Example:
>>> import tempfile
>>> temp_dir = tempfile.mkdtemp()
>>> file_path = os.path.join(temp_dir, 'sample_data.json')
>>> with open(file_path, 'w') as file:
... json.dump({'content': 'This is a (sample) text with some (matches) and characters.'}, file)
>>> matches = task_func(file_path)
>>> len(matches['sample_data.json'])
34
"""
Plain-text mathematical notation (without MathML)
import re
import json
import os
def task_func(file_path: str, regex_pattern=r'\(.+?\)|\w') -> dict:
"""
Extracts matches from a JSON file based on a predefined regular pattern.
The default regular expression pattern is designed to extract any content between parentheses
as a single match and any individual character outside the parentheses as a separate match.
Parameters:
- file_path (str): The path to the JSON file. The JSON file should contain key-value pairs
where the values are strings to be matched against the regex pattern.
Returns:
- dict: A dictionary with the JSON file name as the key and a list of matches as values.
The format is: {filename: [match1, match2, ...]}.
Requirements:
- The function makes use of the following libraries/modules: re, json, os.
Example:
>>> import tempfile
>>> temp_dir = tempfile.mkdtemp()
>>> file_path = os.path.join(temp_dir, 'sample_data.json')
>>> with open(file_path, 'w') as file:
... json.dump({'content': 'This is a (sample) text with some (matches) and characters.'}, file)
>>> matches = task_func(file_path)
>>> len(matches['sample_data.json'])
34
"""
Original LaTeX notation
import re
import json
import os
def task_func(file_path: str, regex_pattern=r'\(.+?\)|\w') -> dict:
"""
Extracts matches from a JSON file based on a predefined regular pattern.
The default regular expression pattern is designed to extract any content between parentheses
as a single match and any individual character outside the parentheses as a separate match.
Parameters:
- file_path (str): The path to the JSON file. The JSON file should contain key-value pairs
where the values are strings to be matched against the regex pattern.
Returns:
- dict: A dictionary with the JSON file name as the key and a list of matches as values.
The format is: {filename: [match1, match2, ...]}.
Requirements:
- The function makes use of the following libraries/modules: re, json, os.
Example:
>>> import tempfile
>>> temp_dir = tempfile.mkdtemp()
>>> file_path = os.path.join(temp_dir, 'sample_data.json')
>>> with open(file_path, 'w') as file:
... json.dump({'content': 'This is a (sample) text with some (matches) and characters.'}, file)
>>> matches = task_func(file_path)
>>> len(matches['sample_data.json'])
34
"""
instruct prompt
Extracts matches from a JSON file based on a predefined regular pattern. The default regular expression pattern is designed to extract any content between parentheses as a single match and any individual character outside the parentheses as a separate match.
The function should output with:
dict: A dictionary with the JSON file name as the key and a list of matches as values.
The format is: {filename: [match1, match2, ...]}.
You should write self-contained code starting with:
Code
import re
import json
import os
def task_func(file_path: str, regex_pattern=r'\(.+?\)|\w') -> dict:
code prompt
Code
import re
import json
import os
def task_func(file_path: str, regex_pattern=r'\(.+?\)|\w') -> dict:
entry point
task_func
libs
- json
- re
- os
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import