用户工具

站点工具


zh:courses:textmining2026:ch07

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
zh:courses:textmining2026:ch07 [2026/10/26 22:28]
pzczxs [课件]
zh:courses:textmining2026:ch07 [2026/10/26 22:33] (当前版本)
pzczxs [LDA模型]
行 3: 行 3:
 下载:{{ :​zh:​courses:​textmining2026:​ch07.pptx |主题模型}} 下载:{{ :​zh:​courses:​textmining2026:​ch07.pptx |主题模型}}
  
 +
 +===== 支持类 =====
 +<file java Chapter7Data.java>​
 +package cn.edu.bjut.textmining.chapter7;​
 +
 +import java.io.BufferedReader;​
 +import java.io.IOException;​
 +import java.io.UncheckedIOException;​
 +import java.nio.charset.StandardCharsets;​
 +import java.nio.file.Files;​
 +import java.nio.file.Path;​
 +import java.nio.file.Paths;​
 +import java.util.ArrayList;​
 +import java.util.List;​
 +
 +/**
 + * 第7章数据与输出路径工具。
 + */
 +public final class Chapter7Data {
 +
 +    private Chapter7Data() {
 +    }
 +
 +    public static Path dataPath(String name) {
 +        return Paths.get("​data",​ "​chapter7",​ name);
 +    }
 +
 +    public static Path outputPath(String name) {
 +        try {
 +            Path directory = Paths.get("​output",​ "​chapter7"​);​
 +            Files.createDirectories(directory);​
 +            return directory.resolve(name);​
 +        } catch (IOException e) {
 +            throw new UncheckedIOException("​创建输出目录失败",​ e);
 +        }
 +    }
 +
 +    public static String display(Path path) {
 +        return path.normalize().toString().replace('​\\',​ '/'​);​
 +    }
 +
 +    public static List<​String>​ readNonBlankLines(String name) {
 +        try {
 +            List<​String>​ lines = new ArrayList<​String>​();​
 +            try (BufferedReader reader = Files.newBufferedReader(dataPath(name),​ StandardCharsets.UTF_8)) {
 +                String line;
 +                while ((line = reader.readLine()) != null) {
 +                    line = line.trim();​
 +                    if (!line.isEmpty() && !line.startsWith("#"​)) {
 +                        lines.add(line);​
 +                    }
 +                }
 +            }
 +            return lines;
 +        } catch (IOException e) {
 +            throw new UncheckedIOException("​读取第7章数据失败",​ e);
 +        }
 +    }
 +}
 +</​file>​
  
 ===== LDA模型 ===== ===== LDA模型 =====
zh/courses/textmining2026/ch07.1793024920.txt.gz · 最后更改: 2026/10/26 22:28 由 pzczxs