class MyClass:        def __init__(self, name):            self.name = name            def greet(self):            print(f"Hello, {self.name}!")        --8<--        def main():        name = input("Enter your name: ")        obj = MyClass(name)        obj.greet()        --8<--        # Code for: class MyClass:            # Code for: def main():            if __name__ == "__main__":        main()        --8<--        class MyClass {      constructor(name) {        this.name = name;      }          greet() {        console.log(`Hello, ${this.name}!`);      }    }        --8<--        function main() {      const name = prompt("Enter your name:");      const obj = new MyClass(name);      obj.greet();    }        --8<--        // Code for: class MyClass {        // Code for: function main() {        main();The parser can be disabled for small files. The parameter parser_threshold indicates the minimum number of lines that the source code file must have to be segmented using the parser.loader = GenericLoader.from_filesystem(    "./example_data/source_code",    glob="*",    suffixes=[".py"],    parser=LanguageParser(language=Language.PYTHON, parser_threshold=1000),)docs = loader.load()len(docs)    1print(docs[0].page_content)    class MyClass:        def __init__(self, name):            self.name = name            def greet(self):            print(f"Hello, {self.name}!")            def main():        name = input("Enter your name: ")        obj = MyClass(name)        obj.greet()            if __name__ == "__main__":        main()    Splitting‚ÄãAdditional splitting could be needed for those functions, classes, or scripts that are too big.loader = GenericLoader.from_filesystem(    "./example_data/source_code",    glob="*",    suffixes=[".js"],    parser=LanguageParser(language=Language.JS),)docs = loader.load()from langchain.text_splitter import (    RecursiveCharacterTextSplitter,    Language,)js_splitter = RecursiveCharacterTextSplitter.from_language(
This notebook covers how to load source code files using a special approach with language parsing: each top-level function and class in the code is loaded into separate documents. Any remaining code top-level code outside the already loaded functions and classes will be loaded into a separate document.
This notebook covers how to load source code files using a special approach with language parsing: each top-level function and class in the code is loaded into separate documents. Any remaining code top-level code outside the already loaded functions and classes will be loaded into a separate document. ->: class MyClass:        def __init__(self, name):            self.name = name            def greet(self):            print(f"Hello, {self.name}!")        --8<--        def main():        name = input("Enter your name: ")        obj = MyClass(name)        obj.greet()        --8<--        # Code for: class MyClass:            # Code for: def main():            if __name__ == "__main__":        main()        --8<--        class MyClass {      constructor(name) {        this.name = name;      }          greet() {        console.log(`Hello, ${this.name}!`);      }    }        --8<--        function main() {      const name = prompt("Enter your name:");      const obj = new MyClass(name);      obj.greet();    }        --8<--        // Code for: class MyClass {        // Code for: function main() {        main();The parser can be disabled for small files. The parameter parser_threshold indicates the minimum number of lines that the source code file must have to be segmented using the parser.loader = GenericLoader.from_filesystem(    "./example_data/source_code",    glob="*",    suffixes=[".py"],    parser=LanguageParser(language=Language.PYTHON, parser_threshold=1000),)docs = loader.load()len(docs)    1print(docs[0].page_content)    class MyClass:        def __init__(self, name):            self.name = name            def greet(self):            print(f"Hello, {self.name}!")            def main():        name = input("Enter your name: ")        obj = MyClass(name)        obj.greet()            if __name__ == "__main__":        main()    Splitting‚ÄãAdditional splitting could be needed for those functions, classes, or scripts that are too big.loader = GenericLoader.from_filesystem(    "./example_data/source_code",    glob="*",    suffixes=[".js"],    parser=LanguageParser(language=Language.JS),)docs = loader.load()from langchain.text_splitter import (    RecursiveCharacterTextSplitter,    Language,)js_splitter = RecursiveCharacterTextSplitter.from_language(