| | --- |
| | language: |
| | - en |
| | tags: |
| | - software-engineering |
| | - code-analysis |
| | - refactoring |
| | - AST |
| | - lexical-features |
| | - Python |
| | - static-analysis |
| | task_categories: |
| | - feature-extraction |
| | pretty_name: Python Function's code feature |
| | size_categories: |
| | - 1M<n<10M |
| | license: cc-by-4.0 |
| | --- |
| | |
| | # ๐ Python Function-Level AST and Lexical Features Dataset |
| |
|
| | ## ๐ Dataset Summary |
| |
|
| | This dataset integrates **function-level static analysis data** from Python repositories. |
| | It merges three data sources: |
| |
|
| | 1. **Lizard Cyclomatic Analysis**: provides complexity, NLOC, and basic function metadata. |
| | 2. **AST Extracted Features**: includes detailed abstract syntax tree information such as token counts, parameters, variable extraction, and function bodies. |
| | 3. **Lexical Features**: captures lexical and structural features of each function (e.g., class structure, modifiers, incoming/outgoing calls, and statement types) and presents it in natural language. |
| |
|
| | The resulting **Dataset** represents each Python function as a unified row combining complexity metrics, lexical information, and AST structure โ enabling advanced research in: |
| | - Code comprehension |
| | - Automated refactoring |
| | - Software quality analysis |
| | - Function-level code search |
| | - Maintainability prediction |
| | - ML model training for software engineering tasks |
| |
|
| | --- |
| |
|
| | ## ๐ง Intended Uses |
| |
|
| | - Feature extraction for code comprehension and maintainability modeling. |
| | - Supervised learning for: |
| | - Maintainability prediction (regression / ordinal classification). |
| | - Refactoring-need ranking (learning-to-rank). |
| | - Benchmarking code-representation learning or graph-based refactoring tools. |
| | - Downstream tasks such as clone detection, defect prediction, and code search. |
| |
|
| | --- |
| |
|
| | ## ๐ Dataset Structure |
| |
|
| | Each row corresponds to **one Python function** identified across open-source repositories. |
| |
|
| | ### Columns |
| |
|
| | | Column name | Description | |
| | |------------------------------|---------------------------------------------------------------------------------------------------| |
| | | `project_name` | Repository name | |
| | | `class_name` | Class name containing the function (if applicable) | |
| | | `class_modifiers` | Access modifiers of the class | |
| | | `class_implements` | Interfaces implemented | |
| | | `class_extends` | Class inheritance | |
| | | `function_name` | Function name | |
| | | `function_body` | Raw function body code | |
| | | `cyclomatic_complexity` | Cyclomatic complexity measure | |
| | | `NLOC` | Number of lines of code | |
| | | `num_parameter` | Number of function parameters | |
| | | `num_token` | Number of tokens | |
| | | `num_variable` | Number of variables detected in function | |
| | | `start_line` / `end_line` | Start and end line of the function in the file | |
| | | `function_index` | Function index in AST parsing | |
| | | `function_params` | Parameter names | |
| | | `function_variable` | Variable names extracted | |
| | | `function_return_type` | Return type (if inferred) | |
| | | `function_body_line_type`| Mapping of statement types inside the function (e.g., Assign, If, Return) | |
| | | `function_num_functions` | Number of functions declared inside | |
| | | `function_num_lines` | Number of lines of function (lexical) | |
| | | `outgoing_function_count` / `outgoing_function_names` | Number and names of functions called inside this function | |
| | | `incoming_function_count` / `incoming_function_names` | Number and names of functions calling this function | |
| | | `lexical_representation` | Present the code features as natural language. | |
| |
|
| | --- |
| |
|
| | ## โ๏ธ Data Sources |
| |
|
| | - Static analysis performed on public Python repositories cloned from [GitHub](https://github.com) that apply the following characteristics (python language projects, commits > 500, and contributors > 10). |
| | - Function-level analysis uses: |
| | - [`lizard`](https://pypi.org/project/lizard/) for cyclomatic complexity. |
| | - Python AST (https://docs.python.org/3/library/ast.html) parsing for structural features. |
| | - Lexical presentation driven by structural and 15 extract code features. |
| |
|
| | --- |
| |
|
| | ## ๐งช Dataset Creation |
| |
|
| | ### Collection |
| | 1. Clone open-source Python repositories. |
| | 2. Run Lizard static analysis to generate base metrics. |
| | 3. Parse source files to extract AST and 15 code features. |
| | 4. Convert code features to natural language using rule-based code. |
| | 5. Merge the three sources |
| |
|
| | --- |
| |
|
| | ## ๐ก How to Load |
| | ```python |
| | from datasets import load_dataset |
| | data = load_dataset("rehaidib/PyFuncAST-Lex", split="train") |
| | ``` |
| |
|
| | or manually: |
| |
|
| | ```python |
| | import pandas as pd |
| | df = pd.read_parquet("PyFuncAST-Lex.parquet") |
| | ``` |
| |
|
| | --- |
| | ## Citation |
| | If you use this dataset, please cite: |
| |
|
| | ``` bibtex |
| | @dataset{PyFuncAST-Lex, |
| | title = {PyFuncAST-Lex: Python Function-Level AST and Lexical Features Dataset}, |
| | author = {Reem Al-Ehaidib}, |
| | year = {2025}, |
| | month = {11}, |
| | publisher = {Hugging Face Datasets}, |
| | version = {1.0}, |
| | url = {https://huggingface.co/datasets/rehaidib/pyfunc_code_features} |
| | } |
| | ``` |
| |
|