import { SentenceSplitter } from "../TextSplitter.js";
import { DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE } from "../constants.js";
import { getNodesFromDocument } from "./utils.js";
/**
 * SimpleNodeParser is the default NodeParser. It splits documents into TextNodes using a splitter, by default SentenceSplitter
 */ export class SimpleNodeParser {
    /**
   * The text splitter to use.
   */ textSplitter;
    /**
   * Whether to include metadata in the nodes.
   */ includeMetadata;
    /**
   * Whether to include previous and next relationships in the nodes.
   */ includePrevNextRel;
    constructor(init){
        this.textSplitter = init?.textSplitter ?? new SentenceSplitter({
            chunkSize: init?.chunkSize ?? DEFAULT_CHUNK_SIZE,
            chunkOverlap: init?.chunkOverlap ?? DEFAULT_CHUNK_OVERLAP,
            splitLongSentences: init?.splitLongSentences ?? false
        });
        this.includeMetadata = init?.includeMetadata ?? true;
        this.includePrevNextRel = init?.includePrevNextRel ?? true;
    }
    async transform(nodes, _options) {
        return this.getNodesFromDocuments(nodes);
    }
    static fromDefaults(init) {
        return new SimpleNodeParser(init);
    }
    /**
   * Generate Node objects from documents
   * @param documents
   */ getNodesFromDocuments(documents) {
        return documents.map((document)=>getNodesFromDocument(document, this.textSplitter.splitText.bind(this.textSplitter), this.includeMetadata, this.includePrevNextRel)).flat();
    }
}
