小说分割器生成查看目录


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * https://blog.csdn.net/qq_36240505/article/details/115605315
 * 正则表达式读取小说(txt文本)的章节
 */
public class NovelSplitterUtils {

    public static void main(String[] args) {
//        // 把获取后的list插入到SQLserver
//        JdbcConnection.insertSQL(parse(1, "C://Users//下一季//Desktop//一念永恒.txt"));

        ArrayList<BookCon> parse = parse(1, "D:\\06tmp\\7175.txt");
        for (int i = 0; i < parse.size(); i++) {
            System.out.println("i = " + parse.get(i).chapterName);
        }
    }

    public static int idCount = 1;// 手动增加 章节id ,导入多个小说文件时,避免id重复

    public static ArrayList<BookCon> parse(int BookId, String path) {

        ArrayList<BookCon> list = null;

        try {

            File file = new File(path);
            if (!file.isFile() || !file.exists()) {
                return null;
            }

            InputStreamReader read = new InputStreamReader(new FileInputStream(file), "GBK");
            BufferedReader bufferedReader = new BufferedReader(read);

            int count = 1;
            String lineTxt = null;
            list = new ArrayList<>();

            StringBuilder lastBuilder = null;
            BookCon lastBookContent = null;

            while ((lineTxt = bufferedReader.readLine()) != null) {

                lineTxt = lineTxt.trim();

//				正则表达式:我的小说章节名是以 ###开头,###结尾 ,所以用第二个更好
                Pattern p = Pattern.compile("(第\\S*)[章节卷集部篇回](\\s)(\\S*)[^#]");
//				Pattern p = Pattern.compile("(###)(.*)(###)");
                Matcher matcher = p.matcher(lineTxt);

                if (matcher.find()) {

                    if (lastBookContent != null) {
                        lastBookContent.content = lastBuilder.toString();
                        list.add(lastBookContent);
//						System.out.println(lastBuilder.toString());// 输出当前的章节内容,建议设置输出长度
                    }

                    BookCon newBookContent = new BookCon(idCount++, BookId, matcher.group(), count++);
//					System.out.println(newBookContent.chapterName);// 输出当前的章节名

                    lastBuilder = new StringBuilder();
                    lastBookContent = newBookContent;

                } else if (lastBuilder != null) {
                    lastBuilder.append(lineTxt + "\n");
                }

            }

//			以防最后一个章节无法读取
            if (lastBuilder != null) {
                lastBookContent.content = lastBuilder.toString();
                list.add(lastBookContent);
            }

            bufferedReader.close();

        } catch (Exception e) {
            System.out.println("文件读取失败");
            e.printStackTrace();
        } finally {
            return list;
        }

    }
    static class BookCon {

        int chapterId;// 章节id
        int bookId;// 图书id
        String chapterName;// 章节名
        String content;// 当前章节内容
        int order;// 章节序号

        public BookCon(int chapterId, int bookId, String chapterName, int order) {// 构造方法(缺少一个成员变量)

            this.order = order;
            this.bookId = bookId;
            this.chapterId = chapterId;
            this.chapterName = chapterName;

        }

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机载点云语义分割是指对机载激光雷或者摄像头采集到的点云数据进行语义分割,即将点云中的每个点分配到不同的语义类别中。代码生成是指根据特定需求生成相应的代码。 在机载点云语义分割任务中,常用的代码生成方法包括以下几个步骤: 1. 数据预处理:对采集到的点云数据进行预处理,包括点云去噪、滤波、坐标转换等操作,以提高后续语义分割的准确性和效果。 2. 特征提取:从预处理后的点云数据中提取特征,常用的特征包括点的坐标、法向量、颜色等。特征提取可以通过计算几何属性、统计属性或者使用深度学习方法进行。 3. 模型选择:选择适合机载点云语义分割任务的模型,常用的模型包括传统的机器学习方法(如支持向量机、随机森林等)和深度学习方法(如卷积神经网络、图卷积网络等)。 4. 模型训练:使用标注好的点云数据对选择的模型进行训练,以学习点云数据的语义信息。训练过程中需要定义损失函数和优化算法,并进行迭代优化。 5. 模型评估:使用测试集对训练好的模型进行评估,计算模型在点云语义分割任务上的准确率、召回率、F1值等指标,以评估模型的性能。 6. 代码生成:根据选择的模型和训练好的参数,生成用于机载点云语义分割的代码。代码可以包括数据加载、特征提取、模型定义、训练和测试等部分。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值