MWDumpLoader#

class langchain_community.document_loaders.mediawikidump.MWDumpLoader(
file_path: str | Path,
encoding: str | None = 'utf8',
namespaces: Sequence[int] | None = None,
skip_redirects: bool | None = False,
stop_on_error: bool | None = True,
)[source]#

Load MediaWiki dump from an XML file.

Example

from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_community.document_loaders import MWDumpLoader

loader = MWDumpLoader(
    file_path="myWiki.xml",
    encoding="utf8"
)
docs = loader.load()
text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=1000, chunk_overlap=0
)
texts = text_splitter.split_documents(docs)
Parameters:
  • file_path (str) โ€“ XML local file path

  • encoding (str, optional) โ€“ Charset encoding, defaults to โ€œutf8โ€

  • namespaces (List[int],optional) โ€“ The namespace of pages you want to parse. See https://www.mediawiki.org/wiki/Help:Namespaces#Localisation for a list of all common namespaces

  • skip_redirects (bool, optional) โ€“ TR=rue to skip pages that redirect to other pages, False to keep them. False by default

  • stop_on_error (bool, optional) โ€“ False to skip over pages that cause parsing errors, True to stop. True by default

Methods

__init__(file_path[,ย encoding,ย namespaces,ย ...])

alazy_load()

A lazy loader for Documents.

aload()

Load data into Document objects.

lazy_load()

Lazy load from a file path.

load()

Load data into Document objects.

load_and_split([text_splitter])

Load Documents and split into chunks.

__init__(
file_path: str | Path,
encoding: str | None = 'utf8',
namespaces: Sequence[int] | None = None,
skip_redirects: bool | None = False,
stop_on_error: bool | None = True,
)[source]#
Parameters:
  • file_path (str | Path)

  • encoding (str | None)

  • namespaces (Sequence[int] | None)

  • skip_redirects (bool | None)

  • stop_on_error (bool | None)

async alazy_load() โ†’ AsyncIterator[Document]#

A lazy loader for Documents.

Yields:

the documents.

Return type:

AsyncIterator[Document]

async aload() โ†’ list[Document]#

Load data into Document objects.

Returns:

the documents.

Return type:

list[Document]

lazy_load() โ†’ Iterator[Document][source]#

Lazy load from a file path.

Return type:

Iterator[Document]

load() โ†’ list[Document]#

Load data into Document objects.

Returns:

the documents.

Return type:

list[Document]

load_and_split(
text_splitter: TextSplitter | None = None,
) โ†’ list[Document]#

Load Documents and split into chunks. Chunks are returned as Documents.

Do not override this method. It should be considered to be deprecated!

Parameters:

text_splitter (Optional[TextSplitter]) โ€“ TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Raises:

ImportError โ€“ If langchain-text-splitters is not installed and no text_splitter is provided.

Returns:

List of Documents.

Return type:

list[Document]

Examples using MWDumpLoader