Extract Python Classes
Extract classes and functions from a Python codebase. This Enrichment is useful in scenarios such as documentation generation, debugging, and code analysis. It allows you to separate and analyze the classes and functions separately, making it easier to identify problems or perform deeper analysis.
Parameters
- Source Column: The column name containing the code you want to extract Python classes from. Defaults to
content
. - Destination Column: The column name that holds the Python classes. Defaults to
classes_and_functions
.
Usage
To use the Extract Python Classes transformation, you will need to follow these steps:
- Specify the Source Column parameter with the name of the column that contains the Python code from which you want to extract classes.
- Specify the Destination Column parameter with the name of the column that will hold the extracted Python classes.
- Run the transformation by clicking the Save and Run Transforms button. The resulting dataset will have a new column with the specified name containing the transformed text.
Example 1: Extracting Python Classes from Code
Suppose you have a text file of Python code snippets and you want to extract the classes from each code snippet.
ID | Code_Snippet |
---|---|
1 | class Dog:\n def init(self, name):\n self.name = name\n\ndef greet():\n return "Hello, World!"\n\nclass Cat:\n def init(self, age):\n self.age = age |
2 | class Car:\n def init(self, make, model):\n self.make = make\n self.model = model\n\nclass Bike:\n def init(self, brand):\n self.brand = brand |
transform:
name: Extract Python Classes
parameters:
source_column: Code_Snippet
destination_column: classes_and_functions
The resulting dataset would look like this:
ID | Code_Snippet | Classes_and_Functions |
---|---|---|
1 | class Dog:\n def init(self, name):\n self.name = name\n\ndef greet():\n return "Hello, World!"\n\nclass Cat:\n def init(self, age):\n self.age = age | class Dog:\n def init(self, name):\n self.name = name\n\nclass Cat:\n def init(self, age):\n self.age = age |
2 | class Car:\n def init(self, make, model):\n self.make = make\n self.model = model\n\nclass Bike:\n def init(self, brand):\n self.brand = brand | class Car:\n def init(self, make, model):\n self.make = make\n self.model = model\n\nclass Bike:\n def init(self, brand):\n self.brand = brand |
Updated over 1 year ago